This site will look much better in a browser that supports web standards, but it is accessible to any browser or Internet device.

VI commands »

Contents


Getting Started with the Vi Editor

Vi is a screen oriented text editor. It has 2 different modes: command and insert.

Insert mode is entered using a number of different commands, but i and a are the most common. Once in insert mode, you just type away entering new text. If you make a mistake, just use the delete key (Backspace on some keyboards) to rub out. To do anything other than insert text you must get out of insert mode by pressing the escape key. If you are unsure which mode you are in, just press the escape key and you will be back in command mode.

In command mode, you can move around in the file, delete text, search for key words, cut and paste, etc. A list of important commands is below. More information on vi is available by typing man vi

To start vi, type vi filename and the file will be displayed on your screen. Use the arrow keys to move around in the file.

  To Do This Type This
Insert and Insert text before the cursor
i
replace Append text after the cursor
a
  Open a new line below current line
o
  Replace char under cursor with x
rx
  Change wordc
cw
  Get out of insert mode
[escape]
Save Save file and continue editing
:w
Delete Delete current line
dd
  Delete word
dw
  Delete character
x
  Delete rest of line
D
Moving Move forward one word
w
around Move backward one word
b
  Move to end of line
$
  Scroll down half screen
[ctrl]d
  Scroll up one half screen
[ctrl]u
  Jump to end of file
G
  Exiting without saving changes
:q!
Other Undo last change
u
  Search for word
/word
  Find next use of word
n
  Join lines
J


Additional Resources

UNIX 101: vi Editor
vi Command Reference
Mastering the VI editor