Magnus
Magnus

Reputation: 4714

Control loading of vim plugins

I'm a using the vimfootnotes plugin when writing emails and plain text. However I've found that its keybindings cause a lot of trouble when I'm editing LaTeX documents. I'd like to modify the plugin so that I have some level of control over when it's loaded.

I've tried a few different things, but in the end I wrapped the keybindings that the plugin registers in a function, then I call that function from the filetype scripts (in ftplugin/) for the filetypes where I want to use footnotes.

Is this an idiosyncratic way to solve this in Vim, or is there a better way to do it?

Upvotes: 1

Views: 233

Answers (2)

ZyX
ZyX

Reputation: 53604

After viewing source code of the plugin, I can suggest the following:

inoremap <Plug>Dummy1 <Plug>AddVimFootnote
nnoremap <Plug>Dummy1 <Plug>AddVimFootnote
inoremap <Plug>Dummy2 <Plug>ReturnFromFootnote
nnoremap <Plug>Dummy2 <Plug>ReturnFromFootnote

function s:FootnoteMaps()
    if &filetype!=#'tex'
        inoremap <buffer> \f <Plug>AddVimFootnote
        nnoremap <buffer> \f <Plug>AddVimFootnote
        inoremap <buffer> \r <Plug>ReturnFromFootnote
        nnoremap <buffer> \r <Plug>ReturnFromFootnote
    else
        inoremap <buffer> #f <Plug>AddVimFootnote
        nnoremap <buffer> #f <Plug>AddVimFootnote
        inoremap <buffer> #r <Plug>ReturnFromFootnote
        nnoremap <buffer> #r <Plug>ReturnFromFootnote
    endif
endfunction
autocmd Filetype * call s:FootnoteMaps()

First creates dummy mappings that will be never triggered but will prevent plugin from setting his own mappings to <Plug>AddVimFootnote and <Plug>ReturnFromFootnote. Second (function+autocommand) will setup old mappings for filetypes other then tex. If I was sure that filetype event is triggered before plugin is loaded, then first section won't be required.

Note that it does not pretend to be a generic solution. Generic solution will be «examine source code of the plugin and think a bit».

Upvotes: 2

Tom Miller
Tom Miller

Reputation: 820

Not that I am aware of. You might want to checkout this thread. I could probably put it in a path that is not loaded by default (ex. ~/.vim/manually_loaded) and write a custom function to source it whenever you need it. You could also source it with an autocommand on the filetype, but if you opened both types on accident it would cause issues.

Upvotes: 2

Related Questions