Vi Commands

(For a complete listing of VI commands consult a book, this page is just the tip of the iceberg!)

Vi is freely available to download for almost every type of PC at www.VIM.org
The LINUX/UNIX files needed are "common" (for any type of VI), "minimal" (for command line), "X11" for GUIs like GNOME and KDE.

Back to Linux Commands    Back to Mainpage


OPERATE (enter/exit commands)

Enter Vi type vi FILENAME
Exit without saving type :q
Exit ignoring and changes made :qa!
Exit and save :wq
Save your text to a file by typing :w FILENAME.
Save saves the lines # through # in file:#,# FILENAME.
Insert a file into the current file :r FILENAME.

NAVIGATE

Move the cursor in a file h (left); j (down); k (up); L (right)
Move forward, backward by word w,W
Move end of a word e, E
Move forward, backward by sentence ),(
Move forward, backward by paragraph },{
Move forward, backward by section ]],[[
Move forward, backward by screen CTRL+F, CTRL+B
Move forward, backward by half screen CTRL+D, CTRL+Y
Move to the end of the file G
Move to a line number in a file (line number) G
Move to a line number in a file :(line #)
Display your line number location in the file Ctrl-g
Search FORWARD for a word or phrase /(word)
Search BACKWARD for a word or phrase ?
Search After a search to find the next occurrence in the same direction n
Search to find the next occurance in the opposite direction.Shift-N

Typing % while the cursor is on a (,),[,],{, or } locates its matching pair.

EDIT

Insert text at the cursor while in Normal mode i then type in text.
o (Lowercase o) opens a line BELOW the cursor and places the cursor on the open line in Insert mode.
O (Captial O) opens the line ABOVE the line the cursor is on.
a to insert text AFTER the character the cursor is on.
A automatically appends text to the end of the line.
R enters Replace mode until ESC is pressed to exit.
:set xxx sets the option "xxx"
Change from the cursor to the end of the word cw
Change to the end of a line c$
Change format is:[number] c object OR c [number] object.
Delete a character under the cursor in Normal mode type x
Delete from the cursor to the end of a word type dw
Delete from the cursor to the end of a line type d$
Delete a whole line type dd
Execute an external command :! for example :!dir - shows a directory listing.
Replace deleted text p which puts the deleted text AFTER the cursor.
Replace the character under the cursor r and then the character which will replace the original.
Substitute a new word for the first old on a line type  :s/old/new
Substitute new for all 'old's on a line type              :s/old/new/g
Substitute phrases between two line #'s type      #,#s/old/new/g
Substitute all occurrences in the file type          :%s/old/new/g
Substitute with confirmation each time            :%s/old/new/gc
Undo previous actions, type u (lowercase u)
Undo all the changes on a line type U (capital U)
Undo the undo's type CTRL-R

EXPLANATIONS

Normal mode format for a command is: [number] command object OR command [number] object where:

Help from within Vi:

1