How to Turn On Syntax Highlighting in Vim/Vi Editor

Turn On Syntax Highlighting in Vim/Vi Editor

Vim is one of the popular text editors among the software developers & system administrators. The macOS as well as on different Linux Distros Vim comes preinstalled. We can edit code in Vim easily. But the syntax is not highlighted by default in Vim. In this tutorial, you are going to learn How to Turn On Syntax Highlighting in Vim/Vi Editor.

Turn On Syntax Highlighting in Vim

First, open helloworld.c file by using the following command. (We have taken here helloworld.c as a demo file you can open any program file.)

vim helloworld.c

Now press Esckey to come in normal mode if you are in any other mode.

The enter following command and hit Enter key:

:syntax on

The output should be:

How to Turn On Syntax Highlighting in Vim Editor - syntax highlighted
How to Turn On Syntax Highlighting in Vim Editor – syntax highlighted

Turn On Syntax Highlighting in Vim Permanently

We can set syntax highlighting permanent by editing ~/.vimrc file. To do this run the following commands:

open .vimrc file using the following command:

vim ~/.vimrc

Now append the following text in the above-opened file and then save the file:

syntax on

Here you have successfully enabled syntax highlighting permanently in Vim.

Turn Off Syntax Highlighting in Vim

You can turn off syntax highlighting by using the following command inside Vim:

:syntax off

Conclusion

In this tutorial, you have learned How to Turn On Syntax Highlighting in Vim/Vi Editor. If You have any queries regarding this please comment below.

Leave a Comment