Show Menu

VIM and its secrets Cheat Sheet by

vim key mapping

Beginner Block

start insert
<es­c> or <C-­[>
escape to normal mode
:w [<f­ile­nam­e>]
in normal mode, write to current file
in normal mode, quit the editor
[ https:­//g­ith­ub.c­om­/Pi­pin­g/d­otfiles ] has my config­ura­tion
Notation: <l­e­a­de­­r> key can be defined via let mapleader = "­\<s­pac­e>"
<C­-a> means Ctrl + A , <S­-x> means Shift + x

Cursor Motions: keystokes that move the cursor

search and move to next typed character
similar to f/F. but stop before character
start/end of current line
start and end of current line with non whitespace
next start/end of word, W/E for word with punctu­nation
previous start of word B for word with punctu­ation
go to line {count}, default first line
go to line {count}, default last line
previo­us/next start of the line
cursor go to TOP/MI­DDL­E/B­OTTOM of the screen
(single quote twice) previous location in jumplist
previous marked position using m{a-z}, E.g. ma `a
To the position where the last change was made.
move to closing pair [], {}, ()
a number type before motions, repeat {count} motion
:help motion
check more on documents inside vim
g; g,
cycle through change positions
Vim Concept: Motions - command that moves the cursor, depends on current cursor position. Above list is not complete! It can be used with OPERATOR to effici­ently editing text in Textual User Interf­ace

Operator - commands that edit text effici­ently

reverse case
filter with external program, E.g. format doc
make lower/­upper case
indent left/right
filter with predefined equalprg
fold the text
Two way to combine operator and select­ions:
1. operator first then selection
2. visual selection first then does operation
E.g. di" delete the word inside double quotes or equiva­lently vi"d.
E.g. yy copy the current line, dd cut/delete the current line (Press one operator twice operate on current line as the select­ion)

Text-O­bje­ct-­Motion : Level Up Cursor Motion

around a paragraph
inner word
aroud word
inner double quote
around double quote
last search result, follow after operator
search­-offset to that whole line
:h iw
help for more

Paste && Registers

paste after cursor using content from register "
paste before cursor or cursor line
paste 0 register's content in normal mode
show content of a list of registers
:h i_ctrl-r
more registers
VIM Concept: Registers, used to store copy/cut text, the register can have single character names, {0-9a­-z"%­#*+­:.-=}.

Page Movement

move buffer down/up and keep cursor position
bring current cursor line to center
bring current cursor line to bottom screen
bring current cursor line to top screen

Visual Mode Commands

switch between two ends of selection (anchor)
switch to visual block mode
switch to visual line mode
switch to visual mode


go to next tab
go to previous tab
new tab, <­lea­der­>t
close current tab

File Navigation

Ctrl + 6 / Ctrl + ^
jump to previous opened file in current window
open file using the text under the cursor
:tabe <fi­len­ame>
open file in the new tab
:e <fi­len­ame>
open file in the current window
list current opened buffer­s(f­iles)
:buf <nu­mbe­r>
open selected buffer­(file) in the current window

Start Insert Mode in various way

insert after the cursor (append)
insert in front of the cursor
I (Caps i)
Insert at the beginning of the line
Insert at the end of the line
remove current character and enter insert mode
enter insert mode with REPLACE semantic
c <mo­tio­ns>
delete selected text and enter insert mode
go to last edited place and enter insert mode

Windows (Split, Size Adjust­ment, Placement)

equal size display all panels
horizontal split
vertical split
go to last accessed window
put pane to absolute left, take full height
put pane to absolute right, take full height
put pane to absolute bottom, take full width
put pane to absolute top, take full width
:set splitright
for vertical split, place new pane right
:vertical split <fi­len­ame>
vertical split buffer­/file
move to cursor to relative left/d­own­/up­/right pane

Insert Mode ( Emacs Style Single Line Editing)

Jump to the beginning of the line
Jump to the end of the line
Backwa­rd-­Delete Word
Forwar­d-D­elete Word
paste/yank to current line
delete the rest line after cursor

Useful Utility Commands (Normal Mode)

dot command, repeat last change
Join the line below to current line
add {count} to number under cusor
subtract {count} to number under cusor
repeat last cmdline command
break current line and move trailing part one line above
dot command . repeat text changes that is defined by vim. E.g. invoked by operator c and followup inserted text.

Ctrl+R (Using Registers in Insert­/Co­mmand Mode)

put last search string
calculator <C-­R>=­128/2, insert mode
put last copied text
put second to last copied text
dot command . does not repeat command line commands, only changes that is defined by vim. E.g. invoked by operator c and followup inserted text.

CSCOPE MAPPING (My Config­ura­tion)

:cs add <path to cscope.ou­t> <path to worksa­pce>
add cscope.out <wo­rksapce path>
search the C symbol under cursor
search global defintion
search who called this function
search this string as egrep pattern
search for this file under cursor
search for files that include the current file
search assignment to this variable
cscope is the most common tool for developing c projects. (look up symbol, defini­tion, locate caller­/callee of functions, etc). cscope interface is built-in feature for most vim distri­bution. To generate cscope database, first use cscope -Rbq in your project directory.

Normal Commands (My Config­ura­tion)

close current window
equivalent to :noh Remove Search Highlights
open tagbar for current file
toggle line number display
open current file in a new tab to "­ZOO­M"

Command Mode :

{range}, equal to 1,$ (the entire file)
:{range}! <ex­ternal cmd>
range of text is being pipe to cmd to be replaced
:%! xxd
edit binary file
:%! xxd -r
save the file into binary form
open cmdline editing windows

Special and Very Useful Windows -- Quickfix

open/close Quickfix
go to next fix
go to previous fix
:make all -j
build the code & report on quickfix list
Quickfix typically used after :make command and can be configured to work with cscope. The quickfix window contains the parsed result from :make that contains where compli­cation error happen, and put cursor to exactly the file/l­ine­/column so user can just fix it!
I open quick fix with my shortcut and prefix a :botright copen to open it at the bottom of window

Fold The Content

:set foldme­thod=
available values: syntax, indent, manual
:set foldlevel=
0,1,2,­3,.., applied when value is changed
toggle folding at the cursor position
Operator to create a fold (manual mode only)
open selection text
close the fold

Vim Diff Mode

:diffsplit <[f­ile­nam­e]>
split the window with diff mode on
turn off diff mode, (include diff highli­ghts)
:set diff!
only switch the diff color highlight
diff obtain the change from the other side
diff put change to the other side
windo diffoff can turn off all diffmode windows in current tab

Commentary ( External Plugin )

commen­t/u­nco­mment current line
comment next 10 lines
comment block
comment the paragrah
comment selection (visual mode)

Help Us Go Positive!

We offset our carbon usage with Ecologi. Click the link below to help us!

We offset our carbon footprint via Ecologi


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

          Sublime Text 2 Windows Keyboard Shortcuts
          ISTQB Test Automation Engineering Cheat Sheet