开发者

Enable syntax highlighting for various filetypes in vim

I can enable syntax highlighting for a file that has an extension that is unknown to vim by doing the following

set syntax=c

Every time I switch tabs however, I have to renter the command. Is there any way to let vim know that a file with an extension .xyz should be coloured with C syntax?开发者_如何学JAVA


Put this at the end of your .vimrc (I'm assuming you have autocommands enabled).

autocmd BufRead,BufNewFile *.xmlx set filetype=xml


In your home directory, create the .vim/ftdetect/xyz.vim:

au BufRead,BufNewFile *.xyz set filetype=c    " to overrule an existing filetype
au BufRead,BufNewFile *.xyz setfiletype c     " to set it only if no filetype has been detected for this extension


With autocommand. E.g.

au BufNewFile,BufRead *.xyz setf c


You can set it in the vim config file:

http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