Mercurial > dotfiles
diff vim/vimrc @ 426:67f14a8c2304
Improve Vim configuration.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 28 Mar 2018 20:07:30 -0700 |
parents | d8086f81b9c8 |
children | 71a080d4d83c |
line wrap: on
line diff
--- a/vim/vimrc Wed Mar 28 20:07:21 2018 -0700 +++ b/vim/vimrc Wed Mar 28 20:07:30 2018 -0700 @@ -23,6 +23,9 @@ if has("win32") || has("win64") || has("dos32") let s:vim_platform = "windows" let s:path_sep = "\\" +elseif has("mac") + let s:vim_platform = "mac" + let s:path_sep = '/' else let s:vim_platform = "unix" let s:path_sep = '/' @@ -67,7 +70,7 @@ endif function! s:HasPlugin(plugname) abort - return globpath(&runtimepath, 'plugin/'.a:plugname.'.vim') !=# '' + return globpath(&runtimepath, 'plugin/'.a:plugname.'.vim') !=# '' endfunction " }}} @@ -255,8 +258,8 @@ " Ctrl-P should however ignore some stuff. let g:ctrlp_custom_ignore = { - \ 'dir': '\v[\/](\.git|\.hg|\.svn|venv|static|node_modules|_cache|_counter)$' - \ } + \ 'dir': '\v[\/](\.git|\.hg|\.svn|venv|static|node_modules|_cache|_counter)$' + \ } " Make Ctrl-P cache stuff in our temp directory. let g:ctrlp_cache_dir = s:vim_home.'/cache' @@ -274,17 +277,28 @@ \] " Use PyMatch to go faster. -if has('python3') || has('python') - let g:ctrlp_match_func = {'match': 'pymatcher#PyMatch'} - let g:ctrlp_max_files = 0 - let g:ctrlp_lazy_update = 350 +if (has('python3') || has('python')) && s:HasPlugin('ctrlp-py-matcher') + let g:ctrlp_match_func = {'match': 'pymatcher#PyMatch'} + let g:ctrlp_max_files = 0 + let g:ctrlp_lazy_update = 350 endif " }}} " FZF {{{ +if s:vim_platform == 'mac' + if filereadable('/usr/local/opt/fzf/plugin/fzf.vim') + " FZF installed via Homebrew. + source /usr/local/opt/fzf/plugin/fzf.vim + endif +endif +let g:fzf_action = { + \'ctrl-t': 'tab split', + \'ctrl-v': 'vsplit', + \'ctrl-x': 'split', + \} " }}} @@ -641,30 +655,30 @@ " YCM mappings. 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 + 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 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 + 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 @@ -672,37 +686,43 @@ \'help', 'nofile', 'quickfix'] function! s:AutoProjectRootCD() abort - try - if index(s:no_auto_projectroot_buftypes, &buftype) == -1 - ProjectRootCD - endif - catch - " Silently ignore invalid buffers - endtry + try + if index(s:no_auto_projectroot_buftypes, &buftype) == -1 + ProjectRootCD + endif + catch + " Silently ignore invalid buffers + endtry endfunction augroup VimRC_ProjectRoot - autocmd! - autocmd BufEnter * call <SID>AutoProjectRootCD() + autocmd! + autocmd BufEnter * call <SID>AutoProjectRootCD() augroup END nnoremap <leader>cd :ProjectRootCD<cr> " Ctrl-P mappings. if s:HasPlugin('ctrlp') - nnoremap <silent> <C-p> :CtrlP<cr> - nnoremap <silent> <C-o> :CtrlPBuffer<cr> - nnoremap <silent> <C-u> :CtrlPTag<cr> - nnoremap <silent> <C-y> :CtrlPBufTag<cr> - nnoremap <silent> <Tab> :CtrlPMRUFiles<cr> - nnoremap <silent> <F8> :CtrlPBookmarkDir<cr> + nnoremap <silent> <C-p> :CtrlP<cr> + nnoremap <silent> <C-o> :CtrlPBuffer<cr> + nnoremap <silent> <C-u> :CtrlPTag<cr> + nnoremap <silent> <C-y> :CtrlPBufTag<cr> + nnoremap <silent> <Tab> :CtrlPMRUFiles<cr> + nnoremap <silent> <F8> :CtrlPBookmarkDir<cr> endif " FZF mappings. if s:HasPlugin('fzf') - nnoremap <silent> <C-p> :Files<cr> - nnoremap <silent> <C-o> :Buffers<cr> - nnoremap <Tab> :History<cr> + if exists('*fzf#run') + nnoremap <silent> <C-p> :Files<cr> + nnoremap <silent> <C-o> :Buffers<cr> + nnoremap <Tab> :History<cr> + else + call ludo#error( + \"FZF is installed and enabled, but the Vim plugin ". + \"isn't loaded... add it to your `vimrc-local-pre`.") + endif endif " }}} @@ -772,13 +792,13 @@ endfunction function! s:ToggleCppFolding() abort - if (&foldmethod == "syntax") - setlocal foldmethod=manual - setlocal nofoldenable - else - setlocal foldmethod=syntax - setlocal foldenable - endif + if (&foldmethod == "syntax") + setlocal foldmethod=manual + setlocal nofoldenable + else + setlocal foldmethod=syntax + setlocal foldenable + endif endfunction " }}}