vi(1)
Name
vi − screen editor
Syntax
vi [ −t tag ] [ +command ] [ −l ] [ −r ] [ −wn ] [ −x ] name...
Description
The vi (visual) editor is a display-oriented text editor based on ex(.). The ex command and the vi command run the same code. You can access the command mode of ex from within vi.
The following is a list of some of the vi commands. See the Vi Beginner’s Reference card and the Introduction to Display Editing with Vi for more details on using vi.
Screen Control Commands
<CTRL/L>Reprints current screen.
<CTRL/Y>Exposes one more line at top of screen.
<CTRL/E>Exposes one more line at bottom of screen.
Paging Commands
<CTRL/F>Pages forward one screen.
<CTRL/B>Pages back one screen.
<CTRL/D>Pages down half screen.
<CTRL/U>Pages up half screen.
Cursor Positioning Commands
jMoves cursor down one line, same column.
kMoves cursor up one line, same column.
hMoves cursor back one character.
lMoves cursor forward one character.
<RETURN>Moves cursor to beginning of next line.
0Moves cursor to beginning of current line.
$Moves cursor to end of current line.
<SPACE>Moves cursor forward one character.
nG Moves cursor to beginning of line n. Default is last line of file.
/pattern Moves cursor forward to next occurrence of pattern.
nRepeats last / or ? pattern search.
Text Insertion Commands
aAppends text after cursor. Terminated by <ESC>.
iInserts text before cursor. Terminated by <ESC>.
oOpens new line below current line for text insertion. Terminated by <ESC>.
<DELETE>Overwrites last character during text insertion.
<ESC>Stops text insertion.
Text Deletion Commands
dwDeletes current word.
xDeletes current character.
ddDeletes current line.
DDeletes from cursor to end of line.
PPuts back text from the previous delete.
Text Change Commands
cwChanges characters of current word until stopped with escape key.
c$Changes text up to the end of the line.
CChanges remaining text on current line until stopped by pressing the escape key.
~Changes case of current character.
xpTransposes current and following characters.
JJoins current line with next line.
rx Replaces current character with x.
Buffer Usage Commands
a−zn yy Yanks n lines to the a−z buffer. Default is current line.
a−zn p Puts n yanked text lines from the a−z buffer, after the cursor.
Exiting vi
ZZExits vi and saves changes
:wqWrites changes to current file and quits edit session.
:qQuits edit session (no changes made).
The view command uses all of the same edit or commands as vi. However, view does not allow you to write the file. See view(.).
Options
−t tag Specifies a list of tag files. The tag files are preceded by a backslash (\) and are separated by spaces. The tag option should always be the first entry.
+command
Tells the editor to begin by executing the specified command. A useful example would be +/pattern to search for a pattern.
−lSets the showmatch and lisp options for editing LISP code.
−r name Retrieves the last saved version of the name’d file in the event of an editor or system crash. If no file is specified, a list of saved files is produced.
−wn Sets the default window size to n. This option is useful for starting in a small window on dialups.
Note
The −x option is available only if the Encryption layered product is installed.
−xCauses vi to prompt for a key. The key is used to encrypt and decrypt the contents of the file. If the file contents have been encrypted with one key, you must use the same key to decrypt the file.
Restrictions
Software tabs using ^T work only immediately after the autoindent.
Left and right shifts on intelligent terminals do not make use of insert and delete character operations in the terminal.
The wrapmargin option sometimes works incorrectly because it looks at output columns when blanks are typed. If a long word passes through the margin and onto the next line without a break, then the line is not broken.
Insert/delete within a line can be slow if tabs are present on intelligent terminals, since the terminals need help in doing this correctly.
Saving text on deletes in the named buffers is somewhat inefficient.
The source command does not work when executed as :source; there is no way to use the :append, :change, and :insert commands, since it is not possible to give on a :global you must Q to ex command mode, execute them, and then reenter the screen editor with vi or open.
See Also
ed(1), ex(1), view(1)
“An Introduction to Display Editing with Vi”, ULTRIX Supplementary Documents, Vol. I: General User