Open In App

Enabling Syntax Highlighting in Vim Editor

Last Updated : 08 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will cover how to highlight syntax in Vim editor. First, we look at what Linux and VIM editors followed by syntax highlighting in the Vim editor with examples and screenshots we will also look at different color schemes available and how we can change the default settings of Vim editor to enable syntax highlighting by default.

VIM Editor

VIM Editor is a text editor generally used in Unix/Linux systems and is well known for its efficiency and flexibility. VIM editor was initially developed by Bill Joy in 1976 as vi editor and later an improved version of vi editor was released in 1991 which is known as VI IMproved (VIM) editor.

Syntax Highlighting in Vim editor

When we open the Vim editor the text is displayed plain and there is no syntax highlighting by default the editor looks like the screenshot below:

Screenshot-from-2023-10-09-20-14-12

Enable Syntax Highlighting

To enable syntax highlighting in the Vim editor follow the below

  • Open the vim editor
  • Press Esc if you are in insert mode
  • Type the below command to enable syntax highlighting and press Enter
:syntax on

Screenshot-from-2023-10-09-20-15-29

Disable syntax Highlighting

To disable the syntax highlighting follow the below simple steps:

  • Open the vim editor
  • Press Esc if you are in insert mode
  • Type the below command to disable syntax highlighting and press Enter
:syntax off

Screenshot-from-2023-10-09-20-15-11

Color Schemes in Vim editor

There are different colors schemes available in the Vim editor to personalize the editor and get syntax highlighting based on the preferences, to check the list of available colors in the Vim editor run the following command,

    ls -l /usr/share/vim/vim*/colors/

After executing the above command you get the list of available color schemes which you can also see in the below output screenshot like desert, Murphy, evening, etc.

Screenshot-from-2023-10-09-20-27-44

To apply Colorscheme in the Vim editor follow the below simple steps:

  • Open the vim editor
  • Press Esc if you are in insert mode
  • Type the below command to apply the color scheme and press Enter
    :colorscheme [colorscheme name]

Example:

:colorscheme evening

Screenshot-from-2023-10-09-20-30-36

Configure the Default Settings of Vim editor

We have to configure the Vim editor configuration file (.vimrc) to change the default settings of Vim editor, so whenever the editor opens it loads with the default settings, to configure the default settings follow the below steps,

  • Please open the file in Vim editor to configure it
vi ~/.vimrc
  • Configure the default setting as per your requirements,
  • For example, if you want to turn on the text/syntax highlighting by default when you open the vi editor add the command syntax on

Screenshot-from-2023-10-09-20-38-31

  • When you are done with the configuration Press Esc to exit the insert mode
  • Use:wq command to save the changes and exit the editor
  • After saving the changes whenever you open the vim editor it will open with the default settings you set in the configuration file.

Conclusion

In this article, we had covered how to highlight syntax in Vim editor and how to enable and disable syntax highlighting we will also look what are the available color schemes in vim editor and how to apply the color schemes in the Vim editor, followed by how can we configure the default settings of the vim editor so whenever we open the editor if loads with the default settings.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads