You can view my .vimrc file on GitHub. It’s patched together from various sources. Here I’m going to do a line-by-line explanation of why I have written what I have.

set history=500

I have this so that I can undo as far back as I need to.

set autoindent
set tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab

Various indentation/tab improvements including autoindentation and tabs expanding to 4 spaces.

set autoread

If the file I’m editing is modified externally, vim reloads it.

command W w !sudo tee % > /dev/null

:W does the same as :w but with sudo - useful for when you forget to run vim as sudo.

set ruler
set number

I can’t stand editing a file without being able to see line numbers and my location on the page.

set hlsearch

Highlighting seach results makes searching much better.

filetype indent plugin on

Needed for various things.

syntax enable

Enables syntax highlighting.

map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l

This is amazing - it allows you to move across windows with ctrl+hjkl rather than ctrl+w hjkl. Saves so much time. It’s from the ultimate vimrc.

set ignorecase
set smartcase

Use case insensitive search, except when using capital letters.

set backspace=indent,eol,start

Allow backspacing over autoindent, line breaks and start of insert action

call plug#begin('~/.vim/plugged')
Plug 'flazz/vim-colorschemes'
Plug 'tpope/vim-surround'
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'tpope/vim-fugitive'
Plug 'sheerun/vim-polyglot'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'Valloric/youcompleteme', { 'do': './install.py' }
Plug 'airblade/vim-gitgutter'
call plug#end()

This uses the amazing vim-plug to install my plugins. Here I’ll go through them:

Plug 'flazz/vim-colorschemes'

This includes many colourschemes. I use molokai.

Plug 'tpope/vim-surround'

This amazing plugin lets you easily surround text with quotes, html tags, brackets, etc.

Plug 'scrooloose/nerdcommenter'

This makes commenting really streamlined.

Plug 'scrooloose/nerdtree'

This adds a very useful tree view to see your files and open new ones without leaving vim.

Plug 'Xuyuanp/nerdtree-git-plugin'

Adds git support to nerdtree. A must have if you use git and nerdtree.

Plug 'tpope/vim-fugitive'

While we’re talking about git, here’s a plugin that allows you to use git from within vim!

Plug 'sheerun/vim-polyglot'

This adds loads of language-specific functionality. Much better than installing all the language-specific plugins seperately.

Plug 'vim-airline/vim-airline'

This plugin gives a great status bar at the bottom with loads of info. On my system I had to fiddle a bit with the symbols to get them to work.

Plug 'vim-airline/vim-airline-themes'

Themes for vim-airline.

Plug 'Valloric/youcompleteme', { 'do': './install.py' }

This plugin adds autocomplete for loads of languages.

Plug 'airblade/vim-gitgutter'

This adds a line along the side showing git additions, deletions or changes.

Okay, now we’re out of the plugins. There’s still some more stuff though.

colorscheme molokai

Other colour schemes are available.

let g:airline_theme='molokai'

Other airline themes area available.

if !exists('g:airline_symbols')
    let g:airline_symbols = {}
endif

Creating an array of airline symbols to fill.

let g:airline_symbols.branch = '⎇'

Changing the branch symbol to prevent it from being rendered as just a question mark in a box.

That’s my .vimrc. If you have any suggestions or comments, please do send them to me with one of the contact options.