Wednesday, January 27, 2010

vi commands

I can never remember them all. here's a vi cheat sheet I found to help me remember them. :D

Window motions
<ctrl>d -- Scroll down (half a screen)
<ctrl>-- Scroll up (half a screen)
<ctrl>f -- Page forward
<ctrl>b -- Page backward
/string -- Search forward
?string -- Search backward
n -- Repeat search
N -- Repeat search reverse
G -- Go to last line
nG -- Go to line n :n -- Go to line n
<ctrl>l -- Redraw screen
<ctrl>g -- File information

--------------------------------------------------------------------------------

Cursor motions

H -- Upper left corner (home)
M -- Middle line
L -- Lower left corner
h -- Back a character
j -- Down a line
k -- Up a line
^ -- Beginning of line
$ -- End of line
l -- Forward a character
w -- Forward one word
b -- Back one word
fc -- Find c
; -- Repeat find (find next c)

--------------------------------------------------------------------------------

Input commands (end with ESC)
a -- Append after cursor
i -- Insert before cursor
o -- Open line below
O -- Open line above
:r file -- Insert file after current line

--------------------------------------------------------------------------------

Changes during insert mode

<ctrl>h -- Back one character
<ctrl>w -- Back one word
<crtl>u -- Back to beginning of insert

--------------------------------------------------------------------------------

Move text from file old to file new

vi old "a10yy -- Yank 10 lines to buffer a
:w -- Write work buffer
:enew -- Edit new file
"ap -- Put text from a after cursor

--------------------------------------------------------------------------------

Delete Commands

dd -- Delete line
ndd -- Delete n lines to general buffer
dw -- Delete word to general buffer
ndw -- Delete n words
d) -- Delete to end of sentence
db -- Delete previous word
D -- Delete to end of line
x -- Delete character

--------------------------------------------------------------------------------

Recovering deletions

p -- Put general buffer after cursor
P -- Put general buffer before cursor

--------------------------------------------------------------------------------

Change Commands

s -- Substitute (ESC) - 1 char with string
cw -- Change word (ESC)
cc -- Change line (ESC) - blanks line
c$ -- Change to end of line
rc -- Replace character with c
R -- Replace (ESC) - typeover
. -- Repeat last change

--------------------------------------------------------------------------------

Undo Commands

u -- Undo last change
U -- Undo all changes on line

--------------------------------------------------------------------------------

Rearrangement Commands

yy or Y -- Yank (copy) line to general buffer
"z6yy -- Yank 6 lines to buffer z
yw -- Yank word to general buffer
"a9dd -- Delete 9 lines to buffer a
"A9dd -- Delete 9 lines; append to buffer a
"ap -- Put text from buffer a after cursor
p -- Put general buffer after cursor
P -- Put general buffer before cursor
J -- Join lines

--------------------------------------------------------------------------------

File management commands

:w name -- Write edit buffer to file name
:wq -- Write to file and quit
:q! -- Quit without saving changes
ZZ -- Same as :wq
:sh -- Execute shell commands (<ctrl>d)

--------------------------------------------------------------------------------

Parameters

:set list -- Show invisible characters
:set nolist -- Don't show invisible characters
:set number -- Show line numbers
:set nonumber -- Don't show line numbers

No comments:

Post a Comment