Advertisement
Guest User

Untitled

a guest
Sep 30th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 16.74 KB | None | 0 0
  1. let g:mapleader=' '
  2.  
  3. " ============= PLUGINS =============
  4.  
  5. " disable netrw
  6. let g:loaded_netrw=1
  7. let g:loaded_netrwPlugin=1
  8.  
  9. call plug#begin('~/vimfiles/plugged')
  10. Plug 'tpope/vim-surround'              " edit braces easily
  11. Plug 'tpope/vim-commentary'            " comment out lines
  12. Plug 'tpope/vim-repeat'                " repeat plugin commands
  13. Plug 'easymotion/vim-easymotion'       " jump to any position
  14. Plug 'google/vim-searchindex'          " show [x/y] when searching
  15. Plug 'machakann/vim-highlightedyank'   " highlight yanks
  16. Plug 'markonm/traces.vim'              " live substitution
  17. Plug 'simnalamburt/vim-mundo'          " graphical undotree
  18. Plug 'maxbrunsfeld/vim-yankstack'      " remember past yanks
  19. Plug 'vim-scripts/ReplaceWithRegister' " operator to replace text
  20. Plug 'wellle/targets.vim'              " more text objects
  21. Plug 'tommcdo/vim-exchange'            " change two objects
  22. Plug 'davidhalter/jedi-vim'            " python engine
  23. Plug 'w0rp/ale'                        " automatic linting
  24. Plug 'terryma/vim-smooth-scroll'       " smooth scrolling
  25. Plug 'Yggdroot/LeaderF'                " fuzzy finding
  26. Plug 'scrooloose/nerdtree'             " file browser
  27. Plug 'chrisbra/Colorizer'              " preview colors
  28. Plug 'junegunn/vim-easy-align'         " align text with motion
  29. Plug 'Valloric/YouCompleteMe'          " better autocompletion
  30. Plug 'sheerun/vim-polyglot'            " better syntax highlighting
  31. Plug 'trevordmiller/nova-vim'          " nova colorscheme
  32. Plug 'tmhedberg/SimpylFold'            " python folding
  33. call plug#end()
  34.  
  35. " sheerun/vim-polyglot
  36. " Edited line 480, python self and cls highlighting
  37.  
  38. " Valloric/YouCompleteMe
  39. let g:ycm_autoclose_preview_window_after_completion=1
  40. let g:ycm_show_diagnostics_ui=0
  41.  
  42. " scrooloose/nerdtree
  43. nnoremap <silent> <Leader>1 :NERDTreeToggle<CR>
  44.  
  45. " Yggdroot/LeaderF
  46. let g:Lf_StlColorscheme='default'
  47. let g:Lf_CursorBlink=0
  48. let g:Lf_UseVersionControlTool=0
  49. let g:Lf_DefaultExternalTool='rg'
  50. let g:Lf_ShowHidden=1
  51. let TempFolder = $HOME . '/vimfiles/.temp'
  52. let g:Lf_CacheDirectory=TempFolder
  53. let g:Lf_IndexTimeLimit=600
  54. let g:Lf_UseCache=1
  55. let g:Lf_HighlightIndividual=1
  56. let g:Lf_NumberOfHighlight=100
  57. let g:Lf_UseMemoryCache=1
  58. let g:Lf_WildIgnore = {
  59.         \ 'dir': ['.git'],
  60.         \ 'file': []
  61.         \}
  62. let g:Lf_ShortcutF='<Leader>p'
  63. nnoremap <Leader>l :LeaderfLine<CR>
  64. nnoremap <Leader>o :LeaderfLineAll<CR>
  65. nnoremap <Leader>k :LeaderfHelp<CR>
  66. nnoremap <Leader>n :LeaderfBufferAll<CR>
  67. nnoremap <Leader>m :LeaderfMru<CR>
  68.  
  69. " w0rp/ale
  70. let g:ale_sign_column_always=0
  71. let g:ale_change_sign_column_color=1
  72. let g:ale_set_signs=0
  73. let g:ale_max_signs=-1
  74. let g:ale_use_global_executables=1
  75. let g:ale_linters_explicit=1
  76. let g:ale_set_quickfix=0
  77. let g:ale_set_loclist=0
  78. let g:ale_linters = {'python': ['flake8', 'mypy'], 'vim': ['vint']}
  79. let g:ale_fixers  = {'python': ['autopep8', 'isort']}
  80. let g:ale_lint_on_enter=0
  81. let g:ale_lint_on_text_changed='never'
  82. let g:ale_lint_on_filetype_changed=0
  83. let g:ale_lint_on_insert_leave=0
  84. let g:ale_lint_on_save=1
  85. let g:ale_fix_on_save=0
  86. nnoremap <silent> <Left>  :ALEPreviousWrap<CR>
  87. nnoremap <silent> <Right> :ALENextWrap<CR>
  88.  
  89. " davidhalter/jedi-vim
  90. let g:jedi#goto_command='<C-]>'
  91. let g:jedi#documentation_command='K'
  92. let g:jedi#rename_command='<Leader>r'
  93. let g:jedi#usages_command='<Leader>u'
  94. let g:jedi#completions_enabled=0
  95. let g:jedi#popup_on_dot=0
  96. let g:jedi#show_call_signatures=0
  97.  
  98. " maxbrunsfeld/vim-yankstack
  99. let g:yankstack_map_keys = 0
  100. nmap <C-P> <Plug>yankstack_substitute_older_paste
  101. nmap <C-N> <Plug>yankstack_substitute_newer_paste
  102. call yankstack#setup()
  103.  
  104. " easymotion/vim-easymotion
  105. let g:EasyMotion_keys='asdghklqwertyuiopzxcvbnmfj'
  106. let g:EasyMotion_do_shade=0
  107. let g:EasyMotion_do_mapping=0
  108. map <Leader>f <Plug>(easymotion-bd-f)
  109. map <Leader>t <Plug>(easymotion-bd-t)
  110.  
  111. " machakann/vim-highlightedyank
  112. let g:highlightedyank_highlight_duration=300
  113.  
  114. " simnalamburt/vim-mundo
  115. let g:mundo_preview_statusline='Diff'
  116. let g:mundo_tree_statusline='History'
  117. let g:mundo_mirror_graph=0
  118. let g:mundo_return_on_revert=0
  119. let g:mundo_verbose_graph=0
  120. nnoremap <silent> <Leader>2 :MundoToggle<CR>
  121.  
  122. " junegunn/vim-easy-align
  123. nmap gl <Plug>(EasyAlign)
  124. xmap gl <Plug>(EasyAlign)
  125.  
  126. " vim-scripts/ReplaceWithRegister
  127. nmap ö <Plug>ReplaceWithRegisterOperator
  128. nmap Ö <Plug>ReplaceWithRegisterOperator$
  129. nmap öö <Plug>ReplaceWithRegisterLine
  130. xmap ö <Plug>ReplaceWithRegisterVisual
  131.  
  132. " terryma/vim-smooth-scroll
  133. nnoremap <silent> <C-U> :call smooth_scroll#up(&scroll, 0, 2)<CR>
  134. nnoremap <silent> <C-D> :call smooth_scroll#down(&scroll, 0, 2)<CR>
  135. nnoremap <silent> <C-B> :call smooth_scroll#up(&scroll*2, 0, 4)<CR>
  136. nnoremap <silent> <C-F> :call smooth_scroll#down(&scroll*2, 0, 4)<CR>
  137.  
  138. " tmhedberg/SimpylFold
  139. let g:SimpylFold_docstring_preview=0
  140. let g:SimpylFold_fold_docstring=0
  141. let g:SimpylFold_fold_import=1
  142.  
  143.  
  144.  
  145. " ============= GENERAL =============
  146.  
  147. " set these only when vim starts, not when sourcing vimrc
  148. if !exists('g:notfirstopen')
  149.     let g:notfirstopen=1
  150.     set lines=40 columns=120  " initial window size
  151.    set guifont=Consolas:h12  " changing font moves the window
  152.     syntax enable
  153.     colorscheme nova  " messes up Mundo if loaded again
  154.    highlight MatchParen gui=bold,underline guifg=#D18EC2
  155.    highlight IncSearch gui=bold guifg=#A8CE93 guibg=#1E272C
  156.    highlight Todo gui=bold guifg=#DF8C8C
  157. endif
  158.  
  159. " use cygwin bash as shell
  160. let $CHERE_INVOKING=1
  161. set shell=C:/cygwin64/bin/bash.exe
  162. set shellcmdflag=--login\ -c
  163. set shellxquote=\"
  164. set noshellslash
  165.  
  166. " visuals
  167. set guioptions=
  168. set guicursor+=a:blinkon0
  169. set guicursor+=i-ci:ver20-blinkon0
  170. set cursorline
  171. set number relativenumber
  172. set showmode showcmd
  173. set report=1
  174. set cmdheight=2
  175.  
  176. " statusline
  177. set laststatus=2                                      " always show statusline
  178. set statusline=                                       " clear statusline
  179. set statusline+=%l                                    " current line number
  180. set statusline+=/%L                                   " total lines
  181. set statusline+=(%p%%)                                " percentage through the file
  182. set statusline+=%4c                                   " cursor column
  183. set statusline+=\|%-4{strwidth(getline('.'))}         " line length
  184. set statusline+=%{LinterStatus()}                     " ALE status
  185. set statusline+=%{&buftype!='terminal'?expand('%:p:h:t').'\\'.expand('%:t'):expand('%')}  " dir\filename.ext
  186. set statusline+=%m                                    " modified flag
  187. set statusline+=%r                                    " read only flag
  188. set statusline+=%=                                    " left/right separator
  189. set statusline+=\ \|\ %{getcwd()}                     " current working directory
  190. set statusline+=\ [%{strlen(&ft)?(&ft\ .\ \',\'):''}  " filetype
  191. set statusline+=%{strlen(&fenc)?(&fenc\ .\ \',\'):''} " file encoding
  192. set statusline+=%{&ff}]                               " line endings
  193. set statusline+=%<                                    " start to truncate here
  194.  
  195. " line wrapping
  196. set wrap linebreak textwidth=0 wrapmargin=0 formatoptions-=t
  197.  
  198. " indentation settings
  199. set tabstop=8 softtabstop=4 shiftwidth=4 expandtab
  200. set smarttab  autoindent    breakindent
  201.  
  202. " show unwanted whitespace on 'set list'
  203. set nolist listchars=tab:>-,trail:.,nbsp:.
  204.  
  205. " search settings
  206. set incsearch hlsearch ignorecase smartcase gdefault
  207.  
  208. " no errorbells
  209. set noerrorbells
  210. augroup NoVisualBells
  211. autocmd!
  212. autocmd GUIEnter * set visualbell t_vb=
  213. augroup END
  214.  
  215. " language settings
  216. let $LANG='en_US'
  217. set fileformats=unix,dos
  218. set encoding=utf-8
  219. scriptencoding utf-8
  220.  
  221. " temp file locations
  222. set undofile
  223. set viminfo+=n~/vimfiles/.temp/_viminfo
  224. set undodir=~/vimfiles/.temp/undo
  225. set backupdir=~/vimfiles/.temp/backup
  226. set directory=~/vimfiles/.temp/swap
  227.  
  228. " mixed settings
  229. set clipboard=unnamed          " use system clipboard
  230. set backspace=indent,eol,start " make backspace behave normally
  231. set hidden                     " switch to another buffer without saving
  232. set autoread                   " update changes to file automatically
  233. set scrolloff=1                " pad cursor row with lines
  234. set splitright                 " open splits to the right
  235. set splitbelow                 " open splits to the bottom
  236. set wildmode=list:longest,full " better tab completion on command line mode
  237. set undolevels=5000            " remember more undo history
  238. set history=1000               " remember more command history
  239. set updatecount=10             " update swap file more often
  240. set matchpairs=(:),{:},[:]     " configure which braces to match
  241. set shortmess=a                " shorter prompt messages
  242. filetype plugin indent on      " auto detect filetype
  243.  
  244.  
  245.  
  246. " ============= MAPPINGS =============
  247.  
  248. " makes these easier to use in profin layout
  249. noremap , :
  250. tnoremap <C-W>, <C-W>:
  251. noremap : ;
  252. noremap ; ,
  253. augroup QMappings
  254.    autocmd!
  255.    autocmd FileType * if &l:buftype !=# 'nofile' |nnoremap <buffer> <silent> q, q:| endif
  256.    autocmd FileType * if &l:buftype ==# 'nofile' |nnoremap <buffer> <silent> q :q<CR>| endif
  257. augroup END
  258.  
  259. " traverse history with alt+,.
  260. nnoremap ® g,
  261. nnoremap ¬ g;
  262.  
  263. " make Y behave the same way as D and C
  264. nnoremap Y y$
  265.  
  266. " makes v and V more consistent with other commands
  267. nnoremap vv V
  268. nnoremap V <C-V>$
  269.  
  270. " makes S more useful
  271. nnoremap S ciw
  272.  
  273. " search for selected text
  274. xnoremap <Leader>/ "zy/\V<C-R>=escape(@z,'/\')<CR><CR>
  275.  
  276. " split navigations (alt+hjkl)
  277. nnoremap è <C-W><C-H>
  278. nnoremap ê <C-W><C-J>
  279. nnoremap ë <C-W><C-K>
  280. nnoremap ì <C-W><C-L>
  281. tnoremap è <C-W><C-H>
  282. tnoremap ê <C-W><C-J>
  283. tnoremap ë <C-W><C-K>
  284. tnoremap ì <C-W><C-L>
  285.  
  286. " cycle buffers (alt+nm)
  287. nnoremap <silent> î :bprev<CR>
  288. nnoremap <silent> í :bnext<CR>
  289. tnoremap <silent> î <C-W>:bprev<CR>
  290. tnoremap <silent> í <C-W>:bnext<CR>
  291.  
  292. " cycle tabs (alt+ui)
  293. nnoremap <silent>õ :tabprevious<CR>
  294. nnoremap <silent>é :tabnext<CR>
  295. tnoremap <silent>õ <C-W>:tabprevious<CR>
  296. tnoremap <silent>é <C-W>:tabnext<CR>
  297.  
  298. " navigate quickfix list and vimgrep
  299. nnoremap <silent> <Down> :cnext<CR>
  300. nnoremap <silent> <Up> :cprev<CR>
  301. nnoremap <silent> <C-Down> :cnfile<CR><C-G>
  302. nnoremap <silent> <C-Up> :cpfile<CR><C-G>
  303.  
  304. " capitalize word under/before under cursor
  305. inoremap <C-J> <Esc>mzbgUiw`za
  306.  
  307. " make C-U and C-W and CR undoable
  308. inoremap <C-U> <C-G>u<C-U>
  309. inoremap <C-W> <C-G>u<C-W>
  310. inoremap <CR> <C-G>u<CR>
  311.  
  312. " change enter behaviour
  313. augroup EnterMappings
  314.    autocmd!
  315.    " Complex but works
  316.    autocmd BufEnter * if &l:buftype ==# ''
  317.            \| nnoremap <buffer> <CR> o<Esc>
  318.            \| nnoremap <buffer> <S-Enter> O<Esc>
  319.            \| nnoremap <buffer> <silent> <C-Enter> :<C-U>call <SID>BlankDown(v:count1)<CR>
  320.            \| nnoremap <buffer> <silent> <C-S-Enter> :<C-U>call <SID>BlankUp(v:count1)<CR>
  321.            \| nnoremap <buffer> <Leader><CR> a<CR><Esc>
  322.            \| endif
  323.    autocmd BufWinEnter * if &l:buftype ==# 'quickfix'
  324.            \| unmap <buffer> <CR>
  325.            \| endif
  326. augroup END
  327.  
  328. " move CTRL-I, since tab is taken
  329. nnoremap <C-K> <C-I>
  330.  
  331. " better way to indent
  332. nnoremap <BS> <<
  333. nnoremap <TAB> >>
  334. xnoremap <BS> <gv
  335. xnoremap <TAB> >gv
  336.  
  337. " persistent visuals
  338. xnoremap > >gv
  339. xnoremap < <gv
  340. xnoremap <C-X> <C-X>gv
  341. xnoremap <C-A> <C-A>gv
  342.  
  343. " Q plays back q macro
  344. nnoremap Q @q
  345.  
  346. " don't copy to clipboard when deleting with <Leader>d
  347. nnoremap <Leader>d "_d
  348. nnoremap <Leader>D "_D
  349. xnoremap <Leader>d "_d
  350.  
  351. " clear highlights
  352. nnoremap <silent> <Esc> <Esc>:noh<CR>
  353.  
  354. " open vimrc
  355. nnoremap <silent> <Leader>vr :tabe<BAR>tabm<BAR>e $MYVIMRC<CR>
  356.  
  357. " toggle fullscreen
  358. nnoremap <silent> <Leader>0 :call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0)<CR>
  359.  
  360. " unmap push-to-talk key
  361. map <F13> <Nop>
  362. map! <F13> <Nop>
  363.  
  364. " close current buffer
  365. nnoremap <silent> <Leader>b :call DeleteCurBufferNotCloseWindow()<CR>
  366.  
  367. " change working directory to current file's directory
  368. nnoremap <leader>cd :cd %:p:h<CR>:pwd<CR>
  369.  
  370.  
  371.  
  372. " ============= COMMANDS =============
  373.  
  374. " vim-plug commands
  375. command! PI w | PlugInstall
  376. command! PC w | PlugClean!
  377. command! PU w | PlugUpdate | PlugUpgrade
  378.  
  379. " source vimrc
  380. command! SO so $MYVIMRC
  381.  
  382. " count lines in file
  383. command! WC %s/^\s*\w\+//n | noh
  384.  
  385. " count all .py files lines
  386. command! PL write|tabn 1|call <SID>RunCommandInSplitTerm("grep -vc '^\\s*$' *.py && echo -n 'total:' && grep -v '^\\s*$' *.py | wc -l")
  387.  
  388.  
  389.  
  390. " ============= FUNCTIONS =============
  391.  
  392. " https://github.com/dhleong/dots/blob/master/.vim/init/terminal.vim
  393. function! s:RunCommandInSplitTerm(command) abort
  394.     write
  395.     let winSize = float2nr(0.3 * winheight('$'))
  396.     let mainBuf = bufnr('%')
  397.     let termBufNr = get(b:, '_run_term', -1)
  398.     let termWinNr = bufwinnr(termBufNr)
  399.  
  400.     if termWinNr == -1
  401.         exe 'below split | resize ' . winSize
  402.         let termBufNr = term_start('bash -l', {
  403.                     \ 'curwin': 1,
  404.                     \ 'term_finish': 'close',
  405.                     \ })
  406.         call setbufvar(mainBuf, '_run_term', termBufNr)
  407.     else
  408.         exe termWinNr . 'wincmd w'
  409.     endif
  410.  
  411.     let mainWin = bufwinnr(mainBuf)
  412.     call term_sendkeys(termBufNr, a:command . '
  413. ')
  414.     exe "normal \<C-W>p"
  415. endfunction
  416.  
  417.  
  418. " https://stackoverflow.com/a/44950143
  419. func! DeleteCurBufferNotCloseWindow() abort
  420.    if &modified
  421.        echohl ErrorMsg
  422.        echom 'E89: no write since last change'
  423.        echohl None
  424.    elseif winnr('$') == 1
  425.        bd
  426.    else  " multiple window
  427.         let oldbuf = bufnr('%')
  428.         let oldwin = winnr()
  429.         while 1   " all windows that display oldbuf will remain open
  430.            if buflisted(bufnr('#'))
  431.                b#
  432.            else
  433.                bn
  434.                let curbuf = bufnr('%')
  435.                if curbuf == oldbuf
  436.                    enew    " oldbuf is the only buffer, create one
  437.                 endif
  438.             endif
  439.             let win = bufwinnr(oldbuf)
  440.             if win == -1
  441.                 break
  442.             else        " there are other window that display oldbuf
  443.                exec win 'wincmd w'
  444.            endif
  445.        endwhile
  446.        " delete oldbuf and restore window to oldwin
  447.         exec oldbuf 'bd'
  448.         exec oldwin 'wincmd w'
  449.     endif
  450. endfunc
  451.  
  452.  
  453. function! s:BlankUp(count) abort
  454.     norm! mz
  455.     for i in range(1, a:count)
  456.         norm! O
  457.     endfor
  458.     norm! `z
  459. endfunction
  460.  
  461. function! s:BlankDown(count) abort
  462.     norm! mz
  463.     for i in range(1, a:count)
  464.         norm! o
  465.     endfor
  466.     norm! `z
  467. endfunction
  468.  
  469.  
  470. function! s:PutXXX(count) abort
  471.     norm! mz
  472.     for i in range(1, a:count)
  473.         norm! A  # XXXj
  474.     endfor
  475.     norm! `z
  476. endfunction
  477.  
  478. function! s:NoXXX(count) abort
  479.     norm! mz
  480.     for i in range(1, a:count)
  481.         norm! $F#gEl"_Dj
  482.     endfor
  483.     norm! `z
  484. endfunction
  485.  
  486.  
  487. function! LinterStatus() abort
  488.     let l:counts = ale#statusline#Count(bufnr(''))
  489.     let l:all_errors = l:counts.error + l:counts.style_error
  490.     let l:all_non_errors = l:counts.total - l:all_errors
  491.  
  492.     return l:counts.total == 0 ? '' : printf(
  493.     \ '[%dW %dE] ',
  494.     \ all_non_errors,
  495.     \ all_errors,
  496.     \)
  497. endfunction
  498.  
  499.  
  500.  
  501. " ============= AUTOCMD =============
  502.  
  503. " config for python files
  504. " TODO: pistä run command vaihtamaan pois terminaalista, esim oik puol splittiin
  505. " Last <BAR>:<CR> in run python command mapping maybe removes 'ml_get: invalid lnum' error
  506. augroup Python
  507.     autocmd!
  508.     autocmd FileType python nnoremap <buffer> <silent> <Leader>5
  509.                 \ :write<BAR>:tabn 1<BAR>:call <SID>RunCommandInSplitTerm('python ' . shellescape(expand('%:p')))<CR><BAR>:<CR>
  510.                 \|nnoremap <buffer> <Leader>' o""""""<Esc>hhi
  511.                \|nnoremap <buffer> <Leader>x :<C-U>call <SID>PutXXX(v:count1)<CR>
  512.                \|nnoremap <buffer> <Leader>z :<C-U>call <SID>NoXXX(v:count1)<CR>
  513. augroup END
  514.  
  515.  
  516. " toggle relative numbers between modes
  517. augroup LineNumbers
  518.    autocmd!
  519.    autocmd WinEnter,FocusGained,InsertLeave * if &l:buftype !=# 'nofile' && &l:buftype !=# 'nowrite' |set relativenumber|endif
  520.    autocmd WinLeave,FocusLost,InsertEnter * if &l:buftype !=# 'nofile' && &l:buftype !=# 'nowrite' |set norelativenumber|endif
  521. augroup END
  522.  
  523.  
  524. " source vimrc when it's saved
  525. augroup ReloadVimrc
  526.     autocmd!
  527.     autocmd BufWritePost vimrc so $MYVIMRC
  528. augroup END
  529.  
  530.  
  531. " configure opening of help windows
  532. augroup HelpOpen
  533.    autocmd!
  534.    autocmd BufRead *.txt if &buftype ==? 'help'
  535.                    \|set number
  536.                    \|set relativenumber
  537.                    \|exe "normal \<C-W>T"
  538.                \|endif
  539. augroup END
  540.  
  541.  
  542. " clear trailing whitespace on save
  543. augroup TrimWhitespace
  544.     autocmd!
  545.     autocmd BufWritePre *vimrc :%s/\s\+$//e
  546. augroup END
  547.  
  548.  
  549.  
  550. " ============= REGISTERS =============
  551.  
  552. " clear the search register for no highlighting
  553. let @/=''
  554. " macro to add a plugin
  555. let @p='gg/call plug#end()
  556. OPlug ''+'' " glip-"nkA '
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement