Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to include multiple file types when using the `FileType` event?

Tags:

vim

latex

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
...
like image 478
xzhu Avatar asked Feb 03 '15 22:02

xzhu


1 Answers

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
like image 120
Peter Rincker Avatar answered Oct 16 '22 05:10

Peter Rincker