Show Menu

vim-rails Cheat Sheet by

My very own cheatsheet for advanced vim on Rails and JS
development     programming     javascript     rails     ruby     vim

Editing

Option-k, Option-d
Insert _
Option-K, Option-D
Insert -
C-l
Insert =>
C-k
Jump over pair expansion (e.g. quotes)
C-j
Jump over pair expansion, insert new line
<le­ade­r>Enter
Insert new line
<le­ade­r>ci
Change inside any surrou­nding
ci<­mot­ion>
Change inside surrou­nding
<le­ade­r>", ', ), [, {, `, etc
Surround word
Option-', ", (, etc
Change inside surrou­ndings
<le­ade­r>cas
Delete surrou­nding and go to insert mode
<le­ade­r>fef
Format entire file
<le­ade­r>a=
Tabularize on =
<le­ade­r>a:
Tabularize on :
<le­ade­r>a,
Tabularize on ,
gc<­mot­ion>
Toggle comments
gcc
Toggle comments for current line
sk, sj
Expand­/Join statements into one line
daa
Delete an argument
cia
Change inner argument
,:
Change hash syntax to Ruby 1.9
gcp
Comment paragr­aph­/block

Window management

C-j, C-k, C-h, C-l
Split switching
vv
Horizontal split
ss
Vertical split
<le­ade­r>qs
Clear last search
<le­ade­r>qq
Close Quickfix

Navigation

<le­ade­r>T
Toggle Tagbar
C-]
Go to tag
C-T
back from tag search
gf
Go to file
<le­ade­r>cd
Changedir of file in buffer
<le­ade­r>md
Create dir containing file in buffer
<le­ade­r>rcd
:lcd to rails repo
<le­ade­r>e­,es­,ev,tb
Helpers for edit command (current dir filled in)
C-p
Insert path of current file into a command
<le­ade­r>b, C-b
CtrlPB­uffer
<le­ade­r>jm
CtrlP app/models
<le­ade­r>jc
CtrlP app/co­ntr­ollers
<le­ade­r>jv
CtrlP app/views
<le­ade­r>js
CtrlP spec
CtrlP: Ctrl-Y
Create file and parent dirs
CtrlP: Ctrl-O
Open in...
CtrlP: Ctrl-T
Open in tab
CtrlP: Ctrl-V
Open in vert split
CtrlP: Ctrl-X
Open in horizontal split
CtrlP: Ctrl-D
Toggle full-path or filename search
CtrlP: Ctrl-R
Toggle regexp mode
<le­ade­r>ocf
Open changed files (git)
 

Motions

ar
Ruby block
ir
Inner Ruby block
ar, ir after selection command
Expand Ruby block selection
ae, ve
Entire file
a:, ci:, vi:, di:
Ruby symbol
a_
Underscore
af
Functions (JS, C)
am
A method
im
Inner method
[m, ]M
Start/end of next method def
]m, [M
Start/end of prev method def
]], ][
Start/end of next module­/class def
[[, []
Start/end of prev module­/class def
aM
Class
iM
Inner class
oar
Outer Ruby block

Ruby dev

<le­ade­r>bb
bundle install
<le­ade­r>rs, <le­ade­r>rb
rspec
Rspec buffer: q
Quit
Rspec buffer: n
Next failure message
Rspec buffer: p
Prev failure message
Rspec buffer: f
Go to finished at section
<le­ade­r>m
Rmodel
<le­ade­r>s
Related spec vsplit
<le­ade­r>pp
conque pry
<le­ade­r>ss
conque console
:Rake
Rake
:Rextract
Extract partial
crl
Plural­ize­/Si­ngu­larize
crt
Tableize, Classify

Integr­ation

:Conqu­eTerm <sh­ell>
Open a shell in the current buffer
<le­ade­r>!
Horizontal split conqueterm zsh
<le­ade­r>fc
Find merge conflicts
[n, ]n
Move to prev/next conflict marker
<le­ade­r>g
:Git
<le­ade­r>w
:Gwrite
<le­ade­r>gd
Git diff
<le­ade­r>gs
Git status
<le­ade­r>gc
Git commit
<le­ade­r>gbl
Git blame (also works with selection)
 

Searching

<le­ade­r>q/
vimgrep current word
<le­ade­r>/
:Ag
:Ag, :AgAdd, :LAg, :LGAdd
Ag (The silver searcher)
o
Ag Quickfix: Open
go
Ag Quickfix: Preview file
t
Ag Quickfix: Open in tab
v
Ag Quickfix: Open in vert split
q
Ag Quickfix: Close
%Subvert
Abolish: x: :%Subv­ert­/fa­cil­it{­y,i­es}­/bu­ild­ing­{,s}/g (See docs)
*
Search for word under cursor
<le­ade­r>*
Vimgrep word under cursor
gK
Search for doc
<le­ade­r>q/
Ag in quicks­earch for last search
K
Ag word under cursor
<le­ade­r>gd
Grep for def <cursor word>
<le­ade­r>gcp
Grep current Rails partial

Ruby and Rails abbrevs & snippets

logd/i­/f/e/w
logger.de­bug­/er­ror­/fa­tal­/in­fo/warn
AC::
Action­Con­tro­ller::
AO::
Active­Model::
AR::
Active­Rec­ord::
AS::
Active­Support
Contro­ller: pa
params[
Contro­ller: rst
respond_to
Contro­ller: rr
render
Contro­ller: rj
render :json
Contro­ller: rt
render :text
Contro­ller: hd
headers
Contro­ller: fl
flash
Contro­ller: re
redire­ct_to
Contro­ller: rq
request
Contro­ller: rs
response
Model: ho
has_one
Model: hm
has_many
beg
begin/­res­cue/end
req
require
def
def
defs
def self.
if
if condition; end
ife
if condition; else; end
elsif
elsif condition
r
attr_r­eader
w
attr_w­riter
rw
attr_a­ccessor
Enum
Enumerable
Comp
Comparable
am
alias_­method
dir
Filena­me.d­ir­nam­e(_­_FI­LE__)
ea
each brace
ead
each block

Download the vim-rails Cheat Sheet

2 Pages
//media.cheatography.com/storage/thumb/blackxored_vim-rails.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

            Ruby on Rails Cheat Sheet by Dave Child and addedbytes.com