3

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?

1 Answer 1

6

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
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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