VI Editor
The commands to move around the file are:
h Move the cursor left one character.
j Move the cursor down one line.
k Move the cursor up one line.
l Move the cursor right one character.
<cursor-arrows>
The cursor arrow keys should work, too.
/text<carriage-return>
Search for the string ``text'' in the file, and move the cursor to
its first character.
The commands to enter new text are:
a Append new text, after the cursor.
i Insert new text, before the cursor.
o Open a new line below the line the cursor is on, and start entering
text.
O Open a new line above the line the cursor is on, and start entering
text.
<escape>
Once you've entered input mode using the one of the a, i, O, or o
commands, use <escape> to quit entering text and return to command
mode.
The commands to copy text are:
yy Copy the line the cursor is on.
p Append the copied line after the line the cursor is on.
The commands to delete text are:
dd Delete the line the cursor is on.
x Delete the character the cursor is on.
The commands to write the file are:
:w<carriage-return>
Write the file back to the file with the name that you originally
used as an argument on the vi command line.
:w file_name<carriage-return>
Write the file back to the file with the name ``file_name''.
The commands to quit editing and exit the editor are:
:q<carriage-return>
Quit editing and leave vi (if you've modified the file, but not
saved your changes, vi will refuse to quit).
:q!<carriage-return>
Quit, discarding any modifications that you may have made.
One final caution. Unusual characters can take up more than one column
on the screen, and long lines can take up more than a single screen line.
The above commands work on ``physical'' characters and lines, i.e. they
affect the entire line no matter how many screen lines it takes up and
the entire character no matter how many screen columns it takes up.
VI COMMANDS
The following section describes the commands available in the command
mode of the vi editor. In each entry below, the tag line is a usage syn-
opsis for the command character.
[count] <control-A>
Search forward count times for the current word.
[count] <control-B>
Page backwards count screens.
[count] <control-D>
Scroll forward count lines.
[count] <control-E>
Scroll forward count lines, leaving the current line and column as
is, if possible.
[count] <control-F>
Page forward count screens.
<control-G>
Display the file information.
<control-H>
[count] h
Move the cursor back count characters in the current line.
[count] <control-J>
[count] <control-N>
[count] j
Move the cursor down count lines without changing the current col-
umn.
<control-L>
<control-R>
Repaint the screen.
[count] <control-M>
[count] +
Move the cursor down count lines to the first nonblank character of
that line.
[count] <control-P>
[count] k
Move the cursor up count lines, without changing the current col-
umn.
<control-T>
Return to the most recent tag context.
<control-U>
Scroll backwards count lines.
<control-W>
Switch to the next lower screen in the window, or, to the first
screen if there are no lower screens in the window.
<control-Y>
Scroll backwards count lines, leaving the current line and column
as is, if possible.
<control-Z>
Suspend the current editor session.
<escape>
Execute ex commands or cancel partial commands.
<control-]>
Push a tag reference onto the tag stack.
<control-^>
Switch to the most recently edited file.
[count] <space>
[count] l
Move the cursor forward count characters without changing the cur-
rent line.
[count] ! motion shell-argument(s)
Replace text with results from a shell command.
[count] # +|-
Increment or decrement the cursor number.
[count] $
Move the cursor to the end of a line.
% Move to the matching character.
& Repeat the previous substitution command on the current line.
'<character>
`<character>
Return to a context marked by the character <character>.
[count] (
Back up count sentences.
[count] )
Move forward count sentences.
[count] ,
Reverse find character count times.
[count] -
Move to first nonblank of the previous line, count times.
[count] .
Repeat the last vi command that modified text.
/RE<carriage-return>
/RE/ [offset]<carriage-return>
?RE<carriage-return>
?RE? [offset]<carriage-return>
N
n Search forward or backward for a regular expression.
0 Move to the first character in the current line.
: Execute an ex command.
[count] ;
Repeat the last character find count times.
[count] < motion
[count] > motion
Shift lines left or right.
@ buffer
Execute a named buffer.
[count] A
Enter input mode, appending the text after the end of the line.
[count] B
Move backwards count bigwords.
[buffer] [count] C
Change text from the current position to the end-of-line.
[buffer] D
Delete text from the current position to the end-of-line.
[count] E
Move forward count end-of-bigwords.
[count] F <character>
Search count times backward through the current line for
<character>.
[count] G
Move to line count, or the last line of the file if count not spec-
ified.
[count] H
Move to the screen line count - 1 lines below the top of the
screen.
[count] I
Enter input mode, inserting the text at the beginning of the line.
[count] J
Join lines.
[count] L
Move to the screen line count - 1 lines above the bottom of the
screen.
M Move to the screen line in the middle of the screen.
[count] O
Enter input mode, appending text in a new line above the current
line.
[buffer] P
Insert text from a buffer.
Q Exit vi (or visual) mode and switch to ex mode.
[count] R
Enter input mode, replacing the characters in the current line.
[buffer] [count] S
Substitute count lines.
[count] T <character>
Search backwards, count times, through the current line for the
character after the specified <character>.
U Restore the current line to its state before the cursor last moved
to it.
[count] W
Move forward count bigwords.
[buffer] [count] X
Delete count characters before the cursor.
[buffer] [count] Y
Copy (or ``yank'') count lines into the specified buffer.
ZZ Write the file and exit vi.
[count] [[
Back up count section boundaries.
[count] ]]
Move forward count section boundaries.
^ Move to first nonblank character on the current line.
[count] _
Move down count - 1 lines, to the first nonblank character.
[count] a
Enter input mode, appending the text after the cursor.
[count] b
Move backwards count words.
[buffer] [count] c motion
Change a region of text.
[buffer] [count] d motion
Delete a region of text.
[count] e
Move forward count end-of-words.
[count] f<character>
Search forward, count times, through the rest of the current line
for <character>.
[count] i
Enter input mode, inserting the text before the cursor.
m <character>
Save the current context (line and column) as <character>.
[count] o
Enter input mode, appending text in a new line under the current
line.
[buffer] p
Append text from a buffer.
[count] r <character>
Replace count characters.
[buffer] [count] s
Substitute count characters in the current line starting with the
current character.
[count] t <character>
Search forward, count times, through the current line for the char-
acter immediately before <character>.
u Undo the last change made to the file.
[count] w
Move forward count words.
[buffer] [count] x
Delete count characters.
[buffer] [count] y motion
Copy (or ``yank'') a text region specified by the count and motion
into a buffer.
[count1] z [count2] -|.|+|^|<carriage-return>
Redraw, optionally repositioning and resizing the screen.
[count] {
Move backward count paragraphs.
[count] |
Move to a specific column position on the current line.
[count] }
Move forward count paragraphs.
[count] ~
Reverse the case of the next count character(s).
[count] ~ motion
Reverse the case of the characters in a text region specified by
the count and motion.
<interrupt>
Interrupt the current operation.
VI TEXT INPUT COMMANDS
The following section describes the commands available in the text input
mode of the vi editor.
<nul>
Replay the previous input.
<control-D>
Erase the previous autoindent character.
^<control-D>
Erase all of the autoindent characters, and reset the autoindent
level.
0<control-D>
Erase all of the autoindent characters.
<control-T>
Insert sufficient <tab> and <space> characters to move the cursor
forward to a column immediately after the next column which is an
even multiple of the shiftwidth option.
<erase>
<control-H>
Erase the last character.
<literal next>
Quote the next character.
<escape>
Resolve all text input into the file, and return to command mode.
<line erase>
Erase the current line.
<control-W>
<word erase>
Erase the last word. The definition of word is dependent on the
altwerase and ttywerase options.
<control-X>[0-9A-Fa-f]*
Insert a character with the specified hexadecimal value into the
text.
<interrupt>
Interrupt text input mode, returning to command mode.