A lot of languages use curly braces {}
to enclose code blocks, so it's nice to have a mapping something like:
inoremap <buffer> {<CR> {<CR>}<Esc>O
I have this mapping in my c.vim
ftplugin
, but also in: r.vim
, scala.vim
, and json.vim
.
But this forces me to duplicate it four times. If I come up with an improvement, or I want to rebind the keys, I have to do it in each place.
Sourcing a shared script in each ftplugin
seems like a good solution, but I'm not sure where the right place to put those shared scripts is. Putting them in plugin/
means they are loaded every time, which is not what I want. autoload/
seems to be designed for functions more than mappings, but perhaps there is a way to use it that way?
So, in short:
How can I define these mappings (but more generally, any part of an ftplugin
) once, and then use them in multiple ftplugin
files?