Search code examples
vimhookautocmd

vim - set filetype in autocmd FileType


I'd like to change filetype in autocmd FileType hook. Thre reason is that I'd like to use NeoMutt syntax file for .muttrc instead of Vim's default syntax file. I've installed NeoMutt's syntax files with Plug manager:

Plug 'neomutt/neomutt.vim'

And I've it in runtime path (I can set it with set ft=neomuttrc). But when I open ~/.muttrc, Vim still uses default syntax file (set ft? prints muttrc). I've tried the following:

autocmd FileType muttrc setl filetype=neomuttrc<CR>

but the filetype is still set to muttrc after I open ~/.muttrc. How can I change the filetype in autocmd FileType hook?


Solution

  • <CR> should be removed:

    autocmd FileType muttrc setl filetype=neomuttrc