My VIM configuration – part I

Posted by on Jan 30, 2015 in tools | No Comments
My VIM configuration – part I

I have been using Vim and gVim for a few years now.

Vim has a steep learning curve (but there are great tutorials out there), but its worth it, as it is a very powerful text editor.

While it is not supposed to be an IDE, there are a lot of plugins out there that can make it get pretty close.

In this post I will share with you some of the configurations I use. Specifically, I will show you how I get gVim to look the way I like it.

Vim stores its configurations in a file called .vimrc, in your home dir.

That may mean different things depending on the operating system you are using. For Linux and Mac OS X, it is your home dir (just type cd ~ in a shell and you will be there). In windows it can vary, but you can get there in a cmd shell by typing cd %HOME%.

In windows the vimrc file is sometimes called _vimrc. You can safely rename it to .vimrc and it will still be loaded. This is useful if you decide you want to keep your vimrc checked-in somewhere and only maintain one version for all platforms.

Before we start: I use Vundle, a VIM plugin manager that lets you install plugins directly from git (github by default). For this to work, you need to have git available as a shell command.

Step 1 – Setup Vundle

Add this to your vimrc file (ignore the line numbers shown here, they are just meant to help me refer to a particular line in my posts):

"""""" Use Vundle """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

"""""" Plugins """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Plugin 'gmarik/vundle'

After this, restart your vim (or reload vimrc by typing :source % in the vim command line).

It should still look the same old boring defaults.

step1

This screenshot shows MacVim, but if you are running another Vim flavor, you should also see a clunky toolbar. Keep reading, we will hide it 😉

Step 2 – Setup colortheme and GUI options

Modify your vimrc to look like this:

"""""" Use Vundle
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

"""""" Plugins
Plugin 'gmarik/vundle'
Plugin 'oceandeep'
Plugin 'cthulhian'

"""""" GUI specific options
if has("gui_running")
colorscheme cthulhian
set guioptions-=T "disable gui toolbar
endif

Reload it, and ask Vundle to install plugins by invoking the :BundleInstall command in vim.

Reload it again and it should now look like this:

step2

I have been using the oceandeep colortheme for quite a few years now. I love it. I have recently discovered cthulhian, which slightly tweaks some colors in oceandeep (you need to have both installed for cthulhian to work). This is my new favorite theme!

Another noteworthy theme you might be interested in is solarized.

step 3 – customize the status line

We will be installing vim-airline. For it to fully work, it needs a patched font installed (to show some extra symbols).

I recommend installing Source Code Pro for Powerline. Powerline was the first vim plugin that did something like this.

Adapt your vimrc to look like this:

"""""" Use Vundle
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

"""""" Plugins
Plugin 'gmarik/vundle'
Plugin 'oceandeep'
Plugin 'cthulhian'
Plugin 'vim-airline'

"""""" GUI specific options
if has("gui_running")
colorscheme cthulhian
set guioptions-=T "disable gui toolbar
set guifont=Source\ Code\ Pro\ for\ Powerline:h18
endif

"""""" generic options
set laststatus=2 "always show status line

"""""" configure plugin: vim-airline
let g:airline_powerline_fonts=1

Reload it, run :BundleInstall and restart vim.
It should now look like this:
step3

 

step 4 – add more visual tweaks

Adapt your vimrc to look like this

"""""" Use Vundle
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

"""""" Plugins
Plugin 'gmarik/vundle'
Plugin 'oceandeep'
Plugin 'cthulhian'
Plugin 'vim-airline'

"""""" GUI specific options
if has("gui_running")
colorscheme cthulhian
set guioptions-=T "disable gui toolbar
set guifont=Source\ Code\ Pro\ for\ Powerline:h18
endif

"""""" generic options
set laststatus=2 "always show status line
set number "show line number
set nowrap "do not wrap lines
set listchars=tab:>-,trail:~,extends:>,precedes:< "show tabs, whitespace and line overflow/underflow
set wildmode=longest:full "when choosing, show longest match
set wildmenu "and show the remaining options in a menu

"""""" configure plugin: vim-airline
let g:airline_powerline_fonts=1

The extra options are commented inline. You can also run :help listchars, for example, to get the full description on that option.

These are the first things I add to a fresh Vim installation. I hope they help you.

I plan on doing a few more posts on particular Vim plugins that turned out to be life changers.

 

 

Leave a Reply