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.
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.
If you want to toggle this on/off (without creating a . vimrc file) simply type :syntax on while in vi/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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With