Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I map keys for specific file types in Vim?

Tags:

vim

I want my Enter key to follow links in help files because my keyboard doesn't have a ] key. Therefore I've put:

nnoremap <Enter> <C-]>

In ftplugin/help.vim. This works, but this key map is now "global" and messes up the use of the key in other places, for example the q: command window.

So how do I restrict a key-bind to a single buffer, or perhaps even a single file type?

like image 913
Hubro Avatar asked Dec 20 '22 21:12

Hubro


1 Answers

map the command using autocmd:

autocmd FileType c,cpp,php nnoremap <buffer> <Enter> <C-]>

maps only for filetypes: c,cpp and php

like image 153
R. Oosterholt Avatar answered Jan 18 '23 20:01

R. Oosterholt