tweag / promptworks.vim

PromptWorks vim configs as a self-bootstrapping vundle setup
2 stars 1 forks source link

Wait until plugins are loaded to check if Tabularize exists #40

Open rzane opened 7 years ago

rzane commented 7 years ago

Plus, this check for exists doesn't work.

di commented 7 years ago

@rzane It's possible the user hasn't installed or uninstalled it and doesn't want the bindings though, right?

rzane commented 7 years ago

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.

di commented 7 years ago

@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()
rzane commented 7 years ago

@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>
di commented 7 years ago

@rzane Ah, yeah that's a really good point. Hmm, I'm not really sure.

rzane commented 7 years ago

Would it make more sense to simply call TabularizeBindings() in the vimrc.bundles?

rzane commented 7 years ago

^ Nevermind, that wouldn't work.