Keith T. Butler

Supercharging VIM

April 03, 2018 | 4 Minute Read

tags: [ vim  code  ]

I decided that I want to set up vim as my developer environment. This is mostly because I love vim, but also for the smaller projects that I work on some of the available IDEs feel too heavy and unnecessary. In general, the tools described below are useful even if you are not doing code development. Things like being able to navigate through the file tree and see syntax highlighting, search for other files etc are nice in any scenario. This setup should take 20 - 30 minutes.

So let’s go from:

Vim before.

To:

Vim after.

in a few easy steps.

Package manager

This takes all the pain out of installing new plugins.

  • vundle seems like a good option.
  • A very thorough guide on how to set up vundle.
  • A quick-start guide for the impatient:
    • Clone the repo:
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
  • Edit your ~/.vimrc:
"""" START Vundle Configuration
"""" Vundle is a VIM package manager - all plugins go in here
 
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 'VundleVim/Vundle.vim'
 

Plugins go here

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

A file tree navigator

This lets you see where you are in the filesystem. It also lets you browse through and look for other files that could be of interest.

  • NERDTree is the clear choice.
  • Allows you to open a file tree from vim and navigate through.
  • I suggest enabling the mouse, add set mouse=r to ~/.vimrc.
  • Note, you can use ctrl+w to toggle between the tabs.
  • To open up the tree from vim, just type :NERDTree.
  • Standard vim commands can close the tree :q.

A Tagbar

Tagbars are used for navigating code. A tag bar shows the tags of the current file. The tags are things like classes, functions and variables in a code file.

  • OSX - get exuberant ctags brew install ctags.
  • Open up vim and use vundle to search for packages Tagbar.
:PluginSearch Tagbar
  • Navigate to the Tagbar package and hit i.
  • Now simply add Plugin 'Tagbar' line to your ~.vimrc in the Plugins go here section.
  • To use :TagbarToggle turns it on/off.

Tab completion

Because of course you want tab completion. Supertab is a good option.

  • Open vim.
  • :PluginSearch supertab.
  • Navigate to supertab and hit i.
  • Now simply add Plugin 'supertab' line to your ~.vimrc in the Plugins go here section.
  • To use, just hit tab while typing.

A fuzzy finder

An example of what the search function looks like.

Just like Google or Mac spotlight search, fzf gives you autocomplete finding (allowing for spelling mistakes etc) from the command line! And, you can plugin to vim to allow for fuzzy searching of your file system from your favourite text editor! See this video of examples of how useful it can be.

  • Download fzf:
brew install fzf
  • Add the following to your .vimrc:
Plugin 'junegunn/fzf'
Plugin 'junegunn/fzf.vim'
  • Open vi and run:
:PluginInstall
  • To use:
    • :Files <path> searches in <path> for files.
    • :Buffers open buffers.
    • :History command history.
    • :Commits Git commits.
    • Many more.

Airbar

This airbar looks the business.

I’m not going to lie, although airbars are useful, this one is more about the look than the utility. It just sits at the bottom of the screen making you look like a pro. Although it does give useful information like the file format, the mode you are in.

  • Add the following to your .vimrc:
Plugin 'vim-airline/vim-airline'
  • Open vi and run:
:PluginInstall