Open In App

How to Highlight Text in Vim Editor in Linux

Last Updated : 24 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will cover how to highlight text or 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.

Linux

Linux is a kernel for operating system(OS) it is a core part of OS which was developed by Linus Torvalds in 1991. It is an open-source kernel that allows everyone to access the source code freely which makes it more popular and widely used in the industry as well as in personal systems. There are operating systems based on the Linux kernel, some of the popular Linux distributions are Ubuntu, Debian, Fedora, Kali Linux, etc.

VIM Editor

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

  • insert mode
  • command mode

Syntax/Text 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

To enable syntax highlighting in the Vim editor follow the below steps:

  • 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

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

ColorSchemes 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

To change the default settings of Vim editor, we have to configure the Vim editor configuration file (.vimrc), 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 text/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