The association is not directly to file extensions, but filetypes (which can be detected based on file extensions, but also other file patterns or even its contents). :setl filetype?
shows you the current buffer's.
To define a filetype-specific mapping, just append the <buffer>
attribute after the :map
command. (Same for custom commands, use -buffer
after :command
.)
You can define that for certain filetypes by prepending :autocmd Filetype {filetype} ...
, and put that into your ~/.vimrc
. But that gets unwieldy as you add mappings and other settings for various filetypes. Better put the commands into ~/.vim/ftplugin/{filetype}_mappings.vim
. (This requires that you have :filetype plugin on
.)