33

For example, I'd like to map a key when in a tex-like file, which includes many different flavor of tex files. Do I have to use multiple commands like this?

au FileType tex nm <C-H> <Plug>IMAP_JumpForward
au FileType latex nm <C-H> <Plug>IMAP_JumpForward
au FileType context nm <C-H> <Plug>IMAP_JumpForward
au FileType plaintex nm <C-H> <Plug>IMAP_JumpForward
...

1 Answer 1

52

Absolutely:

au FileType tex,latex,context,plaintex nm <C-H> <Plug>IMAP_JumpForward

Some thoughts:

  • Should be using a buffer local mapping instead of a global mapping
  • Using short names has only cons and zero pros. Don't.
  • This autocmd should be in a group
  • Autocmd's should be cleared (inside a group) so that re-sourcing is not a problem
  • Maybe use a after ftplugin script. e.g. ~/.vim/after/ftplugin/tex.vim instead of an :autocmd as they are easier to manage
  • look into romainl's idiomatic vimrc for more vimrc do's/don't's

Cleaned up version:

augroup tex_mappings
    autocmd!
    autocmd FileType tex,latex,context,plaintex nmap <buffer> <c-h> <Plug>IMAP_JumpForward
augroup END

Alternatively add the following to ~/.vim/after/ftplugin/txt.vim:

nmap <buffer> <c-h> <Plug>IMAP_JumpForward

Note: with the ftplugin approach you will need to add this line for each FileType (or use :source)

For more help see:

:h :au
:h :aug
:h :map-local
:h after-directory
Sign up to request clarification or add additional context in comments.

1 Comment

Catchy punchlines for the win!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.