Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Change syntax highlight on-demand

I have some HTML files with arbitrary extension.

I would like to know if it's possible to order vim to change the highlight with a command.

Thanks.

like image 944
Pedro Montoto García Avatar asked May 26 '26 02:05

Pedro Montoto García


2 Answers

You can force syntax highlighting for a language by setting syntax:

:set syntax=html

If you'd also like to load filetype-specific settings, you should set filetype instead. This is probably what you want:

:set filetype=html

Since you mention you're editing more than one such file, you can automatically set the filetype for a given extension using autocmd:

:autocmd BufRead,BufNewFile *.<extension> setlocal filetype=html

You can also have this persist into future sessions by placing it in your vimrc.

like image 200
Jamie Schembri Avatar answered May 27 '26 17:05

Jamie Schembri


Do you want just to tell vim that the file you are editing is written in html? Use a command :set filetype=html or just :set ft=html.

like image 42
And R Avatar answered May 27 '26 16:05

And R