change vim color scheme

How to Change Color Scheme in Vim

Vim is a popular text editor in Linux. It allows ton of useful features and customizations. Sometimes you may need to change font color, change color of comments, change color scheme in vim. Vim also allows practical syntax highlighting and customization of user interface. The default software package comes with built-in color schemes. You can also install user-made color schemes. In this article, we will learn how to change color scheme in vim.


How to Change Color Scheme in Vim

Here are the steps to change vim color settings.


1. List Available Color Schemes

Vim comes pre-installed with many color schemes to choose from. It used a default color scheme peachpuff on installation, that varies depending on whether you use a light or dark terminal.

To see the list of available color schemes, open vim editor and enter the following.

:colorscheme [space] [Ctrl+d]

The output will list all the available color schemes.

In fact, it is better if you open an existing document in vim editor for this purpose, since you will be able to readily see the changes when you change color scheme. Each color scheme contains multiple colors, for font, background, highlighting, etc.


2. Change Vim Color Schemes

Once you have entered the command to list all available color schemes, you can change the color scheme as shown below.

:colorscheme [colorscheme_name]

For example, to switch to blue color scheme, enter

:colorscheme blue

You can also use the following command instead to change color scheme.

:colo [colorscheme_name]


3. Download Color Schemes

If you are not satisfied with the available color scheme options, you can download more user-made color schemes from websites like vimcolors.

Once you have downloaded a new theme, move it to /vim/colors folder. If you don’t have this folder, create one with the following command.

$ mkdir ~/.vim/colors

Next, move the downloaded color scheme to /.vim/colors folder. We have assumed that you have downloaded the new scheme to ~/Downloads below. You can change the download location as per your requirement.

$ mv ~/Downloads/[vim_colorscheme]  ~/.vim/colors


4. Set Vim Color Settings

If you don’t want to change the entire color scheme but only a few colors, you can do so manually. Here is the syntax to change color of individual elements in vim editor.

:highlight [Group] [key=value]
or
:hi [Group] [key=value]

In the above command, [Group] is the group of elements whose colors you want to change. key=value is the key-value pair with color information. Here are some of the commonly used groups.

Normal (normal text)
NonText (characters that don’t exist in the text)
Cursor (the character under the cursor)
ErrorMsg (error messages)

For a full list of all available groups, you can refer to Vim official documentation.

The key values depend on whether you use CLI or GUI. Here are some commonly used keys for CLI.

ctermfg (for setting the foreground)
ctermbg (for setting the background)
cterm (for additional properties)

Here are some commonly used keys for GUI.

guifg (for setting the foreground)
guibg (for setting the background)
gui (for additional properties)

Let us look at an example. Let us say you have the following color scheme in your vim editor.

Let us issue the following command to set font color to red and background to black.

:hi Normal ctermfg=Red ctermbg=Black

This is what your vim editor will look like.


5. How to Set Default Color Scheme in Vim

Please note, the above changes are not permanent. They will revert to default settings when you close and re-open vim editor.

To make the changes permanent, you need to edit vim configuration file with new color settings.

Open vim’s configuration file located at /etc or users home directory under the name .vimrc (or .exrc).

Set default color scheme by editing the line for colorscheme and entering new value.

colorscheme [colorscheme_name]

To enable syntax highlighting, add the following line.

syntax on

You can also add the above-mentioned highlight commands in this file to make permanent manual changes.

Save and close the file to apply changes. Close and re-open vim editor to work with new settings, if they are not applied already.

In this article, we have learnt how to change vim color scheme. We have also learnt how to change specific colors such as font color, background color. We also saw how to make these changes permanent. You can customize them as per your requirement.

Also read:

Python Script to Check URL Status
How to Create Executable in Python
How to Store JSON Data in MySQL
How to Fix Dpkg was Interrupted Error in Linux
How to POST JSON Data in cURL

Leave a Reply

Your email address will not be published. Required fields are marked *