How to enable syntax highlighting in Vim / Vi Editor

How to enable syntax highlighting in Vim or Vi editor

Enable syntax highlighting in Vim / Vi Editor

Vim is one of the popular text editors for software developers and system administrators. macOS and various Linux Distros Vim are pre-installed. You can easily edit the code with Vim. However, Vim does not highlight syntax by default. In this tutorial, you will learn how to enable syntax highlighting in Vim / Vi Editor.

Enable syntax highlighting in Vim

First, open helloworld.c Create the file using the following command: (I shot it here helloworld.c You can open any program file as a demo file. )

vim helloworld.c

Press now EscKey to switch to normal mode if you are in another mode.

Enter the following command and hit Enter Key:

:syntax on

The output looks like this:

How to turn on syntax highlighting in Vim editor-highlighted syntax How to turn on syntax highlighting in the Vim editor-syntax highlighting

Turn on syntax highlighting permanently in Vim

Edit allows you to set syntax highlighting permanently ~/.vimrc File. To do this, run the following command:

Open .vimrc File using the following command:

vim ~/.vimrc

Next, add the following text to the file opened above and save the file.

syntax on

Now you have permanently enabled syntax highlighting in Vim.

Turn off syntax highlighting in Vim

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

:syntax off

Conclusion

In this tutorial, you learned how to enable syntax highlighting in Vim / Vi Editor. If you have any questions about this, please comment below.

Sidebar