1

We can use the FileType autocommand event to create a customized key mapping for a specific type of file. For example, Spaceb could call different build tools for a Java file compared to a C++ file.

I wonder is there any way to create a customized key mapping for a specific file?

3

You can use the BufRead event in combination with a buffer-local mapping. For example, if I want o in Normal mode to echo Math is rad only when I'm editing a file named foo.bar:

autocmd BufRead foo.bar nnoremap <buffer> o :echo "Math is rad"<CR>

See:

:h autocmd-events
:h BufRead
:h autocmd-patterns
:h map-local
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.