Can I include multiple file types when using the "FileType" event?

For example, I would like to map the key when in a tex -like file, which includes many different shades of tex files. Should I use several commands like this?

 au FileType tex nm <CH> <Plug>IMAP_JumpForward au FileType latex nm <CH> <Plug>IMAP_JumpForward au FileType context nm <CH> <Plug>IMAP_JumpForward au FileType plaintex nm <CH> <Plug>IMAP_JumpForward ... 
+5
source share
1 answer

Absolutely:

 au FileType tex,latex,context,plaintex nm <CH> <Plug>IMAP_JumpForward 

Some thoughts:

  • Use local buffer mapping instead of global mapping
  • Using short names has only cons and zero pros. Not necessary.
  • This autocmd must be in a group
  • Autocmd needs to be cleaned (within the group), so re-searching is not a problem
  • Maybe use after ftplugin script. e.g. ~/.vim/after/ftplugin/tex.vim instead of :autocmd , since they are easier to manage
  • check out romainl idiomatic vimrc for more vimrc do's / do not

Purified Version:

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

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

 nmap <buffer> <ch> <Plug>IMAP_JumpForward 

Note: using 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 
+15
source

Source: https://habr.com/ru/post/1212572/


All Articles