You need to do 2 things:
- Create a mapping local to a specific buffer by using the
option for noremap
.
- Load the mappings for just a specific filetype.
This can be done via an autocmd
and FileType
event in your .vimrc
like so:
autocmd FileType perl noremap :!perl %:p
The other way option is by creating a filetype plugin. (see :h ftplugin
for more details)
A simple example is do create a file named, ~/.vim/ftplugin/perl.vim
and place your mappings inside like so:
nnoremap :!perl %:p
I personally lean more towards the ftplugin approach but having a everything in your .vimrc
file can be nice.
For more help see:
:h :au
:h FileType
:h map-local
:h ftplugin