Mark Howard
Mark Howard

Reputation: 85

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?

Upvotes: 1

Views: 2240

Answers (2)

Peter Rincker
Peter Rincker

Reputation: 45087

I tested it and this worked for me:

autocmd FileType muttrc set filetype=neomuttrc

I would recommend wrapping this up in a augroup and clearing the group.

augroup neomuttrc
    autocmd!
    autocmd FileType muttrc set filetype=neomuttrc
augroup END

Upvotes: 1

leaf
leaf

Reputation: 1764

<CR> should be removed:

autocmd FileType muttrc setl filetype=neomuttrc

Upvotes: 2

Related Questions