Site Overlay

Vimrc Tutorial – 1

I’ve been a vim user for a couple of years now and still I have never created my own vimrc file. I always used other user’s files, and yet, I can’t find one that makes me comfortable working with.

In this post (or series of posts), I will start creating my own vimrc file, so lets get to it.

Let’s start by deciding what plugins we want to have in our vim. If we go to vimawesome, we can get a list of of all vim plugins that we can install. As you can see, The NERD Tree is the number one plugin for vim and is the one that I will install first since its a very important plugin for every developer (Can you program without a tree file explorer?)

Ok, how to install The NERD Tree? You need to use one of those plugin managers for vim, and the one I’ll use is Vundle, a short for Vim Bundle. Go to it’s GitHub page, start your terminal, and paste the following line.

$ git clone ~/.vim/bundle/Vundle.vim

Now you have vundle installed, but we still need to configure vim to work with it.

In order to do that, we need to create a few folders and files in order to keep things organized and clean. In your Home folder, mkdir a new folder and name it whatever you want as long as you remember its name (I’m gonna call it JJvim). I’m going to mkdir another folder inside it and call it vimrcs┬áto add all my tiny bits of vim code files to it. The first vim file I will add is the Vundle configuration code, so copy the following code and paste it into a new vim file, and call it vundle.vim, and don’t you dare using any text editor other than vim

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" Add your Plugins here
" The NERD Tree
Plugin 'scrooloose/nerdtree'

call vundle#end()            " required
filetype plugin indent on    " required

In the previous text take a look at the “Add Your Plugins Here” section, and notice that I added the following line

Plugin ‘scrooloose/nerdtree’

I got that by going to this link and following the instructions to installing The NERD Tree using Vundle


Now, we need to connect our .vimrc file to our vundle.vim file by adding it as a source as follows:


vimrcmake sure to replace the folder JJvim with the folder you named.

Save, quit, and start vim again. Now we are going to install The NERD Tree into vim. So far we just integrated vim with vundle

Invoke the :PluginInstall command in vim



Again restart vim



Ok, you need to Invoke its command to start it



There it is


Ok, starting vim and invoking the :NERDTree command every time is a pain. We need to have The NERD Tree already started when we start vim. In order to do that, we will create a new .vim file, call it NERDTree.vim, and have all our configurations for The NERD Tree in it.

” To start NERDTree automatically whenever we start vim
autocmd vimenter * NERDTree

” To close vim even if the NERDTree buffer is still open
autocmd bufenter * if (winnr(“$”) == 1 && exists(“b:NERDTree”) && b:NERDTree.isTabTree()) | q | endif

In the previous code the first command is to start NERDTree automatically, the second is optional to you but to me, if I close all my buffers and NERDTree is the only buffer open, then I’d rather have vim completely closed. If you are wondering where I got these commands from, then again, go to the vimawesome NERDTree page and check the FAQ section.

Before I end this post, don’t forget to add the NERDTree.vim file in the list of sources of your .vimrc file

source ~/JJvim/vimrcs/NERDTree.vim

In the next post – Hopefully – I will add a theme to vim.

1 thought on “Vimrc Tutorial – 1

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll Up
%d bloggers like this: