In Vim, it is possible to attach syntax highlighter to a file extension.

Is it possible to do the same with keyboard shortcuts?

I.e. the shortcuts would switch on only if a file with particular extension is being edited.

有帮助吗?

解决方案

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.)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top