Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a specific file extension to behave as if .html in .vimrc file?

Tags:

vim

macvim

I am using MacVim and have colours set on .html documents. I working on various projects that are using the Sparkview Engine for .Net MVC. These files end in .spark. How do I in my .vimrc file set the .spark extensions to map to .html so all my colourations appear on .spark files too?

like image 569
DigiKev Avatar asked Feb 03 '11 10:02

DigiKev


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.

What type of file is Vimrc?

Settings file used by Vim, a text editing program often used by source code developers and system administrators; saves the default settings for the editor when it is opened; allows users to customize options for the editor. VIMRC files are saved in a plain text format.


2 Answers

You can use the following in your .vimrc

autocmd BufRead,BufNewFile *.spark set filetype=html

It means that every time you open or create a new spark file, the file type is set to html for the current buffer. And the appropriate syntax highlighting should be applied.

like image 86
Xavier T. Avatar answered Oct 03 '22 18:10

Xavier T.


Use an autocommand:

    au BufNewFile,BufRead *.spark setfiletype html
like image 23
Andrea Spadaccini Avatar answered Oct 03 '22 19:10

Andrea Spadaccini