diff vim/vimrc @ 420:e6b3048980c4

Vim tweaks - Properly check for whether a plugin is active. - Better function key shortcuts. - Remove `wildignore` from Gutentags command lines, add them to `ctagsrc`.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 13 Feb 2018 11:08:26 -0800
parents c4077384f55f
children d8086f81b9c8
line wrap: on
line diff
--- a/vim/vimrc	Sun Jan 21 12:51:19 2018 -0800
+++ b/vim/vimrc	Tue Feb 13 11:08:26 2018 -0800
@@ -69,6 +69,10 @@
     endif
 endif
 
+function! s:HasPlugin(plugname) abort
+  return globpath(&runtimepath, 'plugin/'.a:plugname.'.vim') !=# ''
+endfunction
+
 " }}}
 
 " General Settings {{{
@@ -292,6 +296,7 @@
 let g:gutentags_cache_dir = s:vim_home.'/tags'
 let g:gutentags_ctags_exclude = ['venv', 'build', 'static', 'node_modules']
 let g:gutentags_ctags_extra_args = ['--options='.s:vim_home.'/ctagsrc']
+let g:gutentags_ctags_exclude_wildignore = 0
 
 " }}}
 
@@ -528,18 +533,37 @@
 nnoremap <C-right> :wincmd l<cr>
 
 " Switch buffers.
-nnoremap <F2> :execute ("buffer " . bufname("#"))<cr>
+nnoremap <F1> :execute ("buffer " . bufname("#"))<cr>
 
 " NERDTree.
-nnoremap <F3> :call <SID>ToggleNERDTree()<cr>
-nnoremap <F4> :call <SID>FindInNERDTree()<cr>
+nnoremap <F2> :call <SID>ToggleNERDTree()<cr>
+nnoremap <C-F2> :call <SID>FindInNERDTree()<cr>
 
 " Tagbar.
-nnoremap <F5> :TagbarToggle<cr>
-nnoremap <F6> :TagbarOpenAutoClose<cr>
+nnoremap <F3> :TagbarToggle<cr>
+nnoremap <C-F3> :TagbarOpenAutoClose<cr>
 
 " Gundo.
-nnoremap <F7> :GundoToggle<cr>
+nnoremap <F4> :GundoToggle<cr>
+
+" F5 to F8 are available for context-dependent mappings.
+
+" Jump to tags by keeping things better in view. Option for jumping to a tag
+" in a split window where everything is folded except what you need to see.
+" Note that if a tag search yield multiple possible results, we will still run
+" some of that `zvzz` stuff, but that's OK, the main point is to not mess up
+" the result selection window either.
+"
+" Go back after checking out a tag.
+nnoremap <F9> :pop<CR>
+" Go check out a tag.
+nnoremap <F10> g<C-]>zvzz
+" Go check out a tag in a split window.
+nnoremap <S-F10> <C-W>vg<C-]>zMzvzz
+" Move to previous matching tag.
+nnoremap <C-F9> :tprevious<CR>
+" Move to next matching tag.
+nnoremap <C-F10> :tnext<CR>
 
 " Common typos.
 nnoremap ; :
@@ -614,43 +638,37 @@
 nnoremap <leader>fa :vimgrep /<C-R><C-W>/ 
 vnoremap <leader>fa "zy:vimgrep /<C-R>z/ 
 
-" Jump to tags by keeping things better in view. Option for jumping to a tag
-" in a split window where everything is folded except what you need to see.
-" Note that if a tag search yield multiple possible results, we will still run
-" some of that `zvzz` stuff, but that's OK, the main point is to not mess up
-" the result selection window either.
-nnoremap <F9> :pop<cr>
-nnoremap <F10> g<C-]>zvzz
-nnoremap <s-F10> <c-w>vg<C-]>zMzvzz
-nnoremap <c-F9> :tprevious
-nnoremap <c-F10> :tnext
-
 " Keep search matches in the middle of the window.
 nnoremap n nzvzz
 nnoremap N Nzvzz
 
 " YCM mappings.
