I probably spend way too much time configuring my VIM setup. It tends to change depending on what I’m working on. So, at the moment the following things matter to me most:

There would be Scala, but I use the excellent IntelliJ IDEA product for that. Nothing can beat it, so there’s no point trying to get VIM to do it.

It matters to me that my editor works cross platform too. Not fussed so much about VIM on Windows (although it’s nice when that works too) but more between OSX and Linux as they are the main two Operating Systems I use.

So I felt I’d do a post about how I manage my VIM config as it may/may not be useful for others.

Setup

Let’s start nice and empty:

1
2
3
4
5
mv ~/.vim ~/.vim.old
mv ~/.vimrc ~/.vimrcold
mkdir ~/.vim
touch ~/.vim/myvimrc
ln -s ~/.vim/myvimrc ~/.vimrc

Why do this? Well, simply put - this way your .vim folder can be easily stored in Git or another VCS you fancy. Job done!

Right, so what next? vundle all the things.

1
2
mkdir ~/.vim/bundle
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/vundle

Now you need a small bit at the top of your .vimrc file.

1
vi ~/.vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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()"

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

" Your stuff is going go here...

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

Now we have a basis of a working VIM we can work on. Let’s set up some cool stuff now…

Some obvious bootstrap things

By default, VIM likes to behave a little bit old fashioned. We want some niceties from the off - so let’s do that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
set expandtab     " Soft tabs all the things
set tabstop=2     " 2 spaces is used almost everywhere now
set shiftwidth=2  " When using >> then use 2 spaces
set autoindent    " Well, obviously
set smartindent   " As opposed to dumb indent

set noautowrite
set number
set autoread      " Read changes from underlying file if it changes
set showmode      " Showing current mode is helpful++
set showcmd
set nocompatible  " Actually make this vim
set ttyfast       " We don't use 33.6 modems these days
set ruler

set incsearch     " Use incremental search like OMG yes
set ignorecase    " Ignore case when searching
set hlsearch      " Highlight searching
set showmatch     " Show me where things match
set diffopt=filler,iwhite "Nice diff options
set showbreak=" Cooler linebreak
set noswapfile    " It's 2014, GO AWAY FFS

set esckeys       " Allow escape key in insert mode
set cursorline    " Highlight the line we're on
set encoding=utf8 " Really, people still use ASCII

You’ll notice that 2 spaces is the default but, obviously, Python is a good example of a language that uses 4.

1
au FileType python setlocal tabstop=8 expandtab shiftwidth=4 softtabstop=4

This way you’ll see, we get to customise each language. It’s nice. ‘au’ is short for auto. As in… Automatically run this when the FileType is python.

Syntastic

This is the Batman utility belt. It’s also easy to set up and serves as a good example of how Vundle works.

1
Bundle 'scrooloose/syntastic'

Job done. Make sure this goes between the Vundle begin and end calls.

Now save that and we’ll online reload/install:

1
vim -c "execute \"BundleInstall\" | q | q"

This will load up vim, install all the things and then exit when done.