Vim Cheat Sheet for Ruby & Ruby on Rails


Install the following plugins:

<leader> mapped to " \ " by default.

Project Management

(Using vim-rails)

Action Command
New project :Rails new project
Start Server :Rserver {options}
Rails Console :Rails console
Generate Templates :Rgenerate {options}
Undo Generate :Rdestroy {options}
Preview path in browser :Rpreview {path}
Rake Commands :Rake {options}

Alternate or Related Files

(Using vim-rails)

Action Command
:A Get Alternate File
:R Get Related File
Current File Alternate File Related File
model unit test related migration
controller functional test template(view)
template(view) helper controller(method)
migration previous migration next migration
config/routes.rb config/database.yml config/environment.rb

File Navigation

(Using vim-rails)

Action Command
Opens file with filename under cursor gf
Open alternate file :A
Open alternate file in new split window :AS
Open related file :R
Open related file in a new split window :RS
Find and edit a file :find
Open the controller file with the word under the cursor as filename :Econtroller
Open the model file with the word under the cursor as filename :Emodel
Open the view file with the word under the cursor as filename :Eview


(Using surround.vim)

Snippet Command
<%= %> S + =
<% -%> S + =
<%# %> S + #


(Using vim-ruby-doc)

Action Command
Ruby docs RB
RSpec docs RS
Rails docs RR
Ruby docs for search_term :RubyDoc <search_term>
RSpec docs for search_term :Rspec <search_term>
Rails documentation for <search_term> :RailsDoc <search_term>


(Using vim-rails, tab-completion)

