vim

Best Ways to Add Color to Your Vim Editing Experience

Vim is, without question, one of the finest text editors. It’s a CLI text editor that comes with numerous features. It’s free and open-source software available for all the popular platforms. Vim is notorious for its learning curve. However, once mastered, Vim can do wonders.

Vim is a CLI text editor. Most of the time, it’s the basic black and white window. How about spicing your Vim experience? Let’s check out the best ways to add color to Vim.

Vim color scheme

Color schemes are one of the simplest ways to make a text editing experience dramatically better, especially if you’re working with codes. It improves visual clarity, allowing you to focus on the important part. For some, the appropriate color scheme can reduce eye strain. It also provides good aesthetics to the editor.

That’s why almost all the text editors support some form of theme. In the case of Vim, there are tons of color schemes out there. It comes with a number of color schemes by default. If you’re not satisfied, you can add more through the Vim plugin system.

Vim color schemes

Vim comes with a handful of awesome themes by default. To change the color scheme, use the following command. For example, I’ll be using the XML code found here.

$ :colorscheme <color_scheme>

If you don’t know the exact name of the color scheme, pressing Tab will reveal all the available ones.

Let’s try out the “desert” color scheme.

$ :colorscheme desert

To check what color scheme Vim is currently using, run this command.

$ :colorscheme

Like many other Vim commands, the color command also has an acronym.

$ :color

$ :colo

Now, this change won’t be permanent. Once you exit Vim, it’ll revert back to the default color scheme. You can define the default color scheme at the vimrc file. It’s the Vim configuration file that Vim loads every time it starts.

Open up the vimrc file. If you don’t have one, the following command will create one by default. My vimrc is a sample one from Vim fandom.

$ vim ~/.vimrc

At the end of the file, add the following line.

$ colo <color_scheme_name>

To take the change into effect, restart Vim. If that’s not an option, then reload the vimrc file.

$ :source ~/.vimrc

Vim additional color schemes

Vim comes with a handful of color schemes by default. There are tons of color schemes out there to be explored. In this section, let’s check out how you can add your favourite color scheme to the editor.

All the Vim color schemes (and plugins) come in the form of a .vim (vimscript) file. The same goes for Vim color schemes. The default Vim color schemes are located at the following directory.

$ ls /usr/share/vim/vim80/colors | grep vim

As for the Vim themes we’re going to add, they’ll be located under the ~/.vim directory. It’s user-specific; one user can’t use other users’ Vim color schemes. Whenever Vim starts, it looks for the directory and its content. If it doesn’t exist, nothing is performed. If it exists and there’s file according to the structure, then Vim will follow those directives.

Generally, this directory doesn’t exist. Run the command to create the directory.

$ mkdir -v ~/.vim

To store the color schemes, we’ll be needing the colors sub-directory.

$ mkdir -v ~/.vim/colors

It’s time to grab your favourite Vim color scheme. There’s a dedicated website that hosts a ton of Vim color schemes with preview. Check out Vim Colors.

In this example, let’s install the miramare dark theme. Download the color scheme from GitHub.

$ git clone https://github.com/franbach/miramare.git

Now, move the miramare.vim file to the “~/.vim/colors” directory.

$ mv -v /<path_to_miramare_git_directory>
/colors/miramare.vim ~/.vim/colors

Voila! The color scheme is ready to use! It should now appear on the list of available color schemes.

$ :colo miramare

To make the newly-added color scheme the default, modify the vimrc file accordingly.

Final thoughts

This is just the manual way of adding Vim color schemes. It’s also possible to use a Vim plugin manager to add the Vim color scheme for you. It’s a far better approach as it’ll also keep the color scheme (and other plugins) updated. Check out how to enjoy Vim plugins. Vim macro is also a great way to improvise your editing experience. Check out Vim macro tutorial.

Enjoy!

About the author

Sidratul Muntaha

Sidratul Muntaha

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.