qiangc.net

Vi

Start

vi vi file

Edit file

:e file

Save file

:w

Save and quit

:wq

Quit

:q :q! # quit without saving

Help

:help

.vimrc

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

Word

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)

Sentence

), (

Paragraph

}, {

Section

]], [[

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

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

:hide

Keep only this window open

:only

Resizing window

Maximize current window

^w_

Make all window equal size

^w=

Increase window size by 10 lines

10 ^w+

Buffer

Show current buffers

:ls

Open buffer #2 in this window

:b 2

Create, delete folding

Creation fold

zf

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

zi

Insert mode

Get back to Command mode

esc

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)

cm

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)

n>m

Un-indent n lines (m is movement)

n

Wwitch case

~

Undo, redo

Undo last command, or undo changes on current line

u U

Redo

^r