vi-Kommandos

vi kennt zwei Arbeitsmodi: Kommandomodus (nach dem Start aktiv) und Text-Eingabemodus. Die Kommandos i,a,A,o,O schalten in den Eingabemodus. ESC schaltet in den Kommandomodus.

vi

vi filename create or edit filename
vi -r file  recover an edit session

FILES

:wq  save changes and quit
ZZ  save changes and quit
:q!  quit without saving
:w  save changes and continue editing
:w file save changes to file
:r file read file into current file

CURSOR MOVEMENT

j *down a line
h *left one character
l *right a character
k *up one line

(Gleichwertig mit Pfeiltasten)

w move to the beginning of the

following word

b move to the beginning of the

next word backwards

e move to the end of the following word
0 move to beginning of line
$ move to end of line
H move to beginning of current window
L move to last line of current window

INSERTING TEXT

a append after cursor
A append to end of current line
i insert before cursor
I insert at beginning of current line
o open a new line below the current line
O open a new line above the current line

PAGING THROUGH TEXT

CRTL-b back one screen
CRTL-d down a partial screen
CRTL-f forward one screen
CRTL-u up a partial screen
G  goto end of File
nG  goto line n

SEARCHING THROUGH TEXT

/ text search forward for string
? text search backward for string
n  repeat previous search forward
N  repaet previous search backward

:[start,end]s/text1/text2/ substitute text1 for the text2 for lines start through end;

[start,end] e.g. may be:

1,$ includes all lines in the file

.,$ from current position to the end of the file n,$ from line n to the end of the file % complete file

CHANGING TEXT

x *delete a character
dw *delete a word
dd *delete a line
D delete to end of line
J join current line and the next line
r  replace current character
R replace to end of line
u undo previous command

COPYING AND MOVING

n Y *yank n lines into buffer
yy  *same as Y
yw *yank a word into the buffer
n dd delete n lines, and save them into the buffer
p  put lines from the buffer below cursor
P  put lines from buffer abouve cursor