Show Menu

VIM IDE Cheat Sheet by

vim IDE key mapping
ide     vim

Beginner Block

i
start insert
<es­c>
escape to normal mode
:w
in normal mode, write to current file
:q
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>m means <s­pac­e>m
<C­-a> means Ctrl + A , <S­-x> means Shift + x

Motions: command that moves the cursor

hjkl
left/d­own­/up­/right
f/F
search and move to next typed character
t/T
similar to f/F. but stop before character
0/$
start/end of current line
w/e
next start/end of word, W/E for word with punctu­nation
b/B
previous start of word B for word with punctu­ation
gg
go to line {count}, default first line
G
go to line {count}, default last line
-/<­ent­er>
previo­us/next start of the line
H/M/L
cursor go to TOP/MI­DDL­E/B­OTTOM of the screen
''
(single quote twice) previous location in jumplist
'{a-z}­/`{a-z}
previous marked position using m{a-z}, E.g. ma `a
'.
To the position where the last change was made.
%
move to closing pair [], {}, ()
{1-9}+
a number type before motions, repeat {count} motion
:help motion
check more on documents inside vim
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

Text-O­bje­ct-­Motion

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

Operator - editing the text effici­ently

d
delete/cut
c
change
y
copy/yank
~
reverse case
!
filter with external program, E.g. format doc
gu/gU
make lower/­upper case
</>
indent left/right
=
filter with predefined equalprg
zf
fold the text
Two way to combine operator and select­ions:
1. <op­era­tor­><m­oti­on> or <op­era­tor­><t­ext­-ob­jec­t-m­oti­on> etc.
2. <se­lection from visual mode><­ope­rat­or>
E.g. di" delete the word inside double quotes
Press one operator twice operate on current line as the select­ion
E.g. yy copy the current line, dd cut/delete the current line

Paste && Registers

p
paste content from register " before current cursor
P
paste after cursor
"0p
paste 0 register's content in normal mode
<C-­R>"
double quote, insert text as if typed
<C-­r>0
insert­-mode "0p
<C-­R>=
eval expression after = and paste
<C-­R>/
the last search pattern
<C-­R><­C-R­>"
equivalent to p in normal mode
: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"%­#*+­:.-=}.

p/P is used in normal mode, other Ctrl-­R{r­egi­ster} are used in insert mode and command line mode. (I reversed p/P since I feel p before cursor is more natural for modern IDE)

Page Movement

<C-­e>/­<C-­y>
move buffer down/up and keep cursor position
zz
bring current line and cursor to center
zb
move current line and cursor to bottom screen
zt
move current line and cursor to top screen

Visual Mode Commands

o
switch between two ends of selection (anchor)
<c-­v>
switch to visual block mode
V
switch to visual line mode
v
switch to visual mode
<le­ade­r>a
alignment, using plugin easy-­align

Tabs

gt
go to next tab
gT
go to previous tab
:tabnew
new tab, <­lea­der­>t
:tabclose
close current tab

Frequent Used Custom Shortcuts

[<s­pac­e> and ]<s­pac­e>
add newline before­/after current line
[e and ]e
move current line up/down, count applies
[p and ]p
go for next/p­revious quickfix item
[l and ]l
l for L, next linter hint (ALE Lint)

Target.vim - Extended and Smart Text Object

Key Sequence: <op­era­tor> <sc­ope> <se­ek?> <te­xt-­obj­ect>
a i A I
<sc­ope> around, inner, around­/Inner space included
n
<se­ek> next text-o­bject
l
<se­ek> seek last text-o­bject
, . ; : ...
<text object> for separator
b ( )
<text object> for parent­heses()
{}<­>[]t
<text object> blocks, html tags
Usage: <op­era­tor> <sc­ope> <se­ek?> <te­xt-­obj­ect>
E.g.
- diw delete the word without the surrou­nding whitespace
- vaw visual select the word & surrou­nding whitespace
- cia change next function arguments ( target.vim )
- dinb delete content inside next parent­hesis (targe­t.vim)
 

Windows (Split, Size Adjust­ment, Placement)

<C-­w>=
equal size display all panels
<C-­w>s
horizontal split
<C-­w>v
vertical split
<C-­W>p
go to last accessed window
<C-­w>H
put pane to absolute left, take full height
<C-­w>L
put pane to absolute right, take full height
<C-­w>J
put pane to absolute bottom, take full width
<C-­w>K
put pane to absolute top, take full width
:set splitright
for vertical split, place new pane right
<C-­w>hjkl
move to relative left/d­own­/up­/right pane

Insert Mode ( Emacs Style Single Line Editing)

<C-­a>
Jump to the beginning of the line
<C-­e>
Jump to the end of the line
<C-­w>
Backwa­rd-­Delete Word
<C-­d>
Forwar­d-D­elete Word
<C-­z>
backward move cursor one word
<C-­x>
forward move cursor one word
<C-­u>
delete/cut current line
<C-­y>
paste/yank to current line
<C-­k>
delete the rest line after cursor

Useful Utility Commands (Normal Mode)

.
dot command, repeat last change
J
Join the line below to current line
<C-­a>
add {count} to number under cusor
<C-­x>
subtract {count} to number under cusor
<C-­R>=
calculator <C-­R>=­128/2, insert mode
@;
repeat last cmdline command, <le­ade­r>:
<le­ade­r>j
break current line and move trailing part one line above
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>
<le­ade­r>ca
add cscope.out <wo­rksapce path>
<le­ade­r>ga
search assignment to this variable
<le­ade­r>gs
search the C symbol under cursor
<le­ade­r>gg
search global defintion
<le­ade­r>gd
search funtions called by this function
<le­ade­r>gc
search who called this function
<le­ade­r>gt
search this string
<le­ade­r>ge
search this egrep pattern
<le­ade­r>gi
search for files include the current file
<le­ade­r>gn
search for files include the filename under cursor

Normal Commands (My Config­ura­tion)

%
go to pairs, if/else, html tags, etc
=
format and intent the file E.g. clang-­format
\
go to end of line
q
close current window
gf
go to file under cursor or fzf search
<le­ade­r>l
toggle invisible characters E.g. whitespace
<le­ade­r>m
open tagbar for current file
<le­ade­r><­cr>
Remove Highlights :noh
<le­ade­r>u
open the undotree
<le­ade­r>z
Distra­cti­on-Free Display, full-z­oomed window
<le­ade­r>q
open quickfix window

Command Mode :

:%
{range}, equal to 1,$ (the entire file)
:! <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
Ctrl-f
open cmdline editing windows

fuzzy-­sea­rch­-panel (My config­uration FZF Plugin)

<c-­f>
select all
<c-­g>
deselect all
tab/sh­ift-tab
select­-de­select current line
<C-­t>
open file in new tab
<C-­x>
split horizo­ntaly
<C-­v>
split vertically
<es­c>/­<c-­d><­c-c>
quit

Special and Very Useful Windows -- Quickfix

:copen­/:c­close
open/close Quickfix
:cn
go to next fix
:cp
go to previous fix
Quickfix typically used after :make command and 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

Commentary ( External Plugin Default)

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

Code Folding

zf
fold selection text
zo
open selection text

Code Review

vimdiff
diffmode for two files (vim -d file1 file2)
git dt
use vim to code review
git dt master
code review based on master branch
dp
modify another buffer to be same as current buffer
do
modify current buffer to be same as other
! Assuming using GIT for version control, setup the ~/.git­config
`
[alias]
d = diff
ds = !git diff --stat
dn = !git diff --name­-only
dt = difftool
[diff]
tool = vimdiff
[difftool]
prompt = false
`

Download the VIM IDE Cheat Sheet

4 Pages
//media.cheatography.com/storage/thumb/piping_vim-ide.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

          Sublime Text 2 Windows Keyboard Shortcuts
          Vim NERDTree Cheat Sheet