For a few specific files I need a set of mappings, which I don't want to be active in my ~/.vimrc file. So I defined them in a file XXX.vim. How can I load XXX.vim on a mode line and where should it be placed in my .vim directory?
~/.vimrc
XXX.vim
.vim
You can't source a script in a modeline for obvious reason. All you can do is set some options.
The canonical way to have some options/mappings/commands available for some files and not others is to use an :help autocommand like this one:
:help autocommand
augroup mystuff autocmd! autocmd BufNewFile,BufRead *.foo nnoremap <buffer> <key> bar augroup END
You can use the pattern above for all files with the foo extension or something like foo/bar/* for all file under foo/bar/, etc.
foo
foo/bar/*
foo/bar/
If you want those mappings only for a specific filetype, say ruby, then it is best to use the built-in ftplugin mechanism:
ruby
Make sure you have either of the following lines in your vimrc:
vimrc
filetype plugin on filetype plugin indent on filetype indent plugin on
Create this file (and the necessary directories) if it doesn't exist:
" Unix-like system ~/.vim/after/ftplugin/ruby.vim " Windows %userprofile%\vimfiles\after\ftplugin\ruby.vim
Add your buffer-local mappings to that file:
nnoremap <buffer> <key> something
You can't source a script in a modeline for obvious reason. All you can do is set some options.
The canonical way to have some options/mappings/commands available for some files and not others is to use an
:help autocommand
like this one:You can use the pattern above for all files with the
foo
extension or something likefoo/bar/*
for all file underfoo/bar/
, etc.If you want those mappings only for a specific filetype, say
ruby
, then it is best to use the built-in ftplugin mechanism:Make sure you have either of the following lines in your
vimrc
:Create this file (and the necessary directories) if it doesn't exist:
Add your buffer-local mappings to that file: