I've been using Vim as my text editor, but now that I'm using it to write Python code, I'd like it to hightlight the syntax like this:
How do I turn on syntax highlighting in Vim? How do I get it to stay on by default for programming files?
vim filename.py
.:syntax on
and hit enter.Note: This will only turn on syntax highlighting temporarily. In other words, if you quit working on that file and open it again, or open a different file with vim, syntax highlighting will be off by default. If you'd like to make syntax highlighting permanent, you need to do some extra steps.
cd
into the terminal. vim .vimrc
, which will edit the .vimrc file if you have it, or create it if you don't.
syntax on
to the file as a new line, then hit esc, type :wq
, and hit enter.
Syntax highlighting will now be enabled by default for files ending in common programming language extensions such as .py
.
If you would like to turn off the syntax highlighting for a particular file, you can do that on a case by case basis.
vim filename.py
.:syntax off
and hit enter.