December 8, 2004

Vi Commands

Since it has been a while, and I need a place for my permanent memory banks. Enjoy

vi ?R file opens a read only copy
vi +n file opens a file at line n
vi +/pattern file opens a file at the first line matching the pattern
vi tail -200 file opens the last 200 lines of the file.

h moves to the left.
j moves down.
k moves up
l moves right

0 is the first position of the current line
$ is the last position of the current line
H brings you to the top of the screen
M brings you to the middle of the screen
L brings you to the bottom of the screen
G brings you to the last line in the file
:linenumber brings you to that line number

/searchpattern searches forward for the pattern.
?searchpattern searches backwards.
n repeats the search.
N repeats the search in the opposite direction

a appends after cursor.
A appends to the end of the current line.
i inserts before the cursor.
I inserts at the beginning of the line
ESC gets you out of insertion mode.

CTRL-J, RETURN moves down one line.
CTRL-I inserts a tab

cw changes a word
cc changes a line
dd deletes the current line
numberdd deletes how many lines number is equal to 11dd 11 lines gone.
s substitute charater
S substitute entire line
u undo last change
U restore current line
x delete current cursor position
X delete back one character
y copy current line to new buffer
yy copy the current line

ZZ, :x quit and save copy if there are changes
:w write file.
:q quit file
:e filenext edit the next file
:n edit the next file (determined at vi starting)
CTL+G show the current file and line number

I think that?s enough to get me going again when the situation arises.

Posted by Elyse at December 8, 2004 5:31 AM | TrackBack