vi basics

To use the insert mode, type:

Now you can enter text and use Backspace to overwrite previously entered characters. For moving around and other operations you must first change to command mode.

To get into command mode press Esc. Press Return after all commands starting with :, /, ?. Use Ctrl-c to abort a command.

File commands
Quit :q if file is saved
:wq save & quit
:q! quit without saving
Save :w
Save As :w file
Open :e file if current file is saved
:e! file without saving current file
Insert File :r file below current line
Edit commands
Undo u last change
U changes in current line
Mark Beginning of Block mx set mark x (x may be any letter)
Mark End of Block and ``Copy'' y`x yank from here to mark x into buffer
Mark End of Block and ``Cut'' d`x delete from here to mark x into buffer
``Paste'' * P put buffer before cursor
p put buffer after cursor
Delete Character x
Delete Line dd
Join Line with Next Line J
Search commands
Search Forward /string
Search Backward ?string
Repeat Last Search n
Replace, query each :,$s/string1/string2/gc enter y Return or Return
Replace all :,$s/string1/string2/g
Navigation commands
Left, Right, Up, Down h , l , k , j arrow keys may also work
1 Screen Forward, Backward Ctrl-f , Ctrl-b
Beginning, End of File 1G , G
Beginning, End of Line 0 , $
Go to Line number :number or number G

A note about P, p

With P, p you can paste the text from the last delete operation with d`x or dd. If you want to use dd without losing a previously saved block, then you have to use a named buffer (any letter can be used for z):
Mark Beginning of Block mx set mark x
Mark End of Block and ``Copy'' "zy`x yank from here to mark x into buffer z
Mark End of Block and ``Cut'' "zd`x delete from here to mark x into buffer z
``Paste'' "zP put buffer z before cursor
"zp put buffer z after cursor


Eric's Tips:

delete 123 lines at once: d123d


More information: vi Tutorial, vi Reference


This page is based on html by Tobias von Petersdorff.

Back to Resources