Monday, February 2, 2009

Useful VIM commands

>>> Edit configuration file: /etc/vim/vimrc

//searh foo and replace with bar (% is meaning all lines)
:%s/foo/bar/

//search for the next instance of foo
/foo

//undo
:u

//go to first/last line
gg / [shift]+g

//go to 8th line
8 [shift]+g

//copy whole line
yy / :ny "n:line number

//copy from current position to the end of file
:y$

//copy 3 lines after current position
3yy

//copy range of lines
:1,5y

//delete whole line
dd / nd "n: line number

//delete from current position to the end of file
d$

//delete ange of lines
:1,5d

//word completion on i-mode
[ctrl]+n

//copy a region of text in i-mode
v {move cursor} y

//cut a region of text in i-mode
v {move cursor} x

//paste -before the cursor
P

//paste -after the cursor
p

//paste -after the cursor
p

//correct indentation
1) :set filetype=xml
2) :filetype indent on
3) :e
4) gg=G

0 comments: