Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell MacVim to always use a certain syntax highlighting with a certain file type?

I'm looking for something to add to my .vimrc that would tell MacVim to always use Markdown syntax highlighting with TXT files.

Currently, I can do this manually with set filetype=markdown but I have to do that every time I open a file.

like image 719
ele Avatar asked Jun 18 '12 16:06

ele


People also ask

How do I permanently set syntax in Vim?

Add the text, “syntax on” anywhere in the file to enable syntax highlighting permanently for vim editor. Save and close the file by typing ':x'. For disabling the feature, just re-open . vimrc file, change the text “syntax on” to “syntax off” and save the file.

How do I enable syntax highlighting in vim Mac?

If you want to toggle this on/off (without creating a . vimrc file) simply type :syntax on while in vi/vim.

How does syntax highlighting work in Vim?

VIM is an alternative and advanced version of VI editor that enables Syntax highlighting feature in VI. Syntax highlighting means it can show some parts of text in another fonts and colors. VIM doesn't show whole file but have some limitations in highlighting particular keywords or text matching a pattern in a file.

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.


1 Answers

You can automatically set the filetype for particular file extensions using autocmd:

autocmd BufRead,BufNewFile  *.txt,*.TXT set filetype=markdown

Add this line to your .vimrc.

Type :help autocmd within vim for more details; see also: :help autocmd-group. See also: :help filetype.

like image 193
pb2q Avatar answered Sep 29 '22 01:09

pb2q