WebDevChallenges Logo
WebDevChallenges

A brief introduction to Vim (Part 8)

Updated June 5, 21
Color schemes, plugin managers and certain plugins in Vim.

About

Here is the seventh (previous) part of this series: A brief introduction to Vim (Part 7)
Here is the ninth (next) part of this series: A brief introduction to Vim (Part 9)

Color schemes

Vim offers you the possibility to use color schemes. There are some default color schemes, Vim ships with. You can get a list of the available ones by typing :colorscheme, then a SPACE character and then press CTRL+d.

Now if you for e.g. want to use the color scheme called evening, simply type :colorscheme evening followed by ENTER.

You can also specify your desired color scheme in your config file at ~/.vimrc by adding the command into the file: colorscheme evening

Custom color schemes

You can download find custom Vim color schemes at https://vimcolors.com/. When you find a scheme you like, follow the github link and download the .vim file.

This file has to be saved in the directory ~/.vim/colors. If that directory does not yet exist, simply create it with mkdir -p ~/.vim/colors. Then move the .vim file in that directory (e.g. mv ~/Downloads/night-owl.vim ~/.vim/colors/).

If you now check the available color schemes the newly installed should be available and can be used instantly (Vim does not have to be restarted).

Plugins

It is possible to expand Vim’s functionality by adding plugins. I will scratch the surface here but there are good resources like vimawesome for diving deeper into that topic.

Plugin managers

There are several plugin managers which simplify the process of installing and managing plugins. The most notable ones are probably:

vim-pathogen

I want to dive a little deeper into the vim-pathogen plugin manager.

You can install it with the following command:

mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

Then add the following line into your ~/.vimrc file: execute pathogen#infect()

Now all plugins which exist in the folder ~/.vimrc/bundle/ will be loaded into Vim.

Fuzzy finder (ctrlp.vim)

A fuzzy finder is a piece of software, which enables you to quickly find a file. One of the most famous fuzzy finder plugins for Vim is called ctrlp.vim.

Installing ctrlp.vim

ctrlp.vim can be installed as described in their documentation.

First of all, we change the directory to ~/.vim/ by entering cd ~/.vim.

Now we clone the git repository to ~/.vim/bundle/ with the following command: git clone https://github.com/kien/ctrlp.vim.git bundle/ctrlp.vim

Because we installed pathogen in the previous step, we don’t have to set the runtimepath as described in the intallation steps.

Then execute the following command inside Vim: :Helptags

Using ctrlp.vim

Finally start Vim in a directory of your choice and press CTRL+p (hence the name of the plugin ;)).

ctrlp.vim will index the files of the directory. So if your directory has a lot of files in it, this process might take a moment.

After the indexing process is done, you will be prompted to type in something and ctrlp.vim will suggest files matching that input. You can select a file in the list with the arrow keys and finally pressing enter).

Tree explorer (NERDTree)

A tree explorer enables you to view the folder structure of the directory as a tree as shown in the github README of the NERDTree plugin:

image

Installing NERDTree

To install NERDTree, simply execute the following command: git clone https://github.com/scrooloose/nerdtree.git ~/.vim/bundle/nerdtree

Then start Vim and execute the following command: :Helptags

Using NERDTree

After installing NERDTree you can execute the command :NERDTreeToggle in Vim.

This command both opens and closes the tree view to on the left side of Vim which you can navigate using either the arrow keys or the usual Vim navigations like j and k but also G for e.g..

To open a file or directory, press ENTER.

Now because always typing :NERDTreeToggle to open up the tree view, you can create a key map as described in my last post called A brief introduction to Vim (Part 7).

For e.g. map <C-n> :NERDTreeToggle<CR> will toggle the tree view when pressing CTRL+n.

Ask me questions

I will be happy to answer your questions in the comments section below. Also let me know if you have any tips or ideas for me to improve my post!