Mercurial > dotfiles
changeset 495:232351531855
Vim config improvements
- Support for gui vs non gui plugin exclusions rules
- Move HasPlugin to an autoload function that can be used in vimrc-local
- Don't load the local bundle if it doesn't exist
- Handle VS vs UE for building projects
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 12 Nov 2021 10:51:57 -0800 |
parents | 76defcf6bf02 |
children | ea3aeb55fca2 |
files | vim/autoload/ludo.vim vim/bundle.pathogenrc vim/local.pathogenrc vim/vimrc |
diffstat | 4 files changed, 72 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/vim/autoload/ludo.vim Fri Nov 12 10:50:18 2021 -0800 +++ b/vim/autoload/ludo.vim Fri Nov 12 10:51:57 2021 -0800 @@ -45,6 +45,14 @@ echohl None endfunction +" Returns whether a plugin file exists in the runtime path. +function! ludo#has_plugin(plugname, ...) abort + let l:dirname = 'plugin/' + if a:0 && a:1 + let l:dirname = 'autoload/' + endif + return globpath(&runtimepath, l:dirname.a:plugname.'.vim') !=# '' +endfunction " Loads `pathogenrc` files in each bundle directory and, if found, " builds an exclude list based on the glob patterns found in them. @@ -65,26 +73,40 @@ if line[0] == '#' continue endif - + + if strcharpart(line, 0, 4) == "gui:" + if !has('gui') + call ludo#trace("Ignoring gui-only line: ".line) + continue + else + let line = line[4:] + endif + endif + if strcharpart(line, 0, 6) == "nogui:" + if has('gui') + call ludo#trace("Ignoring terminal-only line: ".line) + continue + else + let line = line[6:] + endif + endif + + let l:add_to = l:included + let l:remove_from = l:excluded if line[0] == '-' - let l:excls = glob(bundle_dir.'/'.line[1:], 1, 1) - for excl in l:excls - let l:idx = index(l:included, excl) - if l:idx >= 0 - call remove(l:included, l:idx) - endif - call add(l:excluded, excl) - endfor - else - let l:incls = glob(bundle_dir.'/'.line, 1, 1) - for incl in l:incls - let l:idx = index(l:excluded, incl) - if l:idx >= 0 - call remove(l:excluded, l:idx) - endif - call add(l:included, incl) - endfor + let l:add_to = l:excluded + let l:remove_from = l:included + let line = line[1:] endif + + let l:incls = glob(bundle_dir.'/'.line, 1, 1) + for incl in l:incls + let l:idx = index(l:remove_from, incl) + if l:idx >= 0 + call remove(l:remove_from, l:idx) + endif + call add(l:add_to, incl) + endfor endfor for excl in l:excluded @@ -170,3 +192,13 @@ endfor execute ':'.string(l:tagidx).'tag '.l:tag endfunction + +function! ludo#build_vs_or_ue() abort + if !empty(get(g:, 'unreal_branch_dir', '')) + UnrealBuild + elseif !empty(get(g: 'vimcrosoft_current_sln', '')) + VimcrosoftBuildActiveProject + else + call ludo#warn("No VS or UE project active") + endif +endfunction
--- a/vim/bundle.pathogenrc Fri Nov 12 10:50:18 2021 -0800 +++ b/vim/bundle.pathogenrc Fri Nov 12 10:51:57 2021 -0800 @@ -0,0 +1,2 @@ +nogui:-pythonmode +nogui:-python-pep8-indent
--- a/vim/local.pathogenrc Fri Nov 12 10:50:18 2021 -0800 +++ b/vim/local.pathogenrc Fri Nov 12 10:51:57 2021 -0800 @@ -0,0 +1,1 @@ +nogui:-*
--- a/vim/vimrc Fri Nov 12 10:50:18 2021 -0800 +++ b/vim/vimrc Fri Nov 12 10:51:57 2021 -0800 @@ -31,7 +31,11 @@ " Disable some plugins. let g:pathogen_disabled = get(g:, 'pathogen_disabled', []) -call ludo#setup_pathogen([ludo#localpath('bundle'), ludo#localpath('local')]) +let s:bundles = [ludo#localpath('bundle')] +if isdirectory(ludo#localpath('local')) + call add(s:bundles, ludo#localpath('local')) +endif +call ludo#setup_pathogen(s:bundles) " Load pathogen. runtime bundle/pathogen/autoload/pathogen.vim @@ -54,14 +58,6 @@ endif endif -function! s:HasPlugin(plugname, ...) abort - let l:dirname = 'plugin/' - if a:0 && a:1 - let l:dirname = 'autoload/' - endif - return globpath(&runtimepath, l:dirname.a:plugname.'.vim') !=# '' -endfunction - " }}} " General Settings {{{ @@ -287,11 +283,11 @@ " Use PyMatch to go faster. if (has('python3') || has('python')) - if s:HasPlugin('ctrlp-py-matcher') + if ludo#has_plugin('ctrlp-py-matcher') let g:ctrlp_match_func = {'match': 'pymatcher#PyMatch'} let g:ctrlp_max_files = 0 let g:ctrlp_lazy_update = 350 - elseif s:HasPlugin('cpsm', 1) + elseif ludo#has_plugin('cpsm', 1) let g:ctrlp_match_func = {'match': 'cpsm#CtrlPMatch'} let g:ctrlp_max_files = 0 let g:ctrlp_lazy_update = 350 @@ -456,7 +452,7 @@ \ }, \} -if s:HasPlugin('fugitive') +if ludo#has_plugin('fugitive') function! _LightlineFugitive() return fugitive#head() endfunction @@ -465,7 +461,7 @@ endfunction endif -if s:HasPlugin('lawrencium') +if ludo#has_plugin('lawrencium') function! _LightlineLawrencium() return lawrencium#statusline() endfunction @@ -487,7 +483,7 @@ endif endfunction -if s:HasPlugin('gutentags') +if ludo#has_plugin('gutentags') function! _LightlineGutentags() return gutentags#statusline('', '', '♨') endfunction @@ -496,7 +492,7 @@ endfunction endif -if s:HasPlugin('syntastic') +if ludo#has_plugin('syntastic') function! _LightlineLinter() return SyntasticStatuslineFlag() endfunction @@ -515,7 +511,7 @@ endfunction endif -if s:HasPlugin('youcompleteme') +if ludo#has_plugin('youcompleteme') function! _LightlineYcmErrors() let l:cnt = youcompleteme#GetErrorCount() return l:cnt > 0 ? string(l:cnt) : '' @@ -734,7 +730,7 @@ nnoremap N Nzvzz " YCM mappings. -if s:HasPlugin('youcompleteme') +if ludo#has_plugin('youcompleteme') augroup VimRC_YouCompleteMe autocmd! autocmd FileType cpp nnoremap <Leader>jj :YcmCompleter GoToImprecise<cr>zv @@ -748,7 +744,7 @@ endif " OmniSharp mappings -if s:HasPlugin('OmniSharp') +if ludo#has_plugin('OmniSharp') augroup VimRC_OmniSharp autocmd! autocmd FileType cs setlocal omnifunc=OmniSharp#Complete @@ -788,7 +784,7 @@ nnoremap <leader>cd :ProjectRootCD<cr> " Ctrl-P mappings. -if s:HasPlugin('ctrlp') +if ludo#has_plugin('ctrlp') nnoremap <silent> <C-p> :CtrlP<cr> nnoremap <silent> <C-o> :CtrlPBuffer<cr> nnoremap <silent> <C-u> :CtrlPTag<cr> @@ -798,7 +794,7 @@ endif " FZF mappings. -if s:HasPlugin('fzf') +if ludo#has_plugin('fzf') if exists('*fzf#run') nnoremap <silent> <C-p> :Files<cr> nnoremap <silent> <C-o> :Buffers<cr> @@ -816,7 +812,7 @@ endif " LeaderF mappings. -if s:HasPlugin('leaderf') +if ludo#has_plugin('leaderf') let g:Lf_ShortcutF = '<C-p>' let g:Lf_ShortcutB = '<C-o>' nnoremap <silent> <C-p> :LeaderfFile<cr> @@ -832,11 +828,8 @@ let g:Lf_StlSeparator = { 'left': '', 'right': '' } endif -" Vimcrosoft mappings. -if s:HasPlugin('vimcrosoft') - nnoremap <F7> :VimcrosoftBuildActiveProject<cr> - nnoremap <F8> :VimcrosoftBuildSln<cr> -endif +" Vimcrosoft/UE mappings. +nnoremap <F7> :call ludo#build_vs_or_ue()<cr> " }}}