This excerpt is from Learning the vi and Vim Editors, Seventh Edition.
The standard guide for vi since 1986, this book has been expanded to include detailed information on vim, the leading vi clone that includes extra features for both beginners and power users. You learn text editing basics and advanced tools for both editors, such as writing macros and scripts to extend the editor, power tools for programmers, multi-window editing -- all in the easy-to-follow style that has made this book a classic.
This appendix summarizes the standard features of vi in quick-reference format. Commands entered at the colon (known as ex commands because they date back to the original creation of that editor) are included, as well as the most popular Vim features.
This appendix presents the following topics:
Command-line syntax
Review of vi operations
Alphabetical list of keys in command mode
vi commands
vi configuration
ex basics
Alphabetical summary of ex commands
The three most common ways of starting a vi session are:
vi [options]filevi [options] +num filevi [options] +/pattern file
You can open file for editing, optionally at line num or at the first line matching pattern. If no file is specified, vi opens with an empty buffer.
Because vi and ex are the same program, they share the same options. However, some options only make sense for one version of the program. Options specific to Vim are so marked:
+[
num
]
Start editing at line number num, or the last line of the file if num is omitted.
+/
pattern
Start editing at the first line matching
pattern. (For ex, this fails if nowrapscan is set in your .exrc startup file, since ex starts editing at the last line of a
file.)
+?
pattern
-b
-c
command
Run the given ex command
upon startup. Only one -c option is
permitted for vi; Vim accepts
up to 10. An older form of this option, +command, is
still supported.
--cmd
command
Like -c, but execute the command before any resource files are read.
{Vim}
-C
Solaris vi: same
as -x, but assume the file is
encrypted already.
Vim: start the editor in vi-compatible mode.
-d
-D
-e
-h
-i
file
Use the specified file instead of
the default (~/.viminfo) to
save or restore Vim’s state. {Vim}
-l
Enter Lisp mode for running Lisp programs (not supported in all versions).
-L
List files that were saved due to an aborted editor session or
system crash (not supported in all versions). For Vim, this option
is the same as -r.
-m
Start the editor with the write option turned off so that the user
cannot write to files. {Vim}
-M
-n
Do not use a swap file; record changes in memory only. {Vim}
--noplugin
-N
-o[num]Start Vim with num open windows. The default is to open one window for each file. {Vim}
-O[num]Start Vim with num open windows arranged horizontally (split vertically) on the screen. {Vim}
-r
[file]Recovery mode; recover and resume editing on file after an aborted editor session or system crash. Without file, list files available for recovery.
-R
-s
Silent; do not display prompts. Useful when running a
script. This behavior also can be set through the older
- option. For Vim, applies only when used
together with -e.
-s
scriptfile
Read and execute commands given in the specified scriptfile as if they were typed in from the keyboard. {Vim}
-S
commandfile
Read and execute commands given in
commandfile after loading any files for
editing specified on the command line. Shorthand for vim -c 'source
commandfile'. {Vim}
-t
tag
Edit the file containing tag, and position the cursor at its definition.
-T
type
Set the option terminal type. This value overrides the $TERM environment variable. {Vim}
-u
file
Read configuration information from the specified
resource file instead of the default .vimrc resource file. If the
file argument is NONE, Vim will read no resource files,
load no plug-ins, and run in compatible mode. If the argument is
NORC, it will read no resource
files, but it will load plug-ins. {Vim}
-v
--version
-V[num]Verbose mode; print messages about what options are being set and what files are being read or written. You can set a level of verbosity to increase or decrease the number of messages received. The default value is 10 for high verbosity. {Vim}
-w
rows
Set the window size so rows lines at a time are displayed; useful when editing over a slow dial-up line (or long distance Internet connection). Older versions of vi do not permit a space between the option and its argument. Vim does not support this option.
-W
scriptfile
Write all typed commands from the current session to the specified
scriptfile. The file created can be used with
the -s command. {Vim}
-x
Prompt for a key that will be used to try to encrypt or decrypt a file using crypt (not supported in all versions).[74]
-y
Modeless vi; run Vim in insert mode only, without a command mode. This is the same as invoking Vim as evim. {Vim}
-Z
Start Vim in restricted mode. Do not allow shell commands or suspension of the editor. {Vim}
Although most people know ex
commands only by their use within vi,
the editor also exists as a separate program and can be invoked from the
shell (for instance, to edit files as part of a script). Within ex, you can enter the vi or visual command to start vi. Similarly, within vi, you can enter Q to quit the vi editor and enter ex.
You can exit ex in several ways:
This section provides a review of the following:
vi modes
Syntax of vi commands
Status-line commands
Once the file is opened, you are in command mode. From command mode, you can:
Invoke insert mode
Issue editing commands
Move the cursor to a different position in the file
Invoke ex commands
Invoke a Unix shell
Save the current version of the file
Exit vi
In insert mode, you can enter new text in the file. You normally enter insert
mode with the i command. Press the
ESC key to exit insert mode and return to command mode.
The full list of commands that enter insert mode is provided later in
the section the section called “Insert Commands”.
In vi, editing commands have the following general form:
[n]operator[m]motion
The basic editing operators are:
|
|
Begin a change. |
|
|
Begin a deletion. |
|
|
Begin a yank (or copy). |
If the current line is the object of the operation, the
motion is the same as the operator: cc, dd,
yy. Otherwise, the editing operators
act on objects specified by cursor-movement commands or pattern-matching
commands. (For example, cf. changes
up to the next period.) n and
m are the number of times the operation is
performed, or the number of objects the operation is performed on. If
both n and m are specified,
the effect is n ×
m.
An object of operation can be any of the following text blocks:
Includes characters up to a whitespace character (space or tab) or punctuation mark. A capitalized object is a variant form that recognizes only whitespace.
Up to ., !, or ?, followed by two spaces.
Up to the next blank line or paragraph macro defined by the
para= option.
Up to the next nroff/troff section heading defined by the
sect= option.
Up to the character or other text object as specified by a motion specifier, including pattern searches.
|
|
Change the next two words. |
|
|
Delete up to the next paragraph. |
|
|
Delete back to the beginning of the line. |
|
|
Copy the next five lines. |
|
|
Copy up to the next section. |
|
|
Change to the end of the edit buffer. |
More commands and examples may be found in the section the section called “Changing and deleting text” later in this appendix.
Vim provides an additional facility, “visual mode.” This allows you to highlight blocks of text, which then become the object of edit commands such as deletion or saving (yanking). Graphical versions of Vim allow you to use the mouse to highlight text in a similar fashion. See the earlier section the section called “Visual Mode Motion” for more information.
|
|
Select text in visual mode one character at a time. |
|
|
Select text in visual mode one line at a time. |
|
CTRL-V |
Select text in visual mode in blocks. |
Most commands are not echoed on the screen as you input them. However, the status line at the bottom of the screen is used to edit these commands:
|
|
Search forward for a pattern. |
|
|
Search backward for a pattern. |
|
|
Invoke an ex command. |
|
|
Invoke a Unix command that takes as
its input an object in the buffer and replaces it with output
from the command. You type a motion command after the |
Commands that are entered on the status line must be entered by pressing the ENTER key. In addition, error messages and output from the CTRL-G command are displayed on the status line.
vi supplies a large set of single-key commands when in command mode. Vim supplies additional multikey commands.
Some versions of vi do not recognize extended keyboard keys (e.g., arrow keys, page up, page down, home, insert, and delete); some do. All versions, however, recognize the keys in this section. Many users of vi prefer to use these keys, as it helps them keep their fingers on the home row of the keyboard. A number preceding a command repeats the movement. Movement commands are also used after an operator. The operator works on the text that is moved.
|
|
Forward, backward by “word” (letters, numbers, and underscores make up words). |
|
|
Forward, backward by “WORD” (only whitespace separates items). |
|
|
End of word. |
|
|
End of WORD. |
|
|
End of previous word. {Vim} |
|
|
End of previous WORD. {Vim} |
|
|
Beginning of next, current sentence. |
|
|
Beginning of next, current paragraph. |
|
|
Beginning of next, current section. |
|
|
End of next, current section. {Vim} |
Long lines in a file may show up on the screen as multiple
lines. (They wrap around from one screen line
to the next.) Although most commands work on the lines as defined in the file, a few commands work
on lines as they appear on the screen. The Vim option wrap allows you to control how long lines
are displayed.
|
|
First, last position of current line. |
|
|
First nonblank character of current line. |
|
|
First nonblank character of next, previous line. |
|
ENTER |
First nonblank character of next line. |
|
|
Column num of current line. |
|
|
First, last position of screen line. {Vim} |
|
|
First nonblank character of screen line. {Vim} |
|
|
Middle of screen line. {Vim} |
|
|
Move up, down one screen line. {Vim} |
|
|
Top line of screen (Home position). |
|
|
Middle line of screen. |
|
|
Last line of screen. |
|
|
num lines after top line. |
|
|
num lines before last line. |
|
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 screen. |
|
|
Reposition line with cursor to top of screen. |
|
|
Reposition line with cursor to middle of screen. |
|
|
Reposition line with cursor to bottom of screen. |
|
CTRL-L |
Redraw screen (without scrolling). |
|
CTRL-R |
vi: redraw screen (without scrolling). |
|
Vim: redo last undone change. |
|
|
Search forward for pattern. End with ENTER. |
|
|
Go to line num after pattern. Forward search for pattern. |
|
|
Go to line num before pattern. Forward search for pattern. |
|
|
Search backward for pattern. End with ENTER. |
|
|
Go to line num after pattern. Backward search for pattern. |
|
|
Go to line num before pattern. Backward search for pattern. |
|
|
Suspend search highlighting until next search. {Vim} |
|
|
Repeat previous search. |
|
|
Repeat search in opposite direction. |
|
|
Repeat previous search forward. |
|
|
Repeat previous search backward. |
|
|
Search forward for word under cursor. Matches only exact words. {Vim} |
|
|
Search backward for word under cursor. Matches only exact words. {Vim} |
|
|
Search backward for word under cursor. Matches the characters of this word when embedded in a longer word. {Vim} |
|
|
Search backward for word under cursor. Matches the characters of this word when embedded in a longer word. {Vim} |
|
|
Find match of current parenthesis, brace, or bracket. |
|
|
Move cursor forward to x on current line. |
|
|
Move cursor backward to x on current line. |
|
|
Move cursor forward to character before x in current line. |
|
|
Move cursor backward to character after x in current line. |
|
|
Reverse search direction of last
|
|
|
Repeat last |
|
|
Place mark x at current position. |
|
|
(Backquote.) Move cursor to mark x. |
|
|
(Apostrophe.) Move to start of line containing x. |
|
|
(Backquotes.) Return to position before most recent jump. |
|
|
(Apostrophes.) Like preceding, but return to start of line. |
|
|
(Apostrophe quote.) Move to position when last editing the file. {Vim} |
|
|
(Backquote bracket.) Move to beginning/end of previous text operation. {Vim} |
|
|
(Apostrophe bracket.) Like preceding, but return to start of line where operation occurred. {Vim} |
|
|
(Backquote period.) Move to last change in file. {Vim} |
|
|
(Apostrophe period.) Like preceding, but return to start of line. {Vim} |
|
|
(Apostrophe zero.) Position where you last exited Vim. {Vim} |
|
|
List active marks. {Vim} |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
Terminate insert mode. |
The following commands work in insert mode:
|
BACKSPACE |
Delete previous character. |
|
DELETE |
Delete current character. |
|
TAB |
Insert a tab. |
|
CTRL-A |
Repeat last insertion. {Vim} |
|
CTRL-D |
Shift line left to previous shiftwidth. {Vim} |
|
CTRL-E |
Insert character found just below cursor. {Vim} |
|
CTRL-H |
Delete previous character (same as backspace). |
|
CTRL-I |
Insert a tab. |
|
CTRL-K |
Begin insertion of multikeystroke character. |
|
CTRL-N |
Insert next completion of the pattern to the left of the cursor. {Vim} |
|
CTRL-P |
Insert previous completion of the pattern to the left of the cursor. {Vim} |
|
CTRL-T |
Shift line right to next shiftwidth. {Vim} |
|
CTRL-U |
Delete current line. |
|
CTRL-V |
Insert next character verbatim. |
|
CTRL-W |
Delete previous word. |
|
CTRL-Y |
Insert character found just above cursor. {Vim} |
|
CTRL-[ |
(ESC) Terminate insert mode. |
Some of the control characters listed in the previous table are set by stty. Your terminal settings may differ.
Recall that c, d, and y
are the basic editing operators.
The following list is not exhaustive, but it illustrates the most common operations:
|
| |
|
| |
|
|
Change text from current position to end-of-line. |
|
| |
|
| |
|
| |
|
|
Delete text from current position to end-of-line. |
|
| |
|
| |
|
| |
|
| |
|
|
Delete up to first occurrence of pattern. |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
Insert last deleted or yanked text after cursor. |
|
| |
|
| |
|
|
Same as |
|
|
Same as |
|
|
Insert last deleted or yanked text before cursor. |
|
|
Replace character with x. |
|
|
Replace with new text (overwrite), beginning at cursor. ESC ends replace mode. |
|
|
Substitute character. |
|
|
Substitute four characters. |
|
|
Substitute entire line. |
|
|
Undo last change. |
|
CTRL-R |
Redo last change. {Vim} |
|
|
Restore current line. |
|
| |
|
| |
|
|
Delete previous five characters. |
|
|
Repeat last change. |
|
|
Reverse case and move cursor right. |
|
CTRL-A |
Increment number under cursor. {Vim} |
|
CTRL-X |
Decrement number under cursor. {Vim} |
Register names are the letters a–z.
Uppercase names append text to the corresponding register.
|
| |
|
| |
|
|
Copy current line to register x. |
|
| |
|
| |
|
| |
|
|
Delete current line into register x. |
|
|
Delete into register x. |
|
|
Put contents of register x. |
|
|
Copy up to next section heading. |
|
| |
|
| |
|
|
Same as |
|
|
Same as |
Writing a file means overwriting the file with the current text.
|
| |
|
|
Same as |
|
|
Write file and quit. |
|
|
Write file. |
|
|
Save copy to file. |
|
|
Write lines n to m to new file. |
|
|
Append lines n to m to existing file. |
|
|
Write file (overriding protection). |
|
|
Overwrite file with current text. |
|
|
Write current buffer named
file as
|
|
|
Quit vi (fails if changes were made). |
|
|
Quit vi (discarding edits). |
|
|
Quit vi and invoke ex. |
|
|
Return to vi after |
|
|
Replaced with current filename in editing commands. |
|
|
Replaced with alternate filename in editing commands. |
|
| |
|
|
Return to version of current file at time of last write. |
|
|
Begin editing at end of file. |
|
|
Open file at line num. |
|
|
Open to previous position in alternate file. |
|
|
Edit file at location tag. |
|
|
Edit next file in the list of files. |
|
|
Force next file. |
|
|
Specify new list of files. |
|
|
Edit first file in the list. |
|
CTRL-G |
Show current file and line number. |
|
|
Display list of files to be edited. |
|
|
Edit previous file in the list of files. |
The following table lists common commands for controlling windows in
Vim. See also the split, vsplit,
and resize commands in the later section the section called “Alphabetical Summary of ex Commands”. For brevity, control characters are
marked in the following list by ^.
|
| |
|
|
Open file in a new window. |
|
|
Split the current window. With file, edit that file in the new window. |
|
|
Same as |
|
|
Edit next file in file list in new window. |
|
|
Like |
|
|
Close current window. |
|
|
Hide current window, unless it is the only visible window. |
|
|
Make current window the only visible one. |
|
|
Resize window to num lines. |
|
|
Write all changed buffers to their files. |
|
|
Close all buffers and exit. |
|
|
Same as |
|
|
Same as |
|
|
Open new window with alternate (previously edited) file. |
|
|
Same as |
|
|
Same as |
|
|
Move cursor to next/previous window. |
|
|
Move cursor to previous window. |
|
|
Move cursor to window on left/right of screen. |
|
|
Move cursor to window on top/bottom of screen. |
|
|
Move current window to top/bottom of screen. |
|
|
Move current window to far left/right of screen. |
|
|
Rotate windows down/up. |
|
|
Increase/decrease current window size. |
|
|
Make all windows same height. |
|
|
Read in contents of file after cursor. |
|
|
Read in output from command after current line. |
|
|
Like previous, but place after line num (0 for top of file). |
|
|
Run command, then return. |
|
|
Send the text covered by motion to Unix command; replace with output. |
|
|
Send lines n–m to command; replace with output. |
|
|
Send num lines to Unix command; replace with output. |
|
|
Repeat last system command. |
|
|
Create subshell; return to editor with EOF. |
|
CTRL-Z |
Suspend editor, resume with fg. |
|
|
Read and execute ex commands from file. |
|
| |
|
|
Remove abbreviation for in. |
|
|
List abbreviations. |
|
|
Map characters
string as sequence of
commands. Use |
|
|
Remove map for characters string. |
|
|
List character strings that are mapped. |
|
|
Map characters string to input mode sequence. |
|
|
Remove input mode map (you may need to quote the characters with CTRL-V). |
|
|
List character strings that are mapped for input mode. |
|
|
Record typed characters into register specified by letter x. If letter is uppercase, append to register. {Vim} |
|
|
Stop recording. {Vim} |
|
|
Execute the register specified by
letter x. Use |
In vi, the following characters are unused in command mode and can be mapped as user-defined commands:
g, K,
q, V, and
v
^A, ^K,
^O, ^W,
^X, ^_, and
^\
_, *,
\, =, and
#
Vim does not use ^K, ^_, _, or
\.
|
|
Shift text described by following motion command left by one shiftwidth. {Vim} |
|
|
Shift text described by following motion command right by one shiftwidth. {Vim} |
|
|
Shift line left one shiftwidth (default is eight spaces). |
|
|
Shift line right one shiftwidth (default is eight spaces). |
|
|
Shift right to end of paragraph. |
|
|
Shift left until matching parenthesis, brace, or bracket. (Cursor must be on the matching symbol.) |
|
|
Indent line in C-style, or using
program specified in |
|
|
Start many multiple character commands in Vim. |
|
|
Look up word under cursor in manpages
(or program defined in |
|
|
Return to previous jump. {Vim} |
|
|
Same as |
|
|
Return to the previous location in the tag stack. (Solaris vi, Vim, nvi, elvis, and vile.) |
|
|
Perform a tag lookup on the text under the cursor. |
|
|
Enter ex line-editing mode. |
|
|
(Caret key with Ctrl key pressed.) Return to previously edited file. |
This section describes the following:
The :set command
Options available with :set
Example .exrc file
The :set command allows you to specify options that change characteristics
of your editing environment. Options may be put in the ~/.exrc file or set during a vi session.
The colon does not need to be typed if the command is put in
.exrc:
|
|
Enable Boolean option x; show value of other options. |
|
|
Disable option x. |
|
|
Give value to option x. |
|
|
Show changed options. |
|
|
Show all options. |
|
|
Show value of option x. |
Appendix B, Setting Options provides tables of :set options for Solaris vi, Vim, nvi, elvis,
and vile. Please see that appendix
for more information.
In an ex script file, comments
start with the double quote character. The following lines of code
are an example of a customized .exrc file:
set nowrapscan " Searches don't wrap at end of file set wrapmargin=7 " Wrap text at 7 columns from right margin set sections=SeAhBhChDh nomesg " Set troff macros, disallow message map q :w^M:n^M " Alias to move to next file map v dwElp " Move a word ab ORA O'Reilly Media, Inc. " Input shortcut
The ex line editor serves as the foundation for the screen editor vi. Commands in ex work on the current line or on a range of lines in a file. Most often, you use ex from within vi. In vi, ex commands are preceded by a colon and entered by pressing ENTER.
You can also invoke ex on its
own—from the command line—just as you would invoke vi. (You could execute an ex script this way.) Or you can use the vi command Q
to quit the vi editor and enter
ex.
To enter an ex command from vi, type:
:[address]command[options]
An initial : indicates an
ex command. As you type the command,
it is echoed on the status line. Execute the command by pressing the
ENTER key. Address is the line
number or range of lines that are the object of
command. Options and
addresses are described later. ex commands are described in the later section
the section called “Alphabetical Summary of ex Commands”.
You can exit ex in several ways:
|
|
Exit (save changes and quit). |
|
|
Quit without saving changes. |
|
|
Switch to the vi editor on the current file. |
If no address is given, the current line is the object of the command. If the address specifies a range of lines, the format is:
x,y
where x and y are the
first and last addressed lines (x must precede
y in the buffer). x and
y each may be a line number or a symbol. Using
; instead of , sets the current line to
x before interpreting y. The
notation 1,$ addresses all lines in
the file, as does %.
|
|
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 num. |
|
|
Last line. |
|
|
All lines; same as |
|
|
n lines before x. |
|
|
n lines after x. |
|
|
One or num lines previous. |
|
|
One or num lines ahead. |
|
|
(Apostrophe.) Line marked with x. |
|
|
(Apostrophe apostrophe.) Previous mark. |
|
|
Forward to line matching pattern. |
|
|
Backward to line matching pattern. |
See Chapter 6, Global Replacement for more information on using patterns.
!
Indicates a variant form of the command, overriding the
normal behavior. The ! must
come immediately after the command.
The number of times the command is to be repeated. Unlike in
vi commands,
count cannot precede the command, because a
number preceding an ex command
is treated as a line address. For example, d3 deletes three lines, beginning with
the current line; 3d deletes
line 3.
The name of a file that is affected by the command. % stands for the current file; # stands for the previous file.
ex commands can be entered by
specifying any unique abbreviation. In the following list of reference
entries, the full name appears as the heading of the reference entry, and
the shortest possible abbreviation is shown in the syntax line below it.
Examples are assumed to be typed from vi, so they include the : prompt.
abbreviate
ab [string text]append
[address] a[!]text.
Append new text at specified address, or at present address if
none is specified. Add a ! to
toggle the autoindent setting that
is used during input. That is, if autoindent was enabled, ! disables it. Enter new text after entering
the command. Terminate input of new text by entering a line consisting
of just a period.
copy
[address] codestination
delete
[address] d [register] [count]
edit
e[!] [+num] [filename]
Begin editing on filename. If no
filename is given, start over with a copy of the
current file. Add a ! to edit the
new file even if the current file has not been saved since the last
change. With the +num argument, begin
editing on line num. Alternatively,
num may be a pattern, of the form /pattern.
file
f [filename]Change the filename for the current buffer to filename.
The next time the buffer is written, it will be written to file
filename. When the name is changed, the buffer’s
“not edited” flag is set, to indicate that you are not editing an
existing file. If the new filename is the same as a file that already
exists on the disk, you will need to use :w! to overwrite the existing file. When
specifying a filename, the %
character can be used to indicate the current filename. A # can be used to indicate the alternate
filename. If no filename is specified, print the
current name and status of the buffer.
global
[address] g[!]/pattern/[commands]
join
[address] j[!] [count]
map
map[!] [string commands]mark
[address] machar
Mark the specified line with char, a single
lowercase letter. Same as k. Return
later to the line with
'x (apostrophe plus
x, where x is the same as
char). Vim also uses uppercase and numeric
characters for marks. Lowercase letters work the same as in vi. Uppercase letters are associated with filenames and can be
used between multiple files. Numbered marks, however, are maintained
in a special viminfo file and
cannot be set using this command.
next
n[!] [[+num]filelist]
Edit the next file from the command-line argument list. Use
args to list these files. If
filelist is provided, replace the current
argument list with filelist and begin editing on
the first file. With the +num argument, begin
editing on line num. Alternatively,
num may be a pattern, of the form /pattern.
[address] p [count]
quit
q[!]
Terminate the current editing session. Use ! to discard changes made since the last
save. If the editing session includes additional files in the argument
list that were never accessed, quit by typing q! or by typing q twice. Vim closes the editing window only
if there are still other windows open on the screen.
read
[address] rfilename
set
se parameter1 parameter2 ...Set a value to an option with each parameter,
or if no parameter is supplied, print all options
that have been changed from their defaults. For Boolean options, each
parameter can be phrased as
option or nooption; other options
can be assigned with the syntax option=value. Specify
all to list current settings. The
form set
option?
displays the value of option. See the tables that
list set options in Appendix B, Setting Options.
snext
[count] sn [[+num]filelist]
Split the current window and begin editing the next file from the command-line
argument list. If count is provided, edit the
count next file. If filelist
is provided, replace the current argument list with
filelist and begin editing the first file. With
the +n argument, begin editing on line
num. Alternately, num may be
a pattern of the form /pattern. {Vim}
split
[count] sp [+num] [filename]
Split the current window and load filename in the new window, or the same buffer in both windows if no file is specified. Make the new window count lines high, or if count is not specified, split the window into equal parts. With the +n argument, begin editing on line num. num may also be a pattern of the form /pattern. {Vim}
substitute
[address] s [/pattern/replacement/] [options] [count]
Replace the first instance of pattern on each of the specified lines with replacement. If pattern and replacement are omitted, repeat last substitution. count specifies the number of lines on which to substitute, starting with address. (Spelling out the command name does not work in Solaris vi.)
v
[address] v/pattern/[command]
write
[address] w[!] [[>>]file]
Write lines specified by address to
file, or write full contents of buffer if
address is not specified. If
file is also omitted, save the contents of the
buffer to the current filename. If >> file is used,
append lines to the end of the specified file.
Add a ! to force the editor to
write over any current contents of file.
yank
[address] y [char] [count]
z
[address] z [type] [count]
&
[address] & [options] [count]
!
[address] !command
< >
[address] < [count] or [address] > [count]
Shift lines specified by address either
left (<) or right (>). Only leading spaces and tabs are
added or removed when shifting lines. count
specifies the number of lines to shift, starting with
address. The shiftwidth option controls the number of
columns that are shifted. Repeating the < or > increases the shift amount. For
example, :>>> shifts three
times as much as :>.
[74] The crypt command’s encryption is weak. Don’t use it for serious secrets.
If you enjoyed this excerpt, buy a copy of Learning the vi and Vim Editors, Seventh Edition.
Copyright © 2009 O'Reilly Media, Inc.