Vim for Rails development

23 12 2008

UPDATE: This configuration, while valid, is pretty obsolete. I recommend you just grab my config from github at which I update more often.

I’ve been using Vim for a while for all ruby and rails development. Vim is a fantastic cross platform text editor, and the more you use it, the more you realize how efficient it is.

vim screenshot on windows

vim screenshot on windows

But you won’t get too far with the default vim installation. Here’s a few settings and plugins that take the experience from great to superb.

Starting with the plugins:

  • matchit.vim: Press % to jump between parenthesis, brackets, html tags, you name it!
  • fuzzyfinder and fuzzyfinder_textmate: This duo make finding files in your project a snap, making plugins like Project and NERDTree a waist of time in my opinion (there’s always :E or :Sex if you really need to browse around).
  • surround.vim is all about dealing with surroundings in text strings. It helps to rapidly change single to double quotes, quotes to html, etc.
  • BlockComment.vim: select a block in visual mode, and use .c to comment it, and .C to uncomment it.
  • camelcasemotion.vim will create word boundaries at CamelCase or under_score word endings when using the motion keys w, b and e (see my vimrc for configuration).
  • rails.vim. If you’re doing Rails programming, you must install this. End of story.
  • snippetsEmu emulates a bunch of the snippets implemented in E/TextMate. For instance, key in def and a method definition will be expanded with the cursor right on the spot to write the method name. Other snippets for each, map, and others are also emulated.
  • vcscommand.vim: Why would you have to leave your editor to commit your changes or update your code? You don’t. VCSCommand handles Git, SVN and other SCMs
  • Exuberant CTags is just magic! Position the cursor over any method call and press C-[ to jump right to the method definition. C-T takes you back. A must have.

In terms of eye candy, there are three colorschemes that I’d like to mention: railscasts, oceandeep and vividchalk. I keep alternating between these, but have settled for railscasts for a while now.

The font I’ve settled for is Envy Code R.

Finally, my .vimrc file:

set nocompatible
" I usually go back and forth between these three colorschemes.
":colorscheme oceandeep
":colorscheme vividchalk
:colorscheme railscasts
" Some taken from
set history=1000
" additional matches for %: do/end, if/else/end, the usual () [] {}...
runtime macros/matchit.vim
set wildmode=list:longest
" search case insensitive
set ignorecase
" search case sensitive when search-term has a capital letter
set smartcase
nnoremap 3
set ruler
" Intuitive backspacing in insert mode allow, backspace over everything
set backspace=indent,eol,start
" Highlight search terms...
set hlsearch
" search dynamically as keyword is typed.
set incsearch
set shortmess=atI
" get rid of the BEEP
set visualbell
" Provide two lines of context
set scrolloff=2
" set GUI font, again, I go back and forth between these
"set gfn=Bitstream_Vera_Sans_Mono:h9:cANSI
set gfn=Envy_Code_R:h10:cANSI
" when a line has wrapped, jk navigation moves one line on the screen, instead of one line in the file
nnoremap j gj
nnoremap k gk
vnoremap j gj
vnoremap k gk
nnoremap gj
nnoremap gk
vnoremap gj
vnoremap gk
inoremap gj
inoremap gk
" CamelCaseMotion plugin mappings
map w CamelCaseMotion_w
map b CamelCaseMotion_b
map e CamelCaseMotion_e
" Tell vim to remember certain things when we exit
" '10 : marks will be remembered for up to 10 previously edited files
" "100 : will save up to 100 lines for each register
" :20 : up to 20 lines of command-line history will be remembered
" % : saves and restores the buffer list
" n... : where to save the viminfo files
set viminfo='10,\"100,:20,%,n~/.viminfo
" remember open buffers accross sessions
" set viminfo^=%
" Quick write (F2) and load (F3) session:
map :mksession! ~\vim_session
map :source ~\vim_session
" highlight line of cursor:
set cursorline
" Remove toolbar
set guioptions-=T
" and menus
set guioptions-=m
" For fuzzy finder/textmate
" Requires fuzzyfinder and fuzzyfinder_textmate plugins
let g:fuzzy_ignore = "*.log"
let g:fuzzy_ignore = ".svn"
let g:fuzzy_matching_limit = 70
map t :FuzzyFinderTextMate
map b :FuzzyFinderBuffer
" me likes the syntax folding:
set foldmethod=syntax

How about you? Any plugin or setting I may be missing?




One response

4 03 2009
Zayd Connor

Cool! Great Job having this available, I’m going to copy cat your configurations =). This has been very helpful. Right now I use vividchalk, but I’m going to try out the other two you mentioned.

See Ya

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: