I’ve recently return to ViM, after several years in Emacs, and something I’m missing is the ability to set filetype-local keybindings: e.g. I want to make _ underline the current word in Markdown-type files, but do something completely different in, say, Python. Is there a way to do this other than just autocmds that override each other?
I’ve recently return to ViM, after several years in Emacs, and something I’m missing
Share
You can use
map <buffer> ...to make a mapping local to a buffer rather than global. Then set up an autocommand to load that mapping only for certain filetypes, or put the mapping into a ftplugin file for that filetype. Luckily, local mappings aren’t cleared when a buffer is hidden, only when a buffer is destroyed, so the mappings will stick around as you switch between buffers.See
:h :map-local.