Open rzane opened 7 years ago
@rzane It's possible the user hasn't installed or uninstalled it and doesn't want the bindings though, right?
Fair point, but I don't think we've taken that approach with other packages. For example, we just assume the user has NERDTree, ctrl-p, Ag.vim, and Switch.
If there is a reliable way to detect if packages are installed, then maybe all of these instances should be wrapped in conditionals.
@rzane I see what's happening. I think the issue is that the plugins haven't actually loaded before the .vimrc
has finished, so exists
fails. I think the right way to do this is to put the check and the bindings in a function, and call it on a VimEnter
like this:
function! TabularizeBindings()
if exists(":Tabularize")
" align =
nnoremap <Leader>a= :Tabularize /^[^=]*\zs=/l1<CR>
vnoremap <Leader>a= :Tabularize /^[^=]*\zs=/l1<CR>
" align : but without a space before them
nnoremap <Leader>a: :Tabularize/\(:.*\)\@<!:\zs /l0<CR>
vnoremap <Leader>a: :Tabularize/\(:.*\)\@<!:\zs /l0<CR>
" align {
nnoremap <Leader>a{ :Tabularize /^[^{]*\zs{/l1<CR>
vnoremap <Leader>a{ :Tabularize /^[^{]*\zs{/l1<CR>
" align ,'s, but without a space before them
nnoremap <Leader>a, :Tabularize /,\zs/l0r1<CR>
vnoremap <Leader>a, :Tabularize /,\zs/l0r1<CR>
endif
endfunction
autocmd VimEnter * :call TabularizeBindings()
@di, good tip.
Do you think other plugin-related bindings should follow this pattern?
And, could attaching this to VimEnter cause any problems if people want to override these bindings in their vimrc.local
? For example, if I have the following lines in my .vimrc.local
, they'd be overridden:
nnoremap <leader>a= :Something<CR>
@rzane Ah, yeah that's a really good point. Hmm, I'm not really sure.
Would it make more sense to simply call TabularizeBindings()
in the vimrc.bundles
?
^ Nevermind, that wouldn't work.
Plus, this check for
exists
doesn't work.