vi Reference


Tags:
                                  
editing commands

h    cursor left
j    cursor right
k    cursor up
l    cursor down
^    beginning of line  
$    end of line
)    next sentence 
(    previous sentence
}    next paragraph
{    previous paragraph 
:$   end of file
w    one character forward
W    one word forward
:10  go to line number (10)
.    repeats text
u    undo last change
U    undo changes to the current line
 

inserting and appending text

i    inserts text to the left of  cursor
I    inserts at the beginning of line 
a    appends text to right of cursor 
A    appends to the end of line
o    add a new line below the current line
O    adds a new line above the current line.


deleting text

x    deletes character
X    deletes text character to left of cursor
10d  deletes line (10)
dd   deletes current line
D    deletes to end of current line
     
replacing text

r    replace character
R    replace until Esc key is entered
cw   replace word
C    replace to end of current line
     

substitute

s    substitute current character
S    substitute line
     

copy and paste

yy    copy current line into buffer
10yy  copy 10 lines from the current line
p     paste the buffer

     
recovering a unsaved file

vi -r  filename  restores unsaved crashed file from buffer

     
searching

:/mytext    search for text (mytext) 
n           continue search forward
N           continue search backward
     

substitution

:1,$s/<search-string>/<replace-string>/g

     
saving

:w    save changes
:wq   save changes and quit
ZZ    save
:q!   quit without saving