N |
Command |
Meaning |
|
* |
h |
^H |
<erase> |
<*> chars to the left. |
* |
j |
<lf> |
^N |
<*> lines downward. |
* |
l |
<sp> |
<*> chars to the right. |
* |
k |
^P |
<*> lines upward. |
* |
$ |
To the end of line <*> from the cursor. |
- |
^ |
To the first CHAR of the line. |
* |
_ |
To the first CHAR <*> - 1 lines lower. |
* |
- |
To the first CHAR <*> lines higher. |
* |
+ |
<cr> |
To the first CHAR <*> lines lower. |
- |
0 |
To the first char of the line. |
* |
| |
To column <*> (<ht>: only to the endpoint). |
* |
f<char> |
<*> <char>s to the right (find). |
* |
t<char> |
Till before <*> <char>s to the right. |
* |
F<char> |
<*> <char>s to the left. |
* |
T<char> |
Till after <*> <char>s to the left. |
* |
; |
Repeat latest `f'|`t'|`F'|`T' <*> times. |
* |
, |
Idem in opposite direction. |
* |
w |
<*> words forward. |
* |
W |
<*> WORDS forward. |
* |
b |
<*> words backward. |
* |
B |
<*> WORDS backward. |
* |
e |
To the end of word <*> forward. |
* |
E |
To the end of WORD <*> forward. |
* |
G |
Go to line <*> (default EOF). |
* |
H |
To line <*> from top of the screen (home). |
* |
L |
To line <*> from bottom of the screen (last). |
* |
M |
To the middle line of the screen. |
* |
) |
<*> sentences forward. |
* |
( |
<*> sentences backward. |
* |
} |
<*> paragraphs forward. |
* |
{ |
<*> paragraphs backward. |
- |
]] |
To the next section (default EOF). |
- |
[[ |
To the previous section (default begin of file). |
- |
`<a-z> |
To the mark. |
- |
'<a-z> |
To the first CHAR of the line with the mark. |
- |
`` |
To the cursor position before the latest absolute
jump (of which are examples `/' and `G'). |
- |
'' |
To the first CHAR of the line on which the cursor
was placed before the latest absolute jump. |
- |
/<string> |
To the next occurrence of <string>. |
- |
?<string> |
To the previous occurrence of <string>. |
- |
/<string>/+[n] |
To n-th (default 1st) line after next occurrence of <string>. |
- |
?<string>?+[n] |
Idem, searching in the opposite direction. |
- |
/<string>/-[n] |
To n-th (default 1st) line before next occurrence of
<string>. |
- |
?<string>?-[n] |
Idem, searching in the opposite direction. |
- |
<find>[;<find>] |
Perform successive `/'|`?' actions. For example,
/foo/;/bar |
- to next `foo', then to next
`bar' |
?foo?-;/bar |
- to line before previous `foo', then to next
`bar' |
|
- |
n |
Repeat latest `/'|`?' (next). |
- |
N |
Idem in opposite direction. |
- |
% |
Find the next bracket and go to its match
(also with `{'|`}' and `['|`]'). |
N |
Command |
Meaning |
|
* |
a |
<*> times after the cursor. |
* |
A |
<*> times at the end of line. |
* |
i |
<*> times before the cursor (insert). |
* |
I |
<*> times before the first CHAR of the line |
* |
o |
On a new line below the current (open).
The count is only useful on a slow terminal. |
* |
O |
On a new line above the current.
The count is only useful on a slow terminal. |
* |
><move> |
Shift the lines described by <*><move> one
shiftwidth to the right. |
* |
>> |
Shift <*> lines one shiftwidth to the right. |
* |
["<a-zA-Z1-9>]p |
Put the contents of the (default undo) buffer
<*> times after the cursor.
A buffer containing lines is put only once,
below the current line.
See `deleting text'. |
* |
["<a-zA-Z1-9>]P |
Put the contents of the (default undo) buffer
<*> times before the cursor.
A buffer containing lines is put only once,
above the current line.
See `deleting text'. |
* |
. |
Repeat previous command <*> times. If the last
command before a `.' command references a
numbered buffer, the buffer number is
incremented first (and the count is ignored):
"1pu.u.u.u.u |
- `walk through' buffers 1
through 5 |
"1P.... |
- restore them |
|
- |
:[x,y]t<l> |
Copy lines x through y (default current line) to be after line
<l>. See `remembering text'. |
N |
Command |
Meaning |
|
* |
r<char> |
Replace <*> chars by <char> - no <esc>. |
* |
R |
Overwrite the rest of the line,
appending change <*> - 1 times. |
* |
s |
Substitute <*> chars. |
* |
S |
<*> lines. |
* |
c<move> |
Change from begin to endpoint of <*><move>. |
* |
cc |
<*> lines. |
* |
C |
The rest of the line and <*> - 1 next lines. |
* |
=<move> |
If the option `lisp' is set, this command
will realign the lines described by <*><move>
as though they had been typed with the option
`ai' set too. |
- |
~ |
Switch lower and upper cases
(should be an operator, like `c'). |
* |
J |
Join <*> lines (default 2). |
* |
. |
Repeat latest command <*> times (`J' only once). |
- |
& |
Repeat latest `ex' substitute command, e.g.
`:s/wrong/good'. |
- |
:[x,y]j |
Join lines x through y (default current line and next). |
- |
:[x,y]j! |
Idem, but with no space inbetween. |
- |
:[x,y]m<l> |
Move lines x through y (default current line)
to be after line <l>. See `remembering
text'. |
- |
:[x,y]s/<p>/<r>/<f> |
Substitute (on lines x through y) the pattern <p>
(default the last pattern) with <r>. Useful
flags <f> are `g' for `global' (i.e. change
every non-overlapping occurrence of <p>) and
`c' for `confirm' (type `y' to confirm a
particular substitution, else <cr>). Instead
of `/' any punctuation CHAR unequal to <lf>
can be used as delimiter. |
Command |
Meaning |
|
^@ |
If typed as the first character of the
insertion, it is replaced with the previous
text inserted (max. 128 chars), after which
the insertion is terminated. |
^V |
Deprive the next char of its special meaning
(e.g. <esc>). |
^D |
One shiftwidth to the left, but only if
nothing else has been typed on the line. |
0^D |
Remove all indentation on the current line
(there must be no other chars on the line). |
^^D |
Idem, but it is restored on the next line. |
^T |
One shiftwidth to the right, but only if
nothing else has been typed on the line. |
^H |
<erase> |
One char back. |
^W |
One word back. |
<kill> |
Back to the begin of the change on the
current line. |
<intr> |
Like <esc> (but you get a beep as well). |
Command |
Meaning |
|
:q |
Quit vi, unless the buffer has been changed. |
:q! |
Quit vi without writing. |
^Z |
Suspend vi. |
:w |
Write the file. |
:w <name> |
Write to the file <name>. |
:w >> <name> |
Append the buffer to the file <name>. |
:w! <name> |
Overwrite the file <name>. |
:x,y w <name> |
Write lines x through y to the file <name>. |
:wq |
Write the file and quit vi; some versions quit
even if the write was unsuccessful!
Use `ZZ' instead. |
ZZ |
Write if the buffer has been changed, and
quit vi. If you have invoked vi with the `-r'
option, you'd better write the file
explicitly (`:w' or `:w!'), or quit the
editor explicitly (`:q!') if you don't want
to overwrite the file - some versions of vi
don't handle the `recover' option very
well. |
:x [<file>] |
Idem [but write to <file>]. |
:x! [<file>] |
`:w! [<file>]' and `:q'. |
:pre |
Preserve the file - the buffer is saved as if
the system had just crashed; for emergencies,
when a `:w' command has failed and you don't
know how to save your work (see
`vi -r'). |
:f <name> |
Set the current filename to <name>. |
:cd [<dir>] |
Set the working directory to <dir>
(default home directory). |
:cd! [<dir>] |
Idem, but don't save changes. |
:e [+<cmd>] <file> |
Edit another file without quitting vi - the
buffers are not changed (except the undo
buffer), so text can be copied from one file to
another this way. [Execute the `ex' command
<cmd> (default `$') when the new file has been
read into the buffer.] <cmd> must contain no
<sp> or <ht>. See `vi startup'. |
:e! [+<cmd>] <file> |
Idem, without writing the current buffer. |
^^ |
Edit the alternate (normally the previous) file. |
:rew |
Rewind the argument list, edit the first file. |
:rew! |
Idem, without writing the current buffer. |
:n [+<cmd>] [<files>] |
Edit next file or specify a new argument list. |
:n! [+<cmd>] [<files>] |
Idem, without writing the current buffer. |
:args |
Give the argument list, with the current file
between `[' and `]'. |
N |
Command |
Meaning |
|
- |
^G |
Give file name, status, current line number
and relative position. |
- |
^L |
Refresh the screen (sometimes `^P' or `^R'). |
- |
^R |
Sometimes vi replaces a deleted line by a `@',
to be deleted by `^R'
(see option `redraw'). |
* |
^E |
Expose <*> more lines at bottom, cursor
stays put (if possible). |
* |
^Y |
Expose <*> more lines at top, cursor
stays put (if possible). |
* |
^D |
Scroll <*> lines downward
(default the number of the previous scroll;
initialization: half a page). |
* |
^U |
Scroll <*> lines upward
(default the number of the previous scroll;
initialization: half a page). |
* |
^F |
<*> pages forward. |
* |
^B |
<*> pages backward (in older versions `^B' only
works without count). |
Command |
Meaning |
|
:map <string> <seq> |
<string> is interpreted as <seq>, e.g. `:map ^C
:!cc %^V<cr>' to invoke `cc' (the C compiler) from
within the editor (vi replaces `%' with the current file
name). |
:map |
Show all mappings. |
:unmap <string> |
Deprive <string> of its mapping. When vi
complains about non-mapped macros (whereas no
typos have been made), first do something like
`:map <string> Z', followed by
`:unmap <string>' (`Z' must not be a macro
itself), or switch to `ex' mode first with `Q'. |
:map! <string> <seq> |
Mapping in append mode, e.g.
`:map! \be begin^V<cr>end;^V<esc>O<ht>'.
When in append mode <string> is preceded by
`^V', no mapping is done. |
:map! |
Show all append mode mappings. |
:unmap! <string> |
Deprive <string> of its mapping (see `:unmap'). |
:ab <string> <seq> |
Whenever in append mode <string> is preceded and
followed by a breakpoint (e.g. <sp> or `,'), it
is interpreted as <seq>, e.g.
`:ab ^P procedure'. A `^V' immediately
following <string> inhibits expansion. |
:ab |
Show all abbreviations. |
:unab <string> |
Do not consider <string> an abbreviation
anymore (see `:unmap'). |
@<a-z> |
Consider the contents of the named register a
command, e.g.:
o0^D:s/wrong/good/<esc>"zdd
Explanation:
o |
- open a new line |
0^D |
- remove indentation |
:s/wrong/good/ |
- this input text is an `ex' substitute command |
<esc> |
- finish the input |
"zdd |
- delete the line just created into register `z' |
Now you can type `@z' to replace `wrong'
with `good' on the current line.
|
@@ |
Repeat last register command. |
N |
Command |
Meaning |
|
- |
Q |
^\ |
<intr><intr> |
Switch from vi to `ex'. |
- |
: |
An `ex' command can be given. |
- |
:vi |
Switch from `ex' to vi. |
- |
:sh |
Execute a subshell, back to vi by `^D'. |
- |
:[x,y]!<cmd> |
Execute a shell <cmd> [on lines x through y;
these lines will serve as input for <cmd> and
will be replaced by its standard output]. |
- |
:[x,y]!! [<args>] |
Repeat last shell command [and append <args>]. |
- |
:[x,y]!<cmd> ! [<args>] |
Use the previous command (the second `!' in a
new command. |
* |
!<move><cmd> |
The shell executes <cmd>, with as standard
input the lines described by <*><move>,
next the standard output replaces those lines
(think of `cb', `sort', `nroff',
etc.). |
* |
!<move>!<args> |
Append <args> to the last <cmd> and execute it,
using the lines described by the current
<*><move>. |
* |
!!<cmd> |
Give <*> lines as standard input to the
shell <cmd>, next let the standard output
replace those lines. |
* |
!!! [<args>] |
Use the previous <cmd> [and append <args> to
it]. |
- |
:x,y w !<cmd> |
Let lines x to y be standard input for <cmd>
(notice the <sp> between the `w' and the
`!'). |
- |
:r!<cmd> |
Put the output of <cmd> onto a new line. |
- |
:r <name> |
Read the file <name> into the buffer. |