Tuesday, October 17, 2006

A Quick and Dirty Tutorial on VI Editor


i (insert before cursor)
a (insert after cursor)
A (insert at the end of the line)
o (open new line below cursor)
O (open new line above cursor)


Return (moves to beginning of line)
x (deletes single character), 3x (deletes three characters), ...nx (deletes n characters)
dd (deletes single line), 5dd (deletes 5 lines), ...ndd (deletes n lines)
d^ (deletes to beginning of line)
d$ (deletes to end of line)
D (deletes to end of line)
J (joins current line with next line)
dG (deletes to end of file)
yy (copies single line), 5yy (copies 5 lines), ...nyy (copies n lines)
y$ (copies from cursor to end of line)
p (pastes lines)
dw (deletes single word)
cw (changes single word)
r (replaces single character)
n (repeat previous search)
N (reverse previous search)
. (repeats previous command)
u (undo last command)
U (undo a line of changes)
G (go to last line)
1G (go to start line)
7G (moves to seventh line)
0 (zero goes to start line)
^ (go to beginning of line)
$ (go to end of line)
w (moves to word)
W (moves to next space delimited word)
b (moves back a word)
B (moves back a space delimited word)
~ (transpose a case)
control+f (moves forward a screen)
control+b (moves back a screen)
control+u (moves up half a screen)
control+d (moves down half a screen)

/PATTERN_TO_MATCH (move forward to pattern)
?PATTERN_TO_MATCH (move backward to pattern)

:1,5d (delete lines 1-5)
:1,5m 10 (move lines 1-5 to 10)
:1,5t 10 (copy lines 1-5 to 10)

Access Unix commands

Replaces topbloglist to topbloglists
:13,25:/topbloglist/topbloglists/ (replaces lines 13-25)
:1,$:s/topbloglist/topblogists/g (global replace)

:set list (displays non-printable characters)
:set nu (set line numbers)
:set ts=number (sets tab stops)
:set all (show all settings)
:set wm=5 (wrap lines 5 from right margin)

*Use keyboard arrows to move (1 character left/right OR 1 line up or down) around or <- h, j - down, k - up, l ->

To save and exit vi:
:w filename
:w (if filename was provided when vi was invoked)
:w >> filename (append to existing file)
:q! (quit without saving)
:wq! (quit and save--overrides write permissions)
:ZZ (quit and save--does not override write permissions)

vi filename
(now press ESC)


Martin said...

Hi Roy, thanks for stopping by my blog and leaving your comment, I will check out the site you mentioned. I hope all goes well for you too.


esofthub said...

Thanks Martin. I'm curious where your endeavors carries you. You have an interesting site.