Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistent :set syntax for a given filetype?

People also ask

How do I change the filetype in vim?

As other answers have mentioned, you can use the vim set command to set syntax. :set syntax=<type> where <type> is something like perl , html , php , etc. There is another mechanism that can be used to control syntax highlighting called filetype , or ft for short.

How do I enable syntax highlighting in vim?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.

Where does vim put syntax files?

Install the syntax file. Save the file, then install it by copying the file to ~/. vim/syntax/cel. vim on Unix-based systems, or to $HOME/vimfiles/syntax/cel.


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.


Add one of the following passages to your .vimrc:

" Set the filetype based on the file's extension, overriding any
" 'filetype' that has already been set
au BufRead,BufNewFile *.html.twig set filetype=html

or

" Set the filetype based on the file's extension, but only if
" 'filetype' has not already been set
au BufRead,BufNewFile *.html.twig setfiletype html

au BufNewFile,BufRead,BufReadPost *.twig set syntax=HTML

And add this line to ~/.vimrc to make the settings persistent.


I know this doesn't directly answer the question, however this answers the intent of the question, which is to get syntax highlighting working with Twig / Symfony 2

I suggest you check out https://github.com/beyondwords/vim-twig (not mine), which provides:

  • the syntax highlighting file for *.html.twig,
  • file type detection for same, and
  • file type plugin, allowing you to modify various settings as required when editing *.html.twig files

I hope this helps