9.3. Review of vi Operations
This section provides a review of the following:
-
vi
modes
-
Syntax of
vi
commands
-
Status-line commands
9.3.1. Command Mode
Once the file is opened, you are in command mode. From command mode, you can:
9.3.2. Insert Mode
In insert mode, you can enter new text in the file. You normally enter insert mode with the
i
command. Press the Escape 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 Insert Commands."
9.3.4. Syntax of vi Commands
In
vi
, editing commands have the following general form:
[
n
]
operator
[
m
]
motion
The basic editing
operators
are:
-
c
-
Begin a change.
-
d
-
Begin a edeletion.
-
y
-
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
x
m
.
An object of operation can be any of the following text blocks:
-
word
-
Includes
characters
up to a whitespace character (space or tab) or punctuation mark. A capitalized object is a variant form that recognizes only whitespace.
-
sentence
-
Is up to
.
,
!
, or
?
, followed by two spaces.
-
paragraph
-
Is up to the next blank line or paragraph macro defined by the
para=
option.
-
section
-
Is up to the next
nroff
/
troff
section heading defined by the
sect=
option.
-
motion
-
Is up to the character or other text object as specified by a motion
specifier
, including pattern searches.
9.3.4.1 Examples
-
2cw
-
Change the next two words.
-
d}
-
Delete up to next paragraph.
-
d^
-
Delete back to beginning of line.
-
5yy
-
Copy the next five lines.
-
y]]
-
Copy up to the next section.
-
cG
-
Change to the end of the edit buffer.
More commands and examples may be found in the section Changing and Deleting Text," later in this chapter
9.3.4.2 Visual mode (vim only)
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
vim
help file
visual.txt
for the full story.
-
v
-
Select text in visual mode one character at a time.
-
V
-
Select text in visual mode one line at a time.
-
Ctrl-V
-
Select text in visual mode in blocks.
9.3.5. Status-Line Commands
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
!
to describe what should be passed to the Unix command. The command itself is entered on the status line.
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.
|