This pocket reference is a companion to
Learning the vi Editor, by Linda Lamb and
Arnold Robbins.
It describes the vi command-line options,
command mode commands, ex commands and options,
regular expressions and the use of the substitute (s
)
command, and other pertinent information for using vi.
Also covered are the additional features in the
four vi clones,
nvi, elvis,
vim, and vile.
The Solaris 2.6 version of vi served as the “reference” version of vi for this pocket reference.
The following font conventions are used in this book:
Courier
Used for command names, options, and everything to be typed literally
Courier Italic
Used for replaceable text within commands
Used for replaceable text within regular text, program names, filenames, paths, for emphasis, and new terms when first defined
Identifies optional text; the brackets are not typed
Indicates a keystroke
Command | Action |
vi file | Invoke vi on file |
vi file1 file2 | Invoke vi on files sequentially |
view file | Invoke vi on file in read-only mode |
vi -R file | Invoke vi on file in read-only mode |
vi -r file | Recover file and recent edits after a crash |
vi -t tag | Look up tag and start editing at its definition |
vi -w n | Set the window size to n; useful over a slow connection |
vi + file | Open file at last line |
vi + n file | Open file directly at line number n |
vi -c command file | Open file, execute command, which is usually a search command or line number (POSIX) |
vi +/ pattern file | Open file directly at pattern |
ex file | Invoke ex on file |
ex - file < script | Invoke ex on file, taking commands from script; suppress informative messages and prompts |
ex -s file < script | Invoke ex on file, taking commands from script; suppress informative messages and prompts (POSIX) |
Most vi commands follow a general pattern:
[command
][number
]text
object
or the equivalent form:
[number
][command
]text
object
Command | Meaning |
Character | |
h , j ,
k , l | Left, down, up, right (ࢎ, , , →) |
Text | |
w , W ,
b , B | Forward, backward by word |
e , E | End of word |
) , ( | Beginning of next, previous sentence |
} , { | Beginning of next, previous paragraph |
]] , [[ | Beginning of next, previous section |
Lines | |
RETURN | First nonblank character of next line |
0 , $ | First, last position of current line |
^ | First nonblank character of current line |
+ , - | First nonblank character of next, previous line |
n | | Column n of current line |
H | Top line of screen |
M | Middle line of screen |
L | Last line of screen |
n H | n (number) of lines after top line |
n L | n (number) of lines before last line |
Scrolling | |
CTRL-F, CTRL-B | Scroll forward, backward one screen |
CTRL-D, CTRL-U | Scroll down, up one-half screen |
CTRL-E, CTRL-Y | Show one more line at bottom, top of window |
z RETURN | Reposition line with cursor: to top of screen |
z. | Reposition line with cursor: to middle of screen |
z– | Reposition line with cursor: to bottom of screen |
CTRL-L | Redraw screen (without scrolling) |
Searches | |
/ pattern | Search forward for pattern |
? pattern | Search backward for pattern |
n , N | Repeat last search in same, opposite direction |
/ , ? | Repeat previous search forward, backward |
f x | Search forward for character x in current line |
F x | Search backward for character x in current line |
t x | Search forward to character before x in current line |
T x | Search backward to character after x in current line |
; | Repeat previous current-line search |
, | Repeat previous current-line search in opposite direction |
Line number | |
CTRL-G | Display current line number |
n G | Move to line number n |
G | Move to last line in file |
: n | Move to line n in file |
Marking position | |
m x | Mark current position as x |
‘ x | Move cursor to mark x |
‘‘ | Return to previous mark or context |
’ x | Move to beginning of line containing mark x |
’’ | Return to beginning of line containing previous mark |
Command | Action |
Insert | |
i , a | Insert text before, after cursor |
I , A | Insert text before beginning, after end of line |
o , O | Open new line for text below, above cursor |
Change | |
r | Replace character |
cw | Change word |
cc | Change current line |
c motion | Change text between the cursor and the target of motion |
C | Change to end of line |
R | Type over (overwrite) characters |
s | Substitute: delete character and insert new text |
S | Substitute: delete current line and insert new text |
Delete, move | |
x | Delete character under cursor |
X | Delete character before cursor |
dw | Delete word |
dd | Delete current line |
d motion | Delete text between the cursor and the target of motion |
D | Delete to end of line |
p , P | Put deleted text after, before cursor |
" n p | Put text from delete buffer number |
Yank | |
yw | Yank (copy) word |
yy | Yank current line |
" a yy | Yank current line into named buffer a (a–z). Uppercase names append text |
y motion | Yank text between the cursor and the target of motion |
p , P | Put yanked text after, before cursor |
" a P | Put text from buffer a before cursor (a–z) |
Other commands | |
. | Repeat last edit command |
u , U | Undo last edit; restore current line |
J | Join two lines |
ex edit commands | |
:d | Delete lines |
:m | Move lines |
:co or :t | Copy lines |
:.,$d | Delete from current line to end of file |
:30,60m0 | Move lines 30 through 60 to top of file |
:.,/ pattern /co$ | Copy from current line through line containing pattern to end of file |
Command | Meaning |
| Write (save) and quit file |
| Write (save) and quit file |
| Write (save) and quit file |
| Write (save) file |
| Write (save) file, overriding protection |
: | Write from line 30 through line 60 as newfile |
| Write from line 30 through line 60 and append to file |
| Write current buffer named file as file.new |
| Quit file |
| Quit file, overriding protection |
| Quit vi and invoke ex |
| Edit file2 without leaving vi |
| Edit next file |
| Return to version of current file at time of last write (save) |
| Edit alternate file |
| Invoke vi editor from ex |
| Invoke one ex command from vi editor |
| Current filename (substitutes into ex command line) |
| Alternate filename (substitutes into ex command line) |
:ab
abbr phrase
Define abbr as an abbreviation for phrase.
:unab
abbr
Remove definition of abbr.
Be careful with abbreviation texts that either end with the abbreviation name or contain the abbreviation name in the middle.
:map
x sequence
Define character(s) x as a sequence of editing commands.
:unmap
x
Disable the sequence defined for x.
:map
List the characters that are currently mapped.
:map!
x sequence
Define character(s) x as a sequence of editing commands or text that will be recognized in input mode.
:unmap!
x
Disable the sequence defined for the input mode map x.
:map!
List the characters that are currently mapped for interpretation in insert mode.
For both command and input mode maps, the map name x can take several forms:
When you type the character, vi executes the associated sequence of commands.
All the characters must be typed within one second.
The value of notimeout
changes the behavior.
#
n
Function key notation: a #
followed by a digit
n represents the sequence of characters sent
by the terminal’s function key number n.
To enter characters such as Escape (^[
) or
carriage return (^M
), first type a CTRL-V
(^V
).
Named buffers provide yet another way to create “macros”—complex command sequences you can repeat with a few keystrokes. Here’s how it’s done:
Type a vi command sequence or an ex command preceded by a colon; return to command mode.
Delete the text into a named buffer.
Execute the buffer with the @
command
followed by the buffer letter.
The ex command
:@
buf-name
works similarly.
Some versions treat *
identically to
@
when used from the ex command line.
In addition, if the buffer character supplied after the
@
or *
commands
is *
,
the command is taken from the default (unnamed) buffer.
You enable automatic indentation with the command:
:set autoindent
Four special input sequences affect automatic indentation:
^T
Add one level of indentation; typed in insert mode
^D
Remove one level of indentation; typed in insert mode
^ ^D
Shift the cursor back to the beginning of the line, but only for the current line[1]
0 ^D
Shift the cursor back to the beginning of the line and reset the current auto-indent level to zero[2]
Two commands can be used for shifting source code:
<<
Shift a line left eight spaces
>>
Shift a line right eight spaces
The default shift is the value of shiftwidth
,
usually eight spaces.
The general form of the substitute command is:
:[addr1
[,addr2
]]s/old
/new
/[flags
]
Omitting the search pattern
(:s//
replacement
/
)
uses the last search or substitution regular expression.
An empty replacement part
(:s/
pattern
//
) “replaces” the
matched text
with nothing, effectively deleting it from the line.
.
Matches any single character except a newline. Remember that spaces are treated as characters.
*
Matches zero or more (as many as there are) of the single character that immediately precedes it.
The *
can follow a metacharacter, such as
.
or a range in brackets.
^
When used at the start of a regular expression,
^
requires that the following regular
expression be found at the beginning of the line. When not at the
beginning of a regular expression, ^
stands for
itself.
$
When used at the end of a regular expression, $
requires that the preceding regular expression be found at the end
of the line.
When not at the end of a regular expression, $
stands for itself.
Treats the following special character as an ordinary character. (Use to get a literal backslash.)
[ ]
Matches any one of the characters enclosed between the brackets. A range of consecutive characters can be specified by separating the first and last characters in the range with a hyphen.
You can include more than one range inside brackets and specify a mix of ranges and separate characters.
Most metacharacters lose their special meaning inside brackets,
so you don’t need to escape them if you want to use them as
ordinary characters. Within brackets, the three metacharacters
you still need to escape
are
-
]
.
(The hyphen (-
)
acquires meaning as a range specifier; to use an actual hyphen,
you can also place it as the first character inside the
brackets.)
A caret (^
) has special meaning only when it’s the
first character inside the brackets, but in this case, the meaning
differs from that of the normal ^
metacharacter.
As the first character within brackets, a ^
reverses their sense: the brackets
match any one character not in the list. For
example,
[^a-z]
matches any character that’s not a lowercase letter.
( )
Saves the pattern enclosed between (
and )
into a special holding space or “hold buffer.”
Up to nine patterns can be saved in this way on a single line.
You can also use the n
notation within a search or substitute string:
:s/(abcd)1/alphabet-soup/
changes abcdabcd
into
alphabet-soup
.[3]
< >
Matches characters at the beginning (<
) or end
(>
) of a word.
The end or beginning of a
word is determined either by a punctuation mark or by a space.
Unlike (…)
,
these don’t have to be used in matched pairs.
~
Matches whatever regular expression was used in the last search.
POSIX bracket expressions may contain the following:
A POSIX character class consists of keywords bracketed by
[:
and :]
. The
keywords describe different classes of characters such as alphabetic
characters, control characters, and so on (see the following table).
A collating symbol is a multicharacter sequence that should be treated
as a unit. It consists of the characters bracketed by [.
and .]
.
An equivalence class lists a set of characters that should be considered
equivalent, such as e
and
è
.
It consists of a named element from the locale,
bracketed by [=
and =]
.
All three constructs must appear inside the square brackets of a bracket expression.
Class | Matching Characters |
| Alphanumeric characters |
| Alphabetic characters |
| Space and tab characters |
| Control characters |
| Numeric characters |
| Printable and visible (nonspace) characters |
| Lowercase characters |
| Printable characters (includes whitespace) |
| Punctuation characters |
| Whitespace characters |
| Uppercase characters |
| Hexadecimal digits |
n
Is replaced with the text matched by the nth pattern
previously saved by (
and
)
, where
n is a number from 1 to 9, and previously saved patterns
(kept in hold buffers) are counted
from the left on the line.
Treats the following special character as an ordinary character. To specify a real backslash, type two in a row ().
&
Is replaced with the entire text matched by the search pattern when used in a replacement string. This is useful when you want to avoid retyping text.
~
The string found is replaced with the replacement text specified in the last substitute command. This is useful for repeating an edit.
u
or l
Changes the next character in the replacement string to upper- or lowercase, respectively.
U
or L
and e
or E
U
and L
are similar to u
or l
,
but all following characters are
converted to upper- or lowercase until the end of the
replacement string or until e
or E
is reached.
If there is no e
or E
, all characters of the
replacement text are affected by the U
or L
.
You can instruct vi to ignore case by typing
:set
ic
.
A simple :s
is the same as :s//~/
.
:&
is the same as :s
.
You can follow the &
with a g
to make the substitution
globally on the line, and even use it with a line range.
The & key can be used as a vi command
to perform the :&
command, i.e., to repeat the
last substitution.
The :~
command is similar to the :&
command, but with a subtle difference.
The search pattern used is the last regular
expression used in any
command, not necessarily the one used in the last substitute command.
Besides the /
character,
you may use any nonalphanumeric, nonwhitespace
character as your delimiter,
except backslash, double-quote, and the vertical bar
(,
"
,
and |
).
When the edcompatible
option is
enabled, vi remembers the flags
(g
for global and c
for
confirmation) used on the last substitute and applies them
to the next one.
:[address
]command
[options
]
Address | Includes |
| All lines in the file |
| Lines x through y |
| Lines x through y, with current line reset to x |
| Top of file |
| Current line |
| Absolute line number n |
| Last line |
| All lines; same as |
| n lines before x |
| n lines after x |
| One or n lines previous |
| One or n lines ahead |
| Line marked with x |
| Previous mark |
| Ahead or back to line where pat matches |
Full Name | Command |
Abbrev |
|
Append |
[
|
Args |
|
Change | [
|
Copy | [ |
Delete | [ |
Edit |
|
File |
|
Global | [ |
Insert | [
|
Join | [ |
K (mark) | [ |
List | [ |
Map |
|
Mark | [ |
Move | [ |
Next |
|
Number | [ |
Open | [ |
Preserve |
|
[ | |
Put | [ |
Quit |
|
Read | [ |
Read | [ |
Recover |
|
Rewind |
|
Set |
6
|
Shell |
|
Source |
|
Substitute | [ |
T (to) | [ |
Tag | [ |
Unabbreviate |
|
Undo |
|
Unmap |
|
V (global exclude) | [ |
Version |
|
Visual | [ |
Visual |
|
Write | [ |
Write | [ |
Wq (write + quit) |
|
Xit |
|
Yank | [ |
Z (position line) | [ type can be one of:
|
! | [ |
= (line number) | [ |
<> (shift) | [ [ |
Address |
|
Return (next line) | RETURN |
& | [ |
~ | [ |
vi performs the following initialization steps:
If the EXINIT
environment variable exists,
execute the commands it contains.
Separate multiple commands by a pipe symbol (|
).
If EXINIT
doesn’t exist,
look for the file $HOME/.exrc.
If it exists, read and execute it.
If either EXINIT
or $HOME/.exrc
turns on the exrc
option, read and execute
the file ./.exrc, if it exists.
Execute search or goto commands given with
+/
pattern
or
+
n
command-line options (POSIX: –c
option).
The .exrc files are simple scripts of
ex commands; they don’t need a leading
colon.
You can put comments in your scripts by starting a line
with a double quote ("
). This is recommended.
The commands ex -r
or vi -r
list any files you can recover. You then use the command:
$vi -r
file
to recover a particular file.
Even without a crash, you can force the system to preserve your buffer
by using the command :pre
(preserve).
Option | Default |
|
|
|
|
|
|
|
|
| /tmp |
|
|
|
|
|
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
| 5 |
| half window |
|
|
| /bin/sh |
| 8 |
|
|
|
|
| |
| 8 |
| 0 |
| tags /usr/lib/tags |
|
|
| (from |
|
|
|
|
| (from |
|
|
| |
|
|
| 0 |
|
|
The “Exuberant ctags” program was written by Darren Hiebert (home page: http://home.hiwaay.net/~darren/ctags/). As of this writing, the current version is 2.0.3.
This enhanced tags file format has three
tab-separated fields: the tag name (typically an identifier), the
source file containing the tag, and where to find the identifier.
Extended attributes are placed after a separating
;"
. Each attribute is separated from the next
by a tab character and consists of two colon-separated subfields. The
first subfield is a keyword describing the attribute; the second is
the actual value.
Keyword | Meaning |
| The value is a single letter that indicates the lexical type of the tag |
| For static tags, i.e., local to the file |
| For local tags |
| For fields in a |
| For values in an |
| For C++ member functions and variables |
| Intended mostly for C++ class member functions |
| For functions |
If the field doesn’t contain a colon, it’s assumed to be of
type kind
.
Within the value part of each attribute, the backslash, tab, carriage
return, and newline characters should be
encoded as \
,
,
, and
, respectively.
Option | Function |
| Controls the number of significant characters in a tag that is to be looked up; the default value of zero indicates that all characters are significant |
| The value is a list of
filenames in which to look for tags; the default value is |
| When set to |
–c
command
Execute command at startup.
–F
Don’t copy the entire file when starting to edit.
–R
Start in read-only mode, setting the readonly
option.
–S
Run with the secure
option set, disallowing
access to external programs.
–s
Enter batch (script) mode. This is only for ex and is intended for running editing scripts. Prompts and nonerror messages are disabled.
Command | Function |
| Hide the current window |
| Display all buffers, including named, unnamed, and numeric buffers |
| Display the filenames of all backgrounded windows |
| Edit filename in a new window |
| Create a new window editing an empty buffer; /tmp is interpreted especially to create a new temporary file |
| Uncover filename into the current window |
| Uncover filename in a new window; the current window is split |
| Edit the next file in the argument list in a new window |
| Edit the previous file in the argument list in a new window |
| Increase or decrease the size of the current window by nrows rows |
| Edit the file containing tagstring in a new window |
The ^W
command cycles between windows, top to
bottom. The :q
and ZZ
commands
exit the current window.
You may have multiple windows open in the same file. Changes made in one window are reflected in the other.
You use :set extended
to enable
extended regular expression matching:
|
Indicates alternation. The left and right sides don’t need to be single characters.
(…)
Used for grouping, to allow the application of additional regular expression operators.
+
Matches one or more of the preceding regular expressions. This is either a single character or a group of characters enclosed in parentheses.
?
Matches zero or one occurrence of the preceding regular expression.
{…}
Defines an interval expression. Interval expressions describe counted numbers of repetitions. In the following description, n and m represent integer constants:
{
n
}
Matches exactly n repetitions of the previous regular expression.
{
n
,}
Matches n or more repetitions of the previous regular expression.
{
n
,
m
}
Matches n to m repetitions.
When extended
isn’t set, use {
and }
.
When extended
is set,
you should precede the above metacharacters with a backslash in
order to match them literally.
Option | Description |
| The first character of this string, when used on the colon command line, provides access to the command history; hitting RETURN on any given line executes that line |
| The first character of this string, when used on the colon command
line, does shell-style filename expansion; when this character is the
same as for the |
Command | Function |
| Display the tag stack |
| Edit the file containing tagstring as defined in the tags file |
| Just like |
| Pop to the given tag, or to the most recently used tag if no tagloc is supplied |
| Pop to the oldest tag in the stack, clearing the stack in the process |
Option | Default |
| |
| Environment variable |
| |
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
| |
| /var/tmp/vi.recover |
|
|
|
|
|
|
|
|
|
|
| 16 |
| 0 |
| tags /var/db/libc.tags /sys/kern/tags |
|
|
| 0 |
–a
Load each file named on the command line to a separate window.
–R
Start editing each file in read-only mode.
–i
Start editing in input mode instead of in command mode.
–s
Set the safer
option for the whole session, not
just execution of .exrc files.
In elvis 2.1, this option is renamed to
–S
, and
(following the POSIX standard)
–s
provides ex scripting.
–f
filename
Use filename for the session file instead of the default name.
–G
gui
Use the given interface.
–c
command
Execute command at startup (POSIX
version of the historic +
command
syntax).
–V
Output more verbose status information.
–?
Print a summary of the possible options.
Command | Function |
| Create a new window; load it with file if supplied; otherwise, the new window shows the current file |
| Create a new empty buffer and then create a new window to show that buffer |
| |
| Create a new window, showing the next file in the argument list |
| Create a new window, showing the previous file in the argument list |
| Create a new window,
showing the first file in the argument
list; reset the “current” file as the first with
respect to the |
| Create a new window, showing the last file in the argument list |
| Create a new window showing the file where the requested tag is found |
| Create a new window for any files named in the argument list that don’t already have a window |
| With no target, list all windows; the possible values for target are described in the following table |
| Close the current window; the buffer that the window was displaying remains intact |
| Write the buffer back to the file and close the window; the file is saved whether or not it has been modified |
| Issue a |
Command | Function |
| Hide the buffer and close the window |
| Toggle the display mode between “normal” and the buffer’s usual display mode; this is a per-window option |
| Move down to the next window |
| Move up to the previous window |
| Create a new window and a new buffer to be displayed in the window |
| Save the buffer and close the window |
| Split the current window |
| Toggle the
|
| Create a new window, then look up the tag underneath the cursor |
[ | Move to next window, or to the countth window |
| Increase the size of the current window (termcap interface only) |
| Reduce the size of the current window (termcap interface only) |
| Make the current window as large as possible (termcap interface only) |
+
Matches one or more of the preceding regular expressions
?
Matches zero or one of the preceding regular expressions
@
Matches the word under the cursor
=
Indicates where to put the cursor when the text is matched
{…}
Describes an interval expression
POSIX bracket expressions (character classes, etc.) don’t work
in elvis 2.0 (fixed in 2.1),
nor is alternation with the |
character or
grouping with parentheses available.
Key | Effect |
, | Page up and down through the
|
ࢎ, → | Move around on the command line |
Insert characters by typing and erase them by backspacing over them.
The TAB key can be used for filename expansion.
To get a real tab character, precede it with a ^V
.
Disable filename completion entirely by setting the
Elvis ex history
buffer’s
inputtab
option to tab
, via the following command:
:(Elvis ex history)set inputtab=tab
Mode | Display Appearance |
| No formatting; display text as it exists in the file |
| Like |
| An interactive hex dump, reminiscent of mainframe hex dumps; good for editing binary files |
| A simple web page formatter; the tag commands can follow links and return |
| Simple manpage formatter;
like the output of
|
Option | Function |
| The printer type |
| If set, convert Latin-8 extended ASCII to PC-8 extended ASCII |
| The printer needs CR-LF to end each line |
| The file or command to print to |
| The printer’s width |
| Simulate line wrapping |
| The length of the printer’s page |
| Send a formfeed after the last page |
| Size of the paper (letter, A4, etc.); only for PostScript printers |
Name | Printer Type |
| PostScript; one logical page per sheet of paper |
| PostScript; two logical pages per sheet of paper |
| Most dot-matrix printers; no graphic characters supported |
| Panasonic dot-matrix printers |
| Dot-matrix printers with IBM graphic characters |
| Hewlett-Packard printers and most non-PostScript laser printers |
| Line printers; overtyping is done with carriage return |
| Overtyping is done via backspace characters; this setting is the closest to traditional Unix nroff |
| Plain ASCII; no font control |
Option | Default |
|
|
|
|
| (Set automatically) |
| |
|
|
|
|
| |
| |
|
|
| (System dependent) |
|
|
| |
|
|
|
|
| |
| |
| 80 |
|
|
|
|
| 60 |
|
|
| |
|
|
|
|
|
|
| |
| |
| |
|
|
|
|
|
|
| 0 |
| |
| 0 |
| tags |
|
|
| 0 |
| |
|
|
|
|
–c
command
Execute command at startup. (POSIX
version of the historic +
command)
–R
Start in read-only mode, setting the readonly
option.
–s
Enter batch (script) mode. This is only for ex and intended for running editing scripts (POSIX version of the historic “–” argument).
–b
Start in binary mode.
–f
For the GUI version, stay in the foreground.
–g
Start the GUI version of vim, if it has been compiled in.
–o
[N
]Open N windows, if given; otherwise open one window per file.
–i
viminfo
Read the given viminfo file for initialization, instead of the default viminfo file.
–n
Don’t create a swap file: recovery won’t be possible.
–q
filename
Treat filename as the “quick fix” file.
–u
vimrc
Read the given .vimrc file for initialization and skip all other normal initialization steps.
–U
gvimrc
Read the given .gvimrc file for GUI initialization and skip all other normal GUI initialization steps.
–Z
Enter restricted mode (same as having a leading r in the name).
Command | Function |
[ | Split the current window in half |
[ | Create a new window, editing an empty buffer |
[ | Same as |
| Quit the current window (exit if given in the last window) |
| Close the current window; behavior affected by the |
| Close the current window, if it’s not the last one on the screen |
| Make this window the only one on the screen |
| Increase or decrease the current window height by n |
| Set the current window height to n if supplied, otherwise, set it to the largest size possible without hiding the other windows |
| Exit vim |
| Write all changed buffers and exit |
| |
| Write all modified buffers that have filenames |
[ | Split the window and move to the next file in the argument list, or to the Nth file if a count is supplied |
| Split the window and run the
|
Command | Function |
| Same as
|
| |
^W ^S | |
| Same as
|
^W ^N | |
| Perform
|
^W ^^ | |
| Same as the
|
^W ^Q | |
^W c | Same as the
|
| Like the
|
^W ^O | |
| Move cursor to nth window below the current one |
| |
^W ^J | |
| Move cursor to nth window above the current one |
| |
^W ^K | |
| With count, go to nth window; otherwise, move to the window below the current one; if in the bottom window, move to the top one |
^W ^W | |
^W W | With count, go to nth window; otherwise, move to window above the current one; if in the top window, move to the bottom one |
| Move the cursor to the top window |
^W ^T | |
| Move the cursor to the bottom window |
^W ^B | |
| Go to the most recently accessed (previous) window |
^W ^P | |
| Rotate all the windows downwards; the cursor stays in the same window |
^W ^R | |
^W R | Rotate all the windows upwards; the cursor stays in the same window |
| Without count, exchange the current window with the next one; if there is no next window, exchange with the previous window. With count, exchange the current window with the nth window (first window is 1; the cursor is put in the other window) |
^W ^X | |
^W = | Make all windows the same height. |
^W - | Decrease current window height |
^W + | Increase current window height |
| Set the current window size to the value given in a preceding count |
^W ^_ | |
z N RETURN | Set the current window height to N |
| Split the current window; in the new upper window, use the identifier under the cursor as a tag and go to it |
^W ^] | |
| Split the current window and edit the filename under the cursor in the new window |
^W ^F | |
| Open a new window; move the cursor to the first line that matches the keyword under the cursor |
^W ^I | |
| Open a new window, with the cursor on the first macro definition line that contains the keyword under the cursor |
^W ^D |
|
Indicates alternation.
+
Matches one or more of the preceding regular expressions.
=
Matches zero or one of the preceding regular expression.
{
n
,
m
}
Matches n to m of the preceding regular expression, as much as possible. n and m are numbers between 0 and 32,000; vim only requires the left brace to be preceded by a backslash, but not the right brace.
{
n
}
Matches n of the preceding regular expression.
{
n
,}
Matches at least n of the preceding regular expression, as much as possible.
{,
m
}
Matches 0 to m of the preceding regular expression, as much as possible.
{}
Matches 0 or more of the preceding regular expressions, as much as
possible (same as *
).
{-
n
,
m
}
Matches n to m of the preceding regular expression, as few as possible.
{-
n
}
Matches n of the preceding regular expression.
{-
n
,}
Matches at least n of the preceding regular expression, as few as possible.
{-,
m
}
Matches 0 to m of the preceding regular expression, as few as possible.
i
Matches any identifier character, as defined by the isident
option.
I
Like i
, excluding digits.
k
Matches any keyword character, as defined by the iskeyword
option.
K
Like k
, excluding digits.
f
Matches any filename character, as defined by the is-fname
option.
F
Like f
, excluding digits.
p
Matches any printable character, as defined by the isprint
option.
P
Like p
, excluding digits.
s
Matches a whitespace character (exactly space or tab).
S
Matches anything that isn’t a space or a tab.
Backspace.
e
Escape.
Carriage return.
Tab.
Reserved for future use.
~
Matches the last given substitute (i.e., replacement) string.
(…)
Provides grouping for *
, +
,
and =
, as well as making matched subtexts
available in the replacement part of a substitute command
(1
, 2
, etc.).
1
Matches the same string that was matched by
the first subexpression in (
and )
.
2
, 3
and so on may be used
to represent the second, third, and so forth subexpressions.
The
isident
,
iskeyword
,
isfname
, and
isprint
options define the characters that appear in
identifiers, keywords, and filenames, and that are printable,
respectively.
Key | Meaning |
, | Move up (previous), down (more recent) in the history |
ࢎ, → | Move left, right on the recalled line |
INS | Toggle insert/overstrike mode; default is insert mode |
BACKSPACE | Delete characters |
SHIFT or CONTROL combined with ࢎ or → | Move left or right one word at a time |
| Move to the beginning of the command line |
| Move to the end of the command line |
If vim is in vi compatibility mode, ESC acts likes RETURN and executes the command. When vi compatibility is turned off, ESC exits the command line without executing anything.
The wildchar
option contains the character
you type when you want vim to do a completion.
The default value is the tab character.
You can use completion for the following:
Available at the start of the command line
After you’ve typed :tag
When typing a command that takes a filename argument
(see :help suffixes
for details)
When entering a :set
command,
for both option names and their values
Command | Function |
| List the names that match the pattern; for filenames, directories are highlighted |
Value of | (Default: tab) Performs a match, inserting the generated text; hitting TAB successively cycles among all the matches |
| Go to next of multiple |
| Go to previous of multiple |
| Insert all names that match the pattern |
| If there is exactly one match, insert it; otherwise, expand to the longest common prefix of the multiple matches |
Command | Function |
| Edit the file containing tagstring as defined in the tags file |
[ | Jump to the countth newer entry in the tag stack |
[ | Pop a cursor position off the stack, restoring the cursor to its previous position |
| Display the contents of the tag stack |
| List the tags that match tagstring, using the information in the tags file(s) |
| Like |
[ | Jump to the countth next matching tag (default 1) |
[ | Jump to the countth previous matching tag (default 1) |
[ | |
[ | Jump to the first matching tag; with count, jump to the countth matching tag |
| Jump to the last matching tag |
Command | Function | |
| Run make, based on the settings of several options as described in the next table, then go to the location of the first error | |
| Read the error file and jump to the first error | |
| List the errors that include a filename | |
[ | Display the countth next error that includes a filename | |
[ | Display the countth previous error that includes a filename [ | |
| Display error n if supplied; otherwise, display the last error | |
| Display error n if supplied | |
| Displays error n if supplied, otherwise redisplays the current error | |
| Quit with an error code, so that the compiler won’t compile the same file again; intended primarily for the Amiga compiler |
Option | Value | Function |
|
| The shell to execute the command for rebuilding your program |
|
| The program that actually handles the recompilation |
|
| Whatever is needed to cause the shell to save both standard output and standard error from the compilation in the error file |
|
| The name of a file that will
contain the compiler output; the |
|
| A description of what error messages from the compiler look like; this example value is for GCC, the GNU C compiler |
Option | Function |
| Simple-minded indentation; uses that of the previous line |
| Similar to |
| Enables automatic indenting for C programs and is quite smart; C formatting is affected by the rest of the options in this table |
| Input keys that trigger indentation options |
| Tailor your preferred indentation style |
| Keywords that start an extra indentation on the following line |
| A number of single-letter flags that control several behaviors, notably how comments are formatted as you type them |
| Describes different formatting options for different kinds of comments, both those with starting and ending delimiters, as in C, and those that start with a single symbol and go to the end of the line, such as in a Makefile or shell program |
Command | Function |
| Display the first line that contains the keyword under the cursor |
| Display the first line that contains the keyword under the cursor, but starts the search at the current position in the file; this command is most effective when given a count |
| Display all lines that contain the keyword under the cursor; filenames and line numbers are displayed |
| Display all lines that contain the keyword under the cursor, but start from the current position in the file |
| Jump to the first occurrence of the keyword under the cursor |
| Jump to the first occurrence of the keyword under the cursor, but start the search from the current position |
| Open a new window showing the location of the first (or countth) occurrence of the identifier under the cursor |
| |
| Display the first macro definition for the identifier under the cursor |
| Display the first macro definition for the identifier under the cursor, but start the search from the current position |
| Display all macro definitions for the identifier under the cursor; filenames and line numbers are displayed |
| Display all macro definitions for the identifier under the cursor, but start the search from the current positon |
| Jump to the first macro definition for the identifier under the cursor |
| Jump to the first macro definition for the identifier under the cursor, but start the search from the current position |
| Open a new window showing the location of the first (or countth) macro definition of the identifier under the cursor |
|
Command | Function |
[ | Like |
[ | Like |
[ | Like |
[ | Like |
[ | Like |
[ | Like |
[ | Like |
[ | Like |
| List all the included files that couldn’t be
found; with the |
Command | Function |
| Extended to match the |
| Move to the countth
previous unmatched |
| Move to the countth
next unmatched |
| Move to the countth
previous unmatched |
| Move to the countth
next unmatched |
| Move to the countth
previous unmatched |
| Move to the countth
next unmatched |
| Move to the countth
previous unmatched start of a C comment, |
| Move to the countth
next unmatched end of a C comment, |
Option | Default |
|
|
| 0 |
|
|
| .,~/tmp/,~/ |
|
|
|
|
|
|
|
|
| |
|
|
| |
|
|
|
|
|
|
| .,~/tmp,/tmp |
| |
|
|
| (Too long to print) |
|
|
|
|
|
|
| vim default: |
|
|
| |
|
|
|
|
| vim default: 20; vi default: 0 |
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| /tmp/vim##.err |
|
|
| |
|
|
|
|
|
|
|
|
| |
| |
| vim default: |
| 0 |
|
|
|
|
| 0 |
| vim default: |
| ./tags,tags |
|
|
| 1000 |
| |
|
|
–?
vile prints a short usage summary and exits.
–g
N
vile begins editing on the
first file at the specified line number; this can also be given as +
N
.
–s
pattern
In the first file, vile executes an initial
search for the given pattern; this can also be given as +/
pattern
.
–h
Invokes vile on the help file.
–R
Invokes vile in “readonly” mode; no writes are permitted while in this mode.
–v
Invokes vile in “view” mode; no changes are permitted to any buffer while in this mode.
@
cmdfile
vile runs the specified file as its startup file and bypasses any normal startup file.
Command | Key Sequence(s) | Function |
|
| Eliminate all windows except the current one |
|
| Destroy the current window, unless it’s the last one |
edit-file , E , e | ^X e | Bring given
(or under-cursor, for |
| ||
|
| Increase the size of the current window by count |
|
| Move next window down (or buffer up) by count lines |
|
| Move next window up (or buffer down) by count lines |
|
| Scroll window to left by count columns, half screen if count unspecified |
|
| Scroll window to right by count columns, half screen if count unspecified |
|
| Move to the next window |
|
| Reframe with cursor specified
by where,
as follows:
center ( |
|
| Move to the previous window |
| Change the current window to count lines | |
| Return to window saved
with | |
| Mark a window for later return
with | |
|
| Move next window down by count half screens |
|
| Move next window up by count half screens |
|
| Decrease the size of the current window by count lines |
|
| Split the window in half; a count of 1 or 2 chooses which becomes current |
| Bring given file or existing buffer into window; mark it “view-only” | |
|
| Display a list of the first nine
buffers; a digit moves to the given buffer, |
|
| Pop up/down a window showing all the vile buffers |
|
Indicates alternation.
+
Matches one or more of the preceding regular expressions.
?
Matches zero or one of the preceding regular expression.
(…)
Provides grouping for *
, +
,
and ?
, as well as making matched subtexts
available in the replacement part of a substitute command.
s S
Matches whitespace and nonwhitespace characters, respectively.
w W
Matches “word-constituent” characters (alphanumerics and the underscore, ‘_’) and nonword-constituent characters, respectively.
d D
Matches digits and nondigits, respectively.
p P
Matches printable and nonprintable characters, respectively. Whitespace is considered to be printable.
vile allows the escape sequences
,
f
,
,
, and
, to appear in the
replacement part of a substitute command. They stand for
backspace, formfeed, carriage return, tab, and newline, respectively.
Also, from the vile documentation:
Note that vile mimics perl’s handling of
uL1E
instead of vi’s. Given:s/(abc)/uL1E/
, vi will replace withabc
whereas vile and perl will replace withAbc
. This is somewhat more useful for capitalizing words.
vile stores all your ex
commands in a buffer named [History]
.
Options control your access to it and the use of the minibuffer
(the colon command line).
Option | Meaning |
| Log commands from the colon command line
in the |
| The character that
toggles the editing mode in the minibuffer
to use vi motion commands; in Version 8.0, you can also use the |
| Define the highlight attribute to use when the user toggles the
editing mode in the minibuffer. The value should be one of
|
Key | Meaning |
, | Move up (previous), down (more recent) in the history |
ࢎ, → | Move left, right on the recalled line |
BACKSPACE | Delete characters |
The ex command line provides completion of various sorts. Completion applies to built-in and user-defined vile commands, tags, filenames, modes, variables, and to the terminal characters (the character setting such as backspace, suspend, and so on, derived from your stty settings).
Command | Function |
| Edit the file containing tagstring as defined in the tags file |
| Pop a cursor position off the stack, restoring the cursor to its previous position |
| Continue searching through the tags file for more matches |
| Create a new window that displays the tag stack; the display changes as tags are pushed to or popped off the stack |
Command | Function |
| Run command,
saving the output in a buffer
named |
| Find the next error; vile parses the output and moves to the location of each successive error |
The error messages are parsed using regular expressions in the
buffer [Error Expressions]
.
vile creates this buffer automatically and uses it
when you use ^X ^X
.
You can add expressions to it as needed.
You can point the error finder at an arbitrary buffer (not just
the output of shell commands) using
the :error-buffer
command.
This lets you use the error finder on the output of previous
compiler or egrep runs.
Option | Default |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|
|
|
| tags |
|
|
|
|
|
|
|
|
|
|
3.135.221.0