vimrc 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  1. " wreed vimrc
  2. " vim:foldmethod=marker:foldlevel=0:
  3. let g:python3_host_prog = expand('$HOME') . '/.pyenv/versions/nvim/bin/python3'
  4. "{{{ ***** PLUGINS INSTALLATION ***** "
  5. " ##### vim-plug #####
  6. set nocompatible
  7. call plug#begin('~/.vim/bundle')
  8. " **** Major Functionality Plugins
  9. Plug 'nvim-lua/plenary.nvim'
  10. Plug 'AckslD/swenv.nvim'
  11. " coc.nvim - code completion
  12. Plug 'neoclide/coc.nvim', {'branch': 'release'}
  13. Plug 'clangd/coc-clangd'
  14. " Linters
  15. Plug 'mfussenegger/nvim-lint'
  16. " tree-sitter - syntax parsing
  17. Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
  18. " Snippet completion
  19. Plug 'SirVer/ultisnips' ", { 'on': []}
  20. " Dependency for vim-snippets
  21. Plug 'tomtom/tlib_vim'
  22. " A library of snippets that work with Utilsnip
  23. Plug 'honza/vim-snippets'
  24. " Asynchonous building and launching of programs
  25. Plug 'tpope/vim-dispatch'
  26. Plug '5long/pytest-vim-compiler'
  27. " Run tests
  28. " Plug 'janko-m/vim-test'
  29. " Amazing plugin that makes a lot of things obsolete...
  30. "Plug 'Shougo/unite.vim'
  31. "Plug 'Shougo/denite.nvim'
  32. "Plug 'Shougo/neomru.vim'
  33. "Plug 'Shougo/neoyank.vim'
  34. " Plug 'Shougo/unite-outline'
  35. " Diff directories quickly and powerfully
  36. Plug 'will133/vim-dirdiff'
  37. " Diff individual sections of code
  38. Plug 'AndrewRadev/linediff.vim'
  39. " Show differences with style
  40. Plug 'mhinz/vim-signify'
  41. " Better diffs (optionaly)
  42. Plug 'chrisbra/vim-diff-enhanced'
  43. " Gives a graphical view of vim's undo tree (replaced by neovim-compatible
  44. " fork)
  45. "Plugin 'sjl/gundo.vim'
  46. Plug 'simnalamburt/vim-mundo'
  47. " Plug 'mbbill/undotree'
  48. " Git integration
  49. Plug 'tpope/vim-fugitive'
  50. Plug 'tpope/vim-rhubarb'
  51. " Easy alignment
  52. Plug 'junegunn/vim-easy-align'
  53. " command line fuzzy finder
  54. Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
  55. Plug 'junegunn/fzf.vim'
  56. " **** Basic editing and functionality
  57. " Matching things in insert mode
  58. Plug 'Raimondi/delimitMate'
  59. " Comments
  60. " Way more lightweight comment plugin
  61. Plug 'tpope/vim-commentary'
  62. " Makes motions way better. lets you jump anywhere on the screen
  63. " Plug 'Lokaltog/vim-easymotion'
  64. Plug 'justinmk/vim-sneak'
  65. " ability to surround text objects with things like quotes or parens
  66. Plug 'tpope/vim-surround'
  67. " Better text objects
  68. Plug 'wellle/targets.vim'
  69. " Heuristically set indent settings
  70. Plug 'tpope/vim-sleuth'
  71. " Better ways to deal with extra whitespace
  72. Plug 'ntpeters/vim-better-whitespace'
  73. " **** Language-specific plugins
  74. " switch between header files easily
  75. Plug 'vim-scripts/a.vim'
  76. " pretty JSON stuff
  77. Plug 'elzr/vim-json'
  78. " coding in GO
  79. Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' }
  80. " Markdown viewing
  81. " Plug 'suan/vim-instant-markdown', {'for': 'markdown'}
  82. " Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']}
  83. " Behave integration
  84. Plug 'avanzzzi/behave.vim', {'for': 'cucumber'}
  85. Plug 'gisraptor/vim-lilypond-integrator', {'frozen': 1, 'for': ['lilypond']}
  86. Plug 'hashivim/vim-terraform'
  87. Plug 'andrewstuart/vim-kubernetes'
  88. " **** UX enhancements
  89. " Make vim priiiiity
  90. Plug 'bling/vim-airline'
  91. Plug 'vim-airline/vim-airline-themes'
  92. " Make Tmux pretty
  93. Plug 'edkolev/tmuxline.vim'
  94. " Shows file browser. (replaces netrw and :Explore)
  95. Plug 'scrooloose/nerdtree', { 'on': ['NERDTreeToggle', 'NERDTreeFind']}
  96. " show tabs up on top prettily
  97. Plug 'mkitt/tabline.vim'
  98. " shows an outline of all Tags in a file
  99. Plug 'majutsushi/tagbar'
  100. " Fancy start screen
  101. Plug 'mhinz/vim-startify'
  102. " **** SYNTAX Files
  103. " Plug 'linkinpark342/xonsh-vim'
  104. Plug 'stephpy/vim-yaml'
  105. Plug 'solarnz/thrift.vim'
  106. Plug 'martinda/Jenkinsfile-vim-syntax'
  107. Plug 'mustache/vim-mustache-handlebars'
  108. " **** COLORSCHEMES
  109. "COLORSCHEMES
  110. Plug 'vim-scripts/devbox-dark-256'
  111. " end installed plugins
  112. call plug#end()
  113. " }}}
  114. "{{{ ***** PLUGIN SETTINGS ***** "
  115. " {{{##### Vim-Sneak #####
  116. let g:sneak#label = 1
  117. nmap s <Plug>Sneak_s
  118. xmap s <Plug>Sneak_s
  119. omap s <Plug>Sneak_s
  120. nmap S <Plug>Sneak_S
  121. xmap S <Plug>Sneak_S
  122. omap S <Plug>Sneak_S
  123. " 1-character enhanced 'f'
  124. nmap f <Plug>Sneak_f
  125. nmap F <Plug>Sneak_F
  126. xmap f <Plug>Sneak_f
  127. xmap F <Plug>Sneak_F
  128. omap f <Plug>Sneak_f
  129. omap F <Plug>Sneak_F
  130. " 1-character enhanced 't'
  131. nmap t <Plug>Sneak_t
  132. nmap T <Plug>Sneak_T
  133. xmap t <Plug>Sneak_t
  134. xmap T <Plug>Sneak_T
  135. omap t <Plug>Sneak_t
  136. omap T <Plug>Sneak_T
  137. " this seems weird, but it's to maintain motor memory with EasyMotion
  138. nmap <Leader>w <Plug>(SneakStreak)
  139. nmap <Leader>W <Plug>(SneakStreakBackward)
  140. "}}}
  141. " {{{##### Tagbar #####
  142. let g:tagbar_autofocus = 1
  143. let g:tagbar_left = 1
  144. let g:tagbar_zoomwidth = 0
  145. let g:tagbar_show_linenumbers = -1
  146. let g:tagbar_foldlevel = 0
  147. let g:tagbar_autoshowtag = 1
  148. let g:tagbar_sort = 0
  149. " open Tagbar automatically when viewing a supported file/files
  150. "autocmd VimEnter * nested :call tagbar#autoopen(1)
  151. " open Tagbar automatically when entering a buffer of supported file/files
  152. "autocmd BufEnter * nested :call tagbar#autoopen(0)
  153. " Toggle Tagbar
  154. nnoremap <leader>tt :TagbarToggle<CR>
  155. "}}}
  156. " {{{##### Airline #####
  157. let g:airline_powerline_fonts=1
  158. " only if YCM is enabled
  159. " autocmd User YouCompleteMe let g:airline#extensions#ycm#enabled = 1 | AirlineRefresh
  160. let g:airline#extensions#tabline#enabled = 1
  161. let g:airline#extentions#tabline#show_splits = 1
  162. let g:airline#extensions#tabline#show_tab_nr = 1
  163. let g:airline#extensions#tabline#tab_nr_type = 2
  164. let g:airline#extensions#tabline#show_close_button =1
  165. let g:airline#extensions#ycm#enabled = 1
  166. let g:airline#extensions#tagbar#flags = 'f'
  167. let g:airline#extensions#tagbar#enabled = 1
  168. let g:airline#extensions#whitespace#enabled = 1
  169. let g:airline#extensions#tmuxline#enabled = 1
  170. let g:airline#extensions#tabline#buffer_idx_mode = 1
  171. nmap <silent> <leader>1 <Plug>AirlineSelectTab1
  172. nmap <silent> <leader>2 <Plug>AirlineSelectTab2
  173. nmap <silent> <leader>3 <Plug>AirlineSelectTab3
  174. nmap <silent> <leader>4 <Plug>AirlineSelectTab4
  175. nmap <silent> <leader>5 <Plug>AirlineSelectTab5
  176. nmap <silent> <leader>6 <Plug>AirlineSelectTab6
  177. nmap <silent> <leader>7 <Plug>AirlineSelectTab7
  178. nmap <silent> <leader>8 <Plug>AirlineSelectTab8
  179. nmap <silent> <leader>9 <Plug>AirlineSelectTab9
  180. " }}}
  181. " {{{##### NERDTree #####
  182. let g:NERDTreeHijackNetrw = 1
  183. let g:NERDTreeDirArrows = 1
  184. let g:NERDTreeWinPos = "right"
  185. let g:NERDTreeMouseMode = 2
  186. let g:NERDTreeShowLineNumbers = 1
  187. let g:NERDTreeIgnore=['\~$', '\.vim$', '\.d$', '\.sw.$']
  188. nnoremap <leader>nt :NERDTreeToggle<CR>
  189. nnoremap <leader>nf :NERDTreeFind<CR>
  190. " }}}
  191. " {{{##### UltiSnips #####
  192. let g:UltiSnipsEditSplit = "vertical"
  193. let g:UltiSnipsExpandTrigger = "<C-Space>"
  194. let g:UltiSnipsJumpForwardTrigger="<TAB>"
  195. let g:UltiSnipsJumpBackwardTrigger="<S-TAB>"
  196. let g:UltiSnipsSnippetsDir="~/.vim/UltiSnips"
  197. " }}}
  198. " {{{##### Linters #####
  199. lua require('lint').linters_by_ft = { python = {'mypy'} }
  200. command! -nargs=* Lint lua require('lint').try_lint(<f-args>)
  201. au BufWritePost,BufRead * Lint
  202. " }}}
  203. " {{{ ##### FZF #####
  204. command! -nargs=* -complete=dir Cd call fzf#run(fzf#wrap(
  205. \ {'source': 'find '.(empty([<f-args>]) ? '.' : expand(<f-args>)).' -type d',
  206. \ 'sink': 'cd'}))
  207. function! Bufs()
  208. redir => list
  209. silent ls
  210. redir END
  211. return split(list, "\n")
  212. endfunction
  213. command! BufferDelete call fzf#run(fzf#wrap({
  214. \ 'source': Bufs(),
  215. \ 'sink*': { lines -> execute('bwipeout '.join(map(lines, {_, line -> split(line)[0]}))) },
  216. \ 'options': '--multi --bind ctrl-a:select-all+accept --prompt BufDelete'
  217. \ }))
  218. " \ 'options': '+m -x --tiebreak=index --header-lines=1 --ansi -d \t -n "2,1..2" --prompt BufDelete>'
  219. nnoremap <leader>cd :Cd<CR>
  220. nnoremap <leader><leader>cd :Cd ~<CR>
  221. nnoremap <leader>e :Files<CR>
  222. nnoremap <leader><leader>e :Files ~<CR>
  223. nnoremap <leader>be :Buffers<CR>
  224. nnoremap <leader>bd :BufferDelete<CR>
  225. nnoremap <leader>/ :BLines<CR>
  226. nnoremap <leader>gst :GFiles!?<CR>
  227. " }}}
  228. " {{{##### JSON.vim #####
  229. augroup json_autocmd
  230. autocmd!
  231. autocmd FileType json set autoindent
  232. autocmd FileType json set formatoptions=cq2
  233. autocmd FileType json set foldmethod=indent
  234. augroup END
  235. autocmd filetype crontab setlocal nobackup nowritebackup
  236. " }}}
  237. " {{{##### DirDiff #####
  238. let g:DirDiffExcludes = ".*.*.swp,*.d"
  239. " }}}
  240. " {{{##### Mundo #####
  241. nnoremap <leader>u :MundoToggle<CR>
  242. let g:mundo_playback_delay = 300
  243. let g:mundo_preview_bottom = 1
  244. " }}}
  245. " {{{##### EasyAlign #####
  246. vmap <Enter> <Plug>(LiveEasyAlign)
  247. let g:easy_align_delimiters = {
  248. \ '\': {
  249. \ 'pattern': '\\' },
  250. \ '/': {
  251. \ 'pattern': '//\+\|/\*\|\*/',
  252. \ 'delimiter_align': 'l',
  253. \ 'ignore_groups': ['!Comment'] },
  254. \ }
  255. " }}}
  256. " {{{##### DelimitMate #####
  257. let delimitMate_expand_space = 1
  258. let delimitMate_expand_cr = 1
  259. imap <c-l> <Plug>delimitMateS-Tab
  260. " }}}
  261. " {{{##### Startify #####
  262. let g:startify_lists = [
  263. \ { 'type': 'dir', 'header': [ 'MRU '. getcwd()] },
  264. \ { 'type': 'files', 'header': [ 'MRU'] },
  265. \ { 'type': 'sessions', 'header': [ 'Sessions'] },
  266. \ { 'type': 'bookmarks', 'header': [ 'Bookmarks'] },
  267. \ { 'type': 'commands', 'header': [ 'Commands'] },
  268. \ ]
  269. " let g:startify_bookmarks = [ {'v': '~/.vim/vimrc'} ]
  270. let g:startify_commands = [
  271. \ {'rc': 'EditVimrc'},
  272. \ {'crc': 'EditCustomVimrc'},
  273. \ {'p': 'PlugUpdate'}]
  274. let g:startify_session_delete_buffers = 1
  275. if has('nvim')
  276. let g:startify_custom_header =
  277. \ map(split(system('toilet Nvim -t -W -F border'), '\n'), '" ". v:val') + ['','']
  278. " \ map(split(system('cowsay -f dragon Welcome to VIM | sed "s/ *$//"'), '\n'), '" ". v:val') + ['','']
  279. " \ map(split(system('fortune | cowsay'), '\n'), '" ". v:val') + ['','']
  280. else
  281. let g:startify_custom_header =
  282. \ map(split(system('toilet Vim -t -W -F border'), '\n'), '" ". v:val') + ['','']
  283. endif
  284. " }}}
  285. " {{{##### Signify #####
  286. let g:signify_vcs_list = ['git']
  287. omap ih <plug>(signify-motion-inner-pending)
  288. xmap ih <plug>(signify-motion-inner-visual)
  289. omap ah <plug>(signify-motion-outer-pending)
  290. xmap ah <plug>(signify-motion-outer-visual)
  291. " }}}
  292. " {{{ ##### vim-colorscheme switcher #####
  293. let g:colorscheme_switcher_define_mappings = 0
  294. let g:colorscheme_switcher_exclude = []
  295. nnoremap <silent> <F9> :NextColorScheme<CR>
  296. nnoremap <silent> <S-F9> :PrevColorScheme<CR>
  297. nnoremap <silent> <leader><F9> :RandomColorScheme<CR>
  298. " }}}
  299. " {{{ ##### vim-fugitive #####
  300. augroup rebase_tools
  301. autocmd!
  302. autocmd FileType gitrebase nnoremap <buffer> <leader>] :Gedit <c-r><c-w><CR>
  303. autocmd FileType gitrebase nnoremap <buffer> <leader>p :Pick <CR>j
  304. autocmd FileType gitrebase nnoremap <buffer> <leader>r :Reword <CR>j
  305. autocmd FileType gitrebase nnoremap <buffer> <leader>e :Edit <CR>j
  306. autocmd FileType gitrebase nnoremap <buffer> <leader>sq :Squash <CR>j
  307. autocmd FileType gitrebase nnoremap <buffer> <leader>f :Fixup <CR>j
  308. augroup END
  309. command! Jenkins execute 'Gcommit -a --fixup=HEAD' | Gpush
  310. " }}}
  311. " {{{ ##### vim-go #####
  312. let g:go_def_mapping_enabled = 0
  313. let g:go_fmt_experimental = 1 " retains folds on save (For some reason) https://github.com/fatih/vim-go/issues/502
  314. augroup vimgosettings
  315. " autocmd FileType go nmap <leader>] :GoDef<CR>
  316. au FileType go nmap <F4> <Plug>(go-test)
  317. au FileType go nmap <leader><F4> <Plug>(go-lint)
  318. au FileType go nmap <F3> <Plug>(go-build)
  319. au FileType go nmap <leader><F3> <Plug>(go-install)
  320. au FileType go nmap <F2> <Plug>(go-imports)
  321. au FileType go nmap <leader>ie <Plug>(go-iferr)
  322. augroup END
  323. " }}}
  324. " {{{ ##### coc.nvim #####
  325. " Having longer updatetime (default is 4000 ms = 4s) leads to noticeable
  326. " delays and poor user experience
  327. set updatetime=300
  328. " Always show the signcolumn, otherwise it would shift the text each time
  329. " diagnostics appear/become resolved
  330. set signcolumn=yes
  331. " Use tab for trigger completion with characters ahead and navigate
  332. " NOTE: There's always complete item selected by default, you may want to enable
  333. " no select by `"suggest.noselect": true` in your configuration file
  334. " NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
  335. " other plugin before putting this into your config
  336. inoremap <silent><expr> <TAB>
  337. \ coc#pum#visible() ? coc#pum#next(1) :
  338. \ CheckBackspace() ? "\<Tab>" :
  339. \ coc#refresh()
  340. inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
  341. " Make <CR> to accept selected completion item or notify coc.nvim to format
  342. " <C-g>u breaks current undo, please make your own choice
  343. inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
  344. \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
  345. function! CheckBackspace() abort
  346. let col = col('.') - 1
  347. return !col || getline('.')[col - 1] =~# '\s'
  348. endfunction
  349. " Use <c-space> to trigger completion
  350. if has('nvim')
  351. inoremap <silent><expr> <c-space> coc#refresh()
  352. else
  353. inoremap <silent><expr> <c-@> coc#refresh()
  354. endif
  355. " Use `[g` and `]g` to navigate diagnostics
  356. " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list
  357. nmap <silent> [g <Plug>(coc-diagnostic-prev)
  358. nmap <silent> ]g <Plug>(coc-diagnostic-next)
  359. " GoTo code navigation
  360. nmap <silent> gd <Plug>(coc-definition)
  361. nmap <silent> gy <Plug>(coc-type-definition)
  362. nmap <silent> gi <Plug>(coc-implementation)
  363. nmap <silent> gr <Plug>(coc-references)
  364. " Use K to show documentation in preview window
  365. nnoremap <silent> K :call <SID>show_documentation()<CR>
  366. " let g:coc_node_path = '/snap/bin/node'
  367. function! s:show_documentation()
  368. if (index(['vim','help'], &filetype) >= 0)
  369. execute 'h '.expand('<cword>')
  370. else
  371. call CocAction('doHover')
  372. endif
  373. endfunction
  374. " Highlight the symbol and its references when holding the cursor
  375. autocmd CursorHold * silent call CocActionAsync('highlight')
  376. " Symbol renaming
  377. nmap <leader>rn <Plug>(coc-rename)
  378. " Formatting selected code
  379. xmap <leader>f <Plug>(coc-format-selected)
  380. nmap <leader>f <Plug>(coc-format-selected)
  381. augroup mygroup
  382. autocmd!
  383. " Setup formatexpr specified filetype(s)
  384. autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  385. " Update signature help on jump placeholder
  386. autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
  387. augroup end
  388. " Applying code actions to the selected code block
  389. " Example: `<leader>aap` for current paragraph
  390. xmap <leader>a <Plug>(coc-codeaction-selected)
  391. nmap <leader>a <Plug>(coc-codeaction-selected)
  392. " Remap keys for applying code actions at the cursor position
  393. nmap <leader>ac <Plug>(coc-codeaction-cursor)
  394. " Remap keys for apply code actions affect whole buffer
  395. nmap <leader>as <Plug>(coc-codeaction-source)
  396. " Apply the most preferred quickfix action to fix diagnostic on the current line
  397. nmap <leader>qf <Plug>(coc-fix-current)
  398. " Remap keys for applying refactor code actions
  399. nmap <silent> <leader>re <Plug>(coc-codeaction-refactor)
  400. xmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected)
  401. nmap <silent> <leader>r <Plug>(coc-codeaction-refactor-selected)
  402. " Run the Code Lens action on the current line
  403. nmap <leader>cl <Plug>(coc-codelens-action)
  404. " Map function and class text objects
  405. " NOTE: Requires 'textDocument.documentSymbol' support from the language server
  406. xmap if <Plug>(coc-funcobj-i)
  407. omap if <Plug>(coc-funcobj-i)
  408. xmap af <Plug>(coc-funcobj-a)
  409. omap af <Plug>(coc-funcobj-a)
  410. xmap ic <Plug>(coc-classobj-i)
  411. omap ic <Plug>(coc-classobj-i)
  412. xmap ac <Plug>(coc-classobj-a)
  413. omap ac <Plug>(coc-classobj-a)
  414. " Use CTRL-S for selections ranges
  415. " Requires 'textDocument/selectionRange' support of language server
  416. nmap <silent> <C-s> <Plug>(coc-range-select)
  417. xmap <silent> <C-s> <Plug>(coc-range-select)
  418. " Add `:Format` command to format current buffer
  419. command! -nargs=0 Format :call CocActionAsync('format')
  420. " Add `:Fold` command to fold current buffer
  421. command! -nargs=? Fold :call CocAction('fold', <f-args>)
  422. " Add `:OR` command for organize imports of the current buffer
  423. command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport')
  424. " Add (Neo)Vim's native statusline support
  425. " NOTE: Please see `:h coc-status` for integrations with external plugins that
  426. " provide custom statusline: lightline.vim, vim-airline
  427. set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
  428. " Mappings for CoCList
  429. " Show all diagnostics
  430. nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
  431. " Manage extensions
  432. nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
  433. " Show commands
  434. nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
  435. " Find symbol of current document
  436. nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
  437. " Search workspace symbols
  438. nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
  439. " Do default action for next item
  440. nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
  441. " Do default action for previous item
  442. nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
  443. " Resume latest coc list
  444. nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>
  445. " }}}
  446. " {{{ ##### instant-markdown-viewer #####
  447. " let g:instant_markdown_python = 1
  448. let g:instant_markdown_autostart = 0
  449. " }}}
  450. " {{{ ##### markdown-preview #####
  451. let g:mkdp_preview_options = {
  452. \'maid': {
  453. \ "maxTextSize": 99999999,
  454. \},
  455. \}
  456. " }}}
  457. " {{{ ##### Tree-sitter #####
  458. " lua << EOF
  459. " require'nvim-treesitter.configs'.setup {
  460. " -- A list of parser names, or "all" (the listed parsers MUST always be installed)
  461. " ensure_installed = { "vim", "vimdoc", "query", "markdown", "markdown_inline", "go", "python" },
  462. " -- Install parsers synchronously (only applied to `ensure_installed`)
  463. " sync_install = false,
  464. " -- Automatically install missing parsers when entering buffer
  465. " -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
  466. " auto_install = false,
  467. " -- List of parsers to ignore installing (or "all")
  468. " -- ignore_install = { "javascript" },
  469. " ---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
  470. " -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!
  471. " highlight = {
  472. " enable = true,
  473. " -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
  474. " -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
  475. " -- the name of the parser)
  476. " -- list of language that will be disabled
  477. " -- disable = { "c", "rust" },
  478. " -- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files
  479. " -- disable = function(lang, buf)
  480. " -- local max_filesize = 100 * 1024 -- 100 KB
  481. " -- local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
  482. " -- if ok and stats and stats.size > max_filesize then
  483. " -- return true
  484. " -- end
  485. " -- end,
  486. " -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
  487. " -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
  488. " -- Using this option may slow down your editor, and you may see some duplicate highlights.
  489. " -- Instead of true it can also be a list of languages
  490. " additional_vim_regex_highlighting = false,
  491. " },
  492. " }
  493. " EOF
  494. " }}}
  495. " }}}
  496. "{{{ ***** VIM FEATURES ***** "
  497. " allow project-specific .vimrc files
  498. if has('nvim')
  499. set shada+=f10
  500. endif
  501. set exrc
  502. set secure
  503. " allow the use of a modeline
  504. set modeline
  505. " automatically read a file if it changes outside of vim
  506. set autoread
  507. " hide buffers by default instead of unloading them
  508. set hidden
  509. " turn ruler on
  510. set ruler
  511. " set incremental search
  512. set hlsearch
  513. set incsearch
  514. if has('nvim')
  515. set inccommand=split
  516. endif
  517. " set status line always on
  518. if exists("g:gui_oni")
  519. set noshowmode
  520. set noruler
  521. set laststatus=0
  522. set noshowcmd
  523. else
  524. set laststatus=2
  525. endif
  526. set shortmess+=c
  527. " turn vim's mode printing off. Airline takes care of this
  528. set noshowmode
  529. " shorten the pause after leaving insert mode
  530. set ttimeoutlen=50
  531. " set mouse always on. I like the mouse sometimes
  532. set mouse=a
  533. " 256 stuff
  534. " disable BackgroundColorErase (BCE) inside of 256-color tmux sessions
  535. if &term =~ '256color'
  536. set t_ut=
  537. endif
  538. " OR... do this shit instead
  539. if &term =~ '^screen'
  540. " tmux will send xterm-style keys when xterm-keys is on
  541. execute "set <xUp>=\e[1;*A"
  542. execute "set <xDown>=\e[1;*B"
  543. execute "set <xRight>=\e[1;*C"
  544. execute "set <xLeft>=\e[1;*D"
  545. endif
  546. " set utf8
  547. if !has('nvim')
  548. " set encoding=utf-8
  549. endif
  550. " set fileencoding=utf-8
  551. " New Splits default to right, or below
  552. set splitbelow
  553. set splitright
  554. set diffopt+=vertical
  555. "turn omnicomplete on
  556. set omnifunc=syntaxcomplete#Complete
  557. " enable persistant undo history
  558. set undofile
  559. set undodir=~/.vim/undodir
  560. " format options
  561. set expandtab
  562. " set shiftwidth=4
  563. " set softtabstop=4
  564. set tabstop=4
  565. set autoindent
  566. set nosmartindent
  567. set cindent
  568. set cino=l1,t0,(0
  569. set breakindent
  570. set showbreak=↳
  571. set breakindentopt=min:20
  572. " TOhtml settings
  573. let g:html_ignore_conceal=1
  574. let g:html_dynamic_folds=1
  575. " folding options
  576. set foldlevelstart=99
  577. set foldmethod=syntax
  578. augroup folding_settings
  579. autocmd FileType python,xonsh,yaml,thrift set foldmethod=indent
  580. augroup END
  581. " set filetype options
  582. au BufNewFile,BufRead *.xsh set filetype=python
  583. au BufNewFile,BufRead Dockerfile* set filetype=dockerfile
  584. " md options
  585. augroup md_settings
  586. autocmd FileType markdown set textwidth=80
  587. autocmd FileType markdown set nocindent
  588. autocmd FileType markdown set spell
  589. augroup END
  590. set wildmode=longest:full
  591. " switch ' and `
  592. noremap ' `
  593. noremap ` '
  594. noremap Y y$
  595. noremap <leader>y "*y
  596. noremap <leader>p "*p
  597. " In nvim, open keyword/help in new terminal,
  598. " as nvim doesn't currently allow terminal scrollback.
  599. function! KeywordNvim(searchTerm)
  600. if &keywordprg == ':Man'
  601. exe ':Man ' . a:searchTerm
  602. else
  603. let l:man = &keywordprg
  604. vsplit | enew
  605. exe 'terminal ' . l:man a:searchTerm
  606. normal i
  607. endif
  608. endfunction
  609. function! KeywordNvimVisual()
  610. let l:saved_reg = @"
  611. execute "normal! vgvy"
  612. call KeywordNvim(@")
  613. let @" = l:saved_reg
  614. endfunction
  615. " if has("nvim")
  616. " nnoremap K :call KeywordNvim(expand("<cword>"))<CR>
  617. " vnoremap K <Esc>:call KeywordNvimVisual()<CR>
  618. " endif
  619. let g:clipboard = {
  620. \ 'name': 'My xsel',
  621. \ 'copy': {
  622. \ '+': 'xsel -i',
  623. \ '*': 'xsel -ib',
  624. \ },
  625. \ 'paste': {
  626. \ '+': 'xsel -i',
  627. \ '*': 'xsel -ib',
  628. \ },
  629. \ 'cache_enabled': 1,
  630. \ }
  631. " comment strings
  632. augroup comment_strings
  633. autocmd FileType python set commentstring=#\ %s
  634. augroup END
  635. " }}}
  636. "{{{ ***** VISUALS ***** "
  637. set number
  638. set relativenumber
  639. set expandtab
  640. set shiftwidth=2
  641. set softtabstop=2
  642. set autoindent
  643. set nosmartindent
  644. set foldmethod=indent
  645. set background=dark
  646. syntax on
  647. augroup numbertoggle
  648. autocmd!
  649. autocmd BufEnter,FocusGained,InsertLeave,WinEnter,CmdlineLeave * if &nu | set rnu | endif
  650. autocmd BufLeave,FocusLost,InsertEnter,WinLeave,CmdlineEnter * if &nu | set nornu | redraw | endif
  651. augroup END
  652. autocmd BufWinEnter * if line2byte(line("$") + 1) > 10000000 | syntax clear | endif
  653. colorscheme devbox-dark-256
  654. set termguicolors&
  655. set showcmd
  656. "}}}
  657. "{{{ ***** KEY MAPPINGS ***** "
  658. " make <C-A> work the same in tmux and not
  659. nnoremap <C-C> <C-A>
  660. " easier buffer navigation
  661. " nnoremap bn :bn<CR>
  662. " nnoremap bp :bp<CR>
  663. " make backspace work
  664. set backspace=eol,start,indent
  665. set whichwrap+=<,>,h,l
  666. set whichwrap+=<,>,h,l
  667. " nnoremap <silent> <F5> :so ~/.vim/vimrc<CR>:LvimrcReload<CR>
  668. nnoremap <silent> <F5> :so ~/.vim/vimrc<CR>
  669. nnoremap <silent> <F6> :redraw!<CR>
  670. " set pastetoggle=<F7>
  671. nmap <F8> :mks!<CR>
  672. " treat wrapped lines as multiple lines when navigating
  673. map j gj
  674. map k gk
  675. " Scroll the window more intuitively
  676. nnoremap <M-j> <C-e>
  677. nnoremap <M-k> <C-y>
  678. nnoremap <M-h> 10zh
  679. nnoremap <M-l> 10zl
  680. nnoremap j <C-e>
  681. nnoremap k <C-y>
  682. nnoremap h 10zh
  683. nnoremap l 10zl
  684. vnoremap <M-j> <C-e>
  685. vnoremap <M-k> <C-y>
  686. vnoremap <M-h> 10zh
  687. vnoremap <M-l> 10zl
  688. vnoremap j <C-e>
  689. vnoremap k <C-y>
  690. vnoremap h 10zh
  691. vnoremap l 10zl
  692. " Open a new line and exit insert mode, staying on the same line
  693. nnoremap <leader>o o<ESC>
  694. nnoremap <leader>O O<ESC>
  695. " Clean a line and exit insert mode
  696. nnoremap <leader>c cc<ESC>
  697. " Exit insert mode and put ';' at the end of the line
  698. " inoremap ;<Esc> <Esc>A;<Esc>
  699. " Open tag in new tab
  700. nnoremap <M-]> <C-W><C-]><C-W>T
  701. " Toggle TODOs as done or not
  702. nnoremap <silent> <leader>x :s/\[ \]TODO/[X]TODO/<CR>:nohl<CR>
  703. nnoremap <silent> <leader><space> :s/\[X\]TODO/[ ]TODO/<CR>:nohl<CR>
  704. " copy 'filename:linenumber' to @f register. useful for adding links to
  705. " places in files in comments
  706. nnoremap <silent> <leader>gf :let @f=@% . ':' . line('.')<CR>:echo @f<CR>
  707. " WINDOW ORGANISATION
  708. " Smart way to move between windows
  709. map <C-j> <C-W>j
  710. map <C-k> <C-W>k
  711. map <C-h> <C-W>h
  712. map <C-l> <C-W>l
  713. map <C-Up> <C-W>k
  714. map <C-Down> <C-W>j
  715. map <C-Left> <C-W>h
  716. map <C-Right> <C-W>l
  717. " easy resize windows
  718. nnoremap <S-Up> <C-W>+
  719. nnoremap <S-Down> <C-W>-
  720. nnoremap <S-Left> 3<C-W><
  721. nnoremap <S-Right> 3<C-W>>
  722. " easy move windows
  723. nnoremap <C-S-Up> <C-W><S-K>
  724. nnoremap <C-S-Down> <C-W><S-J>
  725. nnoremap <C-S-Left> <C-W><S-H>
  726. nnoremap <C-S-Right> <C-W><S-L>
  727. " close annoying windows easily
  728. nnoremap cq :cclose<CR>
  729. nnoremap cqq :lclose<CR>
  730. nnoremap cp :pclose<CR>
  731. " Call CopyMode
  732. vnoremap <C-c> :call CopyMode()<CR><CR>
  733. " Visual mode pressing * or # searches for the current selection
  734. " Super useful! From an idea by Michael Naumann
  735. vnoremap <silent> * :call VisualSelection('f')<CR>
  736. vnoremap <silent> # :call VisualSelection('b')<CR>
  737. " Default building/running options
  738. let g:run_command = 'echo No run command defined'
  739. nnoremap <leader>` :execute "Start " . g:run_command<CR>
  740. nnoremap <F3> :Make %<CR>
  741. autocmd FileType lilypond setlocal makeprg=lilypond
  742. augroup python_build
  743. autocmd FileType python compiler pylint
  744. autocmd FileType python nnoremap <F3> :Make %<CR>
  745. autocmd FileType python nnoremap <S-F3> :Make .<CR>
  746. autocmd FileType python nnoremap <F4> :Dispatch mypy %<CR>
  747. autocmd FileType python nnoremap <S-F4> :Dispatch mypy .<CR>
  748. augroup END
  749. " Quickly edit a macro
  750. nnoremap <leader>@ :<c-u><c-r><c-r>='let @'. v:register .' = '. string(getreg(v:register))<cr><c-f><left>
  751. " Quickly edit the Q macro
  752. nnoremap <leader>q :<c-u><c-r><c-r>='let @q = '. string(getreg('q'))<cr><c-f><left>
  753. " go back and delete last buffer (dangerous if the going back doesn't bring
  754. " you to another buffer
  755. nnoremap <M-C-O> <C-^>:bd! #<CR>
  756. " toggle number
  757. nnoremap <silent> -- :set number!<CR>
  758. " toggle cursorcolumn
  759. nnoremap <silent> scc :set cursorcolumn!<CR>
  760. " insert command at line
  761. inoremap <C-r>! <C-\><C-O>:let @r=system("")<left><left>
  762. " terminal escape
  763. " tnoremap <Esc><Esc> <C-\><C-N>
  764. " enter selects menu entry (<CR> is already remaped by delimitMate, so
  765. " hardcode what it does to mimic behavior)
  766. imap <expr> <CR> pumvisible() ? "\<C-Y>" : "<Plug>delimitMateCR"
  767. " base64 decode selected text
  768. :vnoremap <leader>64 d:let @@ = system('base64 --decode', @")<cr><esc>o<esc>p
  769. " }}}
  770. "{{{ ***** COMMANDS ***** "
  771. " Terminal commands
  772. command! -nargs=0 VTerm vsplit term://bash
  773. command! -nargs=0 STerm split term://bash
  774. command! -nargs=0 VPyTerm vsplit term://python3
  775. command! -nargs=0 SPyTerm split term://python3
  776. " make todo list
  777. " command! -nargs=* -complete=file Todos execute "Unite -keep-focus -auto-resize -no-quit -buffer-name=Todos vimgrep:%:TODO(" . expand("$USER") . ")"
  778. " Edit ~/.vim/vimrc in a new tab
  779. command! -nargs=0 EditVimrc tabedit ~/.vim/vimrc
  780. " Swap two lines
  781. command! -nargs=1 -range Swap call Swap(<f-args>)
  782. function! Swap(s1, s2, d1, d2)
  783. let cursor = line(".")
  784. echo "swap <" . a:s1 . "," . a:s2 . "> and <" . a:d1 . "," . a:d2 . ">"
  785. if a:s1 <= a:d1
  786. let l:source1 = a:s1
  787. let l:source2 = a:s2
  788. let l:dest1 = a:d1
  789. let l:dest2 = a:d2
  790. else
  791. let l:dest1 = a:s1
  792. let l:dest2 = a:s2
  793. let l:source1 = a:d1
  794. let l:source2 = a:d2
  795. endif
  796. let l:offset = l:source2 - l:source1
  797. execute l:source1 .",". lsource2 . "move " . l:dest2
  798. execute l:dest1 . "," . l:dest2 . "move " . l:source2
  799. execute l:source1 . ",". l:source2 . "normal =="
  800. execute l:dest1 . ",". l:dest2 . "normal =="
  801. execute "normal " . cursor . "G"
  802. endfunction
  803. function! CopyMode() range
  804. execute a:firstline . "," . a:lastline . "yank c"
  805. tabnew
  806. setlocal nonumber
  807. setlocal norelativenumber
  808. setlocal showbreak=
  809. map <buffer> <silent> <C-V> :bd!<CR>
  810. normal [p
  811. endfunction
  812. " Diff original file (from help)
  813. command! DiffOrig vert new | set bt=nofile | r ++edit # | 0d_
  814. \ | diffthis | wincmd p | diffthis
  815. " from https://amix.dk/vim/vimrc.html
  816. function! VisualSelection(direction) range
  817. let l:saved_reg = @"
  818. execute "normal! vgvy"
  819. let l:pattern = escape(@", '\\/.*$^~[]')
  820. let l:pattern = substitute(l:pattern, "\n", "", "")
  821. let l:pattern = '\<'.l:pattern.'\>'
  822. if a:direction == 'b'
  823. execute "normal ?" . l:pattern . "^M"
  824. " elseif a:direction == 'gv'
  825. " call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
  826. " elseif a:direction == 'replace'
  827. " call CmdLine("%s" . '/'. l:pattern . '/')
  828. elseif a:direction == 'f'
  829. " execute "normal /" . l:pattern . "^M"
  830. execute "normal /" . l:pattern
  831. endif
  832. let @/ = l:pattern
  833. let @" = l:saved_reg
  834. endfunction
  835. " }}}
  836. "{{{ ***** MACHINE SPECIFIC CONFIG ***** "
  837. command! -nargs=0 EditCustomVimrc tabedit ~/.vimrc_custom
  838. if filereadable($HOME . "/.vimrc_custom")
  839. source ~/.vimrc_custom
  840. endif
  841. "}}}
  842. lua << EOF
  843. require('swenv').setup({
  844. -- Should return a list of tables with a `name` and a `path` entry each.
  845. -- Gets the argument `venvs_path` set below.
  846. -- By default just lists the entries in `venvs_path`.
  847. get_venvs = function(venvs_path)
  848. return require('swenv.api').get_venvs(venvs_path)
  849. end,
  850. -- Path passed to `get_venvs`.
  851. venvs_path = vim.fn.expand('~/.pyenv/versions'),
  852. -- Something to do after setting an environment, for example call vim.cmd.LspRestart
  853. post_set_venv = function()
  854. vim.cmd.CocRestart()
  855. end,
  856. })
  857. EOF
  858. lua require('swenv.api').auto_venv()