Command Result
pa[ params
rq[ request
rs[ response
se[ session
hd[ headers
te[ templates
co[ cookies
fl[ flash
rr( render
rrp( render partial:
rl( render layout:
ra( render action:
rea( redirect_to action:
rec( redirect_to controller:
:a action:
:c controller:
:i id:
:o object:
:p partial:
logd( logger.debug
logw( logger.warn
loge( logger.error
logf( logger.fatal


(Using vim-rails)

Action Command
Run one spec :.Rake
Run whole spec suite :Rake

Rake Tasks

(Using vim-rake)

Action Command
Invoke rake. :Rake [task]
Edit alternate file. :A
Edit alternate file in horizontal split window. :AS [file]
Edit alternate file in vertical split window. :AV [file]
Edit alternate file in new tab. :AT [file]
Edit a Ruby file under lib/ :Elib [file]
Edit a test file under test/ :Etest [file]
Edit a spec file under spec/ :ESpec [file]
Edit a rake file under rakelib/ :Etask [file]


(Using vim-coffee-script) (Using vim-javascript-syntax)

Action Command
Compile coffeescript to javascript :compiler coffee
Compile into javascript without showing output. :silent make


(using fugitive)

Action Command
Run an arbitrary command :Git {args}
Output of git-status :Gstatus
Commit(Ru :Gstatus if no args) :Gcommit {args}
A wrapper around git-grep :Ggrep {args}
Previous revisions of current file :Glog {args}
Write to file and stage :Gwrite
vimdiff against revision :Gdiff {revision}
Wrapper for git-mv :Gmove {destination}
Wrapper for git-rm :Gremove
Run git-blame on the file :Gblame {flags}

Gem Management

(via vim-bundler)

Action Command
Invoke bundle :Bundle[!] [args]
With no argument, edits the Gemfile. Otherwise, effectively does a bundle open of a gem :Bopen[!] [gem]
Like :Bopen, but don't :lcd afterwards. :Bedit[!] [gem]
Like :Bopen, but horizontally split. :Bsplit[!] [gem]
Like :Bopen, but vertically split. :Bvsplit[!] [gem]
Like :Bopen, but use a new tab. :Btabedit[!] [gem]
Like :Bopen, but use a preview window. :Bpedit[!] [gem]

Window Management

Action Command
Puts cursor in top window ctrl-w up arrow
Puts cursor in next window ctrl-w ctrl-w
Maximise current window ctrl-w_
Gives the same size to all windows ctrl-w=
Add 10 lines to current window 10 ctrl-w+
Split window horizontally :split file
Split window vertically :vsplit file
Same as :split in readonly mode :sview file
Close current window :hide
Close all windows, excepted current :­nly
Open #2 in this window :b 2


(Uses NERDTree)

Action Command
Open a new NERD tree with the current directory as root. :NERDTree
Open a new NERD tree with the bookmark as the root directory. :NERDTreeFromBookmark <bookmark>
Reopen and render existing NERD tree for the tab. :NERDTreeToggle
Share an existing NERD tree from an existing tab. :NERDTreeMirror
Close the current NERD tree. :NERDTreeClose
Find the current file in the tree. :NERDTreeFind
Change tree root to current directory. :NERDTreeCWD

NERDTree Navigation

(Uses NERDTree)

Action Command
Open files, directories and bookmarks. o
Open file and leave cursor in NERDTree. go
Open file/bookmark in a new tab. t
Same as 't' but keep the focus on the current tab T
Open selected file in a split window i
Same as 'i', but leave the cursor on the NERDTree gi
Open selected file in a new vsplit s
Same as s, but leave the cursor on the NERDTree gs
Recursively open the selected directory O
Close the current nodes parent x
Recursively close all children of the current node X
Edit the current dir e
Delete the current bookmark D
Jump to the root node P
Jump to current nodes parent p
Jump up inside directories at the current tree depth K
Jump down inside directories at the current tree depth J
Move the tree root up one directory u
Same as 'u' except the old root node is left open U
Recursively refresh the current directory r
Recursively refresh the current root R
Display the NERD tree menu m
Change the CWD to the dir of the selected node cd
Change tree root to the CWD CD
Toggle whether hidden files displayed I
Toggle whether the file filters are used f
Toggle whether files are displayed F
Toggle whether the bookmark table is displayed B
Close the NERDTree window q
Zoom (maximize/minimize) the NERDTree window A
Toggle the display of the quick help ?


(Uses vim-rspec)

Action Command
Run current Spec file <Leader>t
Run nearest Spec <Leader>s
Run last Spec <Leader>l
Run all Specs <Leader>a


(Uses vim-cucumber) (Uses vim-rubytest)

Action Command
Opens step definition in current window CTRL-]
Opens step definition in split window CTRL-W
Opens step definition in split preview window CTRL-W
run test case under cursor <leader>t
run all tests in file <leader>T
run the last test, from any buffer <leader>l


Action Command
next difference ]c :
previous difference [c :
diff obtain do
diff put dp
open folded text zo
close folded text zc
re-scan the files for differences :diffupdate
Temporarily disable simultaneous scrolling. :set noscrollbind
Enable simultaneous scrolling. :set scrollbind

Color Options

(Uses colorv.vim)

View Colors

Action Command
show ColorV window :ColorV (<leader>cv)
show ColorV window with color text under cursor. :ColorVView (<leader>cw)
Preview colors in current buffer :ColorVPreview (<leader>cpp)

Edit Colors

Action Command
Edit color text under cursor :ColorVEdit (<leader>ce)
Edit color text under cursor and change all in current buffer. :ColorVEditAll (<leader>cE)
Insert color with ColorV window. :ColorVInsert (<leader>cii)

Design Colors

Action Command
show color name list window. :ColorVName (<leader>cn):
generate Hue list with color text under cursor. :ColorVList Hue (<leader>cgh)
generate Hue list from hex1 to hex2. :ColorVTurn2 {hex1} {hex2} (cgg)
show a GUI color picker. :ColorVPicker (<leader>cd)

Design Schemes

Action Command
Fetch scheme from Kuler or ColourLover :ColorVScheme (<leader>css)
Show Faved schemes :ColorVSchemeFav (<leader>csf)
Create a new scheme :ColorVSchemeNew (<leader>csn)


Action Command
Open CtrlP in find file mode. :CtrlP
Open CtrlP in find buffer mode. :CtrlPBuffer
Open CtrlP in find Most-Recently-Used file mode. :CtrlPMRU
Open CtrlP in the last mode used. When having the "--dir" argument. :CtrlPLastMode [--dir]
Flush the cache for the current working directory. :CtrlPClearCache
Delete all the cache files saved in :CtrlPClearAllCaches


(Uses vim-rvm)

Action Command
Set the current Ruby version to the version found in the .rvmrc :Rvm
Set the current Ruby version to {version}. :Rvm {version}
As above, but echo the version chosen. :Rvm use [version]
Run rvm with arbitrary arguments. :Rvm {command}

You may also be interested in


Talk to us, that's always a good idea!