vi Editor Quick Reference


Overview

Conventions

vi Quick Reference table


Overview

vi is a somewhat arcane editor that is shipped with most variants of Unix. It has been around for a long time, and therefore retains some aspects of a line-based editor. vi is a screen-based editor, but functions in two modes: command-based and edit-based. In command mode, you can move the cursor, issue editing commands (see the table below), and exit the editor. In edit-based mode, you can type text and move around within the text you just entered. vi is a difficult editor to learn, but it is available on almost every Unix platform you may encounter. For an interactive tutorial, type VILEARN (upper case is necessary) at the sunny unix prompt.

Conventions

Using the vi editor is easier if you first understand some of the conventions used to enter and exit the command and editing modes. When you start up vi, you are in command mode. To enter editing mode, you must use one of the editing-mode keys, such as i for insert, a for append, or o for a line insert. More on these commands can be found in the table below. In command mode, the arrow keys will usually let you navigate around the document. The h j k l keys can be used in place of the arrow keys for moving left, up, down or right respectively.

Most editing commands can be modified to perform the desired action a multiple number of times by preceding the command with a number. For example, 8x will delete 8 characters rather than have to press x 8 times.

vi Quick Reference Table

vi Quick Reference
Desired FunctionCommand
General Commands
Start the vi editor (at the $ prompt)vi [filename]
Write the editor contents to a file:w [filename]
Save the file and exit viZZ or :wq
Exit vi without saving changes:q!
Escape to the unix shell $ prompt!/bin/sh then exit at the $ prompt to return to the editor
Moving around in your file
Move the cursor left, up, down or righth j k l or the arrow keys
Move to the beginning of the file1G
Move to the end of the fileG
Move to the beginning of the next wordw
Move to the beginning of the previous wordb
Move to the end of the current worde
Move cursor to the end of the line$
Move to beginning of next line[Return]
Scroll down one screen[Ctrl] f
Scroll up one screen[Ctrl] b
Searching for text in your file
Find [pattern]/[pattern]/
Find next occurence of [pattern]/
Find prev occurence of [pattern]?
Cutting, pasting and deleting text
Delete a character at current cursor positionx
Delete a character after current cursor positionX
Paste a character at current cursor positionp
Paste a character after current cursor positionP
Enter insert mode at current cursor positioni enter text [Esc]
Enter insert mode after current cursor positiona enter text [Esc]
Replace character at current cursor positionr replacement character
Replace multiple characters at current cursor positionR replacement text [Esc]
Delete a line of textdd
Paste textp
Copy a line of textyy
Append another file at current cursor position:r [filename]
Append next line of text to current line of textJ

viqref