vi vi file

Edit file

:e file

Save file


Save and quit



:q :q! # quit without saving




filetype plugin indent on # turns on "detection", "plugin" and "indent" at once set tabstop=4 # show existing tab with 4 spaces width set shiftwidth=4 # when indenting with '>', use 4 spaces width set expandtab # on pressing tab, insert 4 spaces

Move by character

h # left j # down k # up l # right space

Move by text


w or W # next word (stop or skip puncuation) b or B # previous word (stop or skip puncuation) e or E # end of word (stop or skip puncuation)


), (


}, {


]], [[

Move by line

Current line

0/^ n| $

Next, previous line

\r + or -

Top, middle, and last line of screen

H, nH M L, nL

Move by screen

One screen: forward, backward

^f ^b

Half screen: down, up

^d ^u

One more line at bottom, top of window

^e ^y

Reposition cursor to top, middle, or bottom of screen

z\r z. z-

Redraw screen

^l ^r

Move by window

Move to another window (cycle)

^w ^w

Up / Down / Left / Right

^w up ^w down ^w right ^w left


Search forward and backward

/text ?text

Repeat search, repeat search in opposite direction, repeat forward and backward

n N / ?

Go to line n after, before text

/text/+n ?text?-n

Current line character search

fx, Fx # Move search forward, backward to x tx, Tx # Search forward,before, backward after x , # Reverse search direction of, f, F, t, or T ; # Repeat last character search (f, F, t, or T)

Line numbering

^g ng g :n

Marking position

mx `x `` ''

Split window

Split window and load another file

:split file

Same as split, but readonly

:sview file

Vertical split

:vsplit file

Show & hide window

Close current window


Keep only this window open


Resizing window

Maximize current window


Make all window equal size


Increase window size by 10 lines

10 ^w+


Show current buffers


Open buffer #2 in this window

:b 2

Create, delete folding

Creation fold


d-elete, delete all fold

zd, zD

Open, close folding

o-pen, open all fold

zo zO

c-lose, close all fold

zc zC

Folding less, more

r-educe fold

zr zR

fold more

zm zM

Disable, enable fold

disable, enable fold

zn zN

Toggles between zn and zN


Insert mode

Get back to Command mode


Insert text

Insert before cursor or at beginning of line

i I

Append after cursor or at end of line

a A

Open line below or about cursor

o or O

Change text (m is movement)


Copy, cut, paste

Cut char under or before cursor

x X

Cut m movement, line, to end of line

dm dd D

Yank m movement or current line

ym yy Y

Paste after or before cursor

z p P

Search & replace

Change all "old" to "new" from lines n to m. "old" can be regular expression. Symbolic line: . (current), $ (last)

:n,m s/old/new/g

Formating text

Indent n lines (m is movement)


Un-indent n lines (m is movement)


Wwitch case


Undo, redo

Undo last command, or undo changes on current line

u U