Persistent :set syntax for a given filetype?

Bendihossan picture Bendihossan · Jul 26, 2012 · Viewed 39.9k times · Source

I'm working on a Symfony2 project which uses Twig, and the filetypes are myfile.html.twig. Vim doesn't automatically detect the syntax highlighting and so applies none. I can use :set syntax=HTML after I've opened the file but this is a pain when jumping between files.

Is there a way to persistently set the syntax highlighting for a specific file type in vim?

Answer

Hauleth picture Hauleth · Jul 26, 2012

You can use autocmd to accomplish that, i.e.:

augroup twig_ft
  au!
  autocmd BufNewFile,BufRead *.html.twig   set syntax=html
augroup END

Should work.