-augroup VimRC_YouCompleteMe
-  autocmd!
-  autocmd FileType cpp nnoremap <Leader>jj :YcmCompleter GoToImprecise<cr>zv
-  autocmd FileType cpp nnoremap <Leader>jd :YcmCompleter GoToDefinition<cr>zv
-  autocmd FileType cpp nnoremap <Leader>jh :YcmCompleter GoToDeclaration<cr>zv
-  autocmd FileType cpp nnoremap <Leader>ji :YcmCompleter GoToInclude<cr>
-  autocmd FileType cpp nnoremap <Leader>jc  :YcmCompleter GetDoc<cr>
-augroup END
+if s:HasPlugin('youcompleteme')
+  augroup VimRC_YouCompleteMe
+    autocmd!
+    autocmd FileType cpp nnoremap <Leader>jj :YcmCompleter GoToImprecise<cr>zv
+    autocmd FileType cpp nnoremap <Leader>jd :YcmCompleter GoToDefinition<cr>zv
+    autocmd FileType cpp nnoremap <Leader>jh :YcmCompleter GoToDeclaration<cr>zv
+    autocmd FileType cpp nnoremap <Leader>ji :YcmCompleter GoToInclude<cr>
+    autocmd FileType cpp nnoremap <Leader>jc :YcmCompleter GetDoc<cr>
+    autocmd FileType cpp nnoremap <Leader>je :YcmShowDetailedDiagnostic<cr>
+  augroup END
+endif
 
 " OmniSharp mappings
-augroup VimRC_OmniSharp
-  autocmd!
-  autocmd FileType cs setlocal omnifunc=OmniSharp#Complete
-  autocmd BufEnter,TextChanged,InsertLeave *.cs SyntasticCheck
-  autocmd CursorHold *.cs call OmniSharp#TypeLookupWithoutDocumentation()
-  autocmd FileType cs nnoremap <Leader>jj :OmniSharpGotoDefinition<cr>
-  autocmd FileType cs nnoremap <Leader>x  :OmniSharpFixIssue<cr>
-  autocmd FileType cs nnoremap <Leader>fx :OmniSharpFixUsings<cr>
-  autocmd FileType cs nnoremap <Leader>tt :OmniSharpTypeLookup<cr>
-  autocmd FileType cs nnoremap <Leader>dc :OmniSharpDocumentation<cr>
-augroup END
+if s:HasPlugin('OmniSharp')
+  augroup VimRC_OmniSharp
+    autocmd!
+    autocmd FileType cs setlocal omnifunc=OmniSharp#Complete
+    autocmd BufEnter,TextChanged,InsertLeave *.cs SyntasticCheck
+    autocmd CursorHold *.cs call OmniSharp#TypeLookupWithoutDocumentation()
+    autocmd FileType cs nnoremap <Leader>jj :OmniSharpGotoDefinition<cr>
+    autocmd FileType cs nnoremap <Leader>x  :OmniSharpFixIssue<cr>
+    autocmd FileType cs nnoremap <Leader>fx :OmniSharpFixUsings<cr>
+    autocmd FileType cs nnoremap <Leader>tt :OmniSharpTypeLookup<cr>
+    autocmd FileType cs nnoremap <Leader>dc :OmniSharpDocumentation<cr>
+  augroup END
+endif
 
 " ProjectRoot mappings
 let s:no_auto_projectroot_buftypes = [
@@ -674,7 +692,7 @@
 nnoremap <leader>cd :ProjectRootCD<cr>
 
 " Ctrl-P mappings.
-if index(g:pathogen_disabled, 'ctrlp') < 0
+if s:HasPlugin('ctrlp')
   nnoremap <silent> <C-p> :CtrlP<cr>
   nnoremap <silent> <C-o> :CtrlPBuffer<cr>
   nnoremap <silent> <C-u> :CtrlPTag<cr>
@@ -684,7 +702,7 @@
 endif
 
 " FZF mappings.
-if index(g:pathogen_disabled, 'fzf') < 0
+if s:HasPlugin('fzf')
   nnoremap <silent> <C-p> :Files
   nnoremap <silent> <C-o> :Buffers
 endif