Sunday, March 29, 2009

Learning Vim - Basic movement

[left, right, up, down] - h, l, k, j
e.g., 9j, 5l
e.g.,
move between windows: CTRL-W H, CTRL-W L, CTRL-W K, CTRL-W J


[PageUP, PageDown] - CTRL-B, CTRL-F
e.g., 3CTRL-B, 5CTRL-F


[Move to line] - gg, G, :n, n%, CTRL-G
Show line number: :set nu
Go to the first line: gg
Go to the last line: G
Go to line n: nG, :n
Go to n% of all: n%
Show current position: CTRL-G
e.g., gg, G, 5G, :5, 20%, CTRL-G


[Move to specified char in line] - 0, $, ^, f, t, F, T
Go to the first char: 0, ^
Go to the last char: $
Find char x in right: fx, tx
Find char x in left: Fx, Tx
Repeat backward find: ;
Repeat forward find: ,
e.g., 0, $, fw, 3fp, 5tu, ;;


[Move to word] - w, b, e, ge, W, B, E, gE
Words forward, backward: w, b
forward, backward to the end of word: e, ge
e.g., 2w, 3b, 4ge


[Move/Scroll in screen]
- H, M, L, zt, zz, zb
Move to screen Head/Middle/Last line: H, M, L
Scroll current line to screen Head/Middle/Bottom: zt, zz, zb
e.g.: M, zz


[Find & Move] - /, ?, n, N, CTRL-P, CTRL-N, q/, q?
Find related setting: :set incsearch/noincsearch or :set is/nois
:set hlsearch/nohlsearch or :set hls/nohls
:set ignorecase and set :set smartcase
Forward, backward find sth: /sth, ?sth
Repeat forward, backward find: n, N
Forward, backup find history: /CTRL-P, /CTRL-N
Modify find history: q/, q?
e.g., /Leeon, ?Leeon, /CTRL-P, q/