By Arnold Robbins
Book Price: $9.95 USD
£6.95 GBP
PDF Price: $7.99
Cover | Table of Contents
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.Courier| 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) |
[command][number]text object
[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 |
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.Courier| 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) |
[command][number]text object
[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 |
nH | n (number) of lines after top line |
nL | 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 |
fx | Search forward for character x in current line |
Fx | Search backward for character x in current line |
tx | Search forward to character before x in current line |
Tx | 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 |
nG | Move to line number n |
G | Move to last line in file |
:n | Move to line n in file |
| Marking position | |
mx | 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 |
:ab abbr phrase:unab abbr:map x sequence:unmap x:map:map! x sequence:unmap! x:map!notimeout changes the behavior.#n# followed by a digit
n represents the sequence of characters sent
by the terminal’s function key number n.^[) or
carriage return (^M), first type a CTRL-V
(^V).@ command
followed by the buffer letter.:@buf-name
works similarly.* 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.:set autoindent
^T^D^ ^D0 ^D:[addr1[,addr2]]s/old/new/[flags]
:s//replacement/)
uses the last search or substitution regular expression.:s/pattern//) “replaces” the
matched text
with nothing, effectively deleting it from the line.Flag | Meaning |
|---|---|
c | Confirm each substitution |
g | Change all occurrences of old
to new on each line (globally) |
p | Print the line after the change is made |
:g::g/Object Oriented/s//Buzzword compliant/g
.** can follow a metacharacter, such as
. or a range in brackets.^^ 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.$$
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.\[ ]\ - ].
(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.)^) 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 :[address] command [options]
Address | Includes |
|---|---|
1,$ | All lines in the file |
x,y | Lines x through y
|
x;y | Lines x through y,
with current line reset to x |
0 | Top of file |
. | Current line |
n | Absolute line number n
|
$ | Last line |
% | All lines; same as 1,$ |
x-n | n lines before x
|
x+n | n lines after x
|
-[n] | One or n lines previous |
+[n] | One or n lines ahead |
’x | Line marked with x |
’’ | Previous mark |
/pat/ or ?pat? | Ahead or back to line where pat matches
|
Symbol | Meaning |
|---|---|
! | A variant form of the command |
count | Repeat the command count times |
file | Filename:
% is current file,
# is previous file |
| Full Name | Command | |
|---|---|---|
| Abbrev | ab [string text] | |
| Append |
[address]
a[!]
text
. | |
| Args |
ar | |
| Change | [address]
c[!]
text
. | |
| Copy | [address]
co
destination | |
| Delete | [address]
d
[buffer] | |
| Edit | e
[!][+n]
[filename] | |
| File | f [filename] | |
| Global | [address] g[!]/pattern/[commands] | |
| Insert | [address]
i[!]
text
. | |
| Join | [address] j[!][count] | |
| K (mark) | [address]
k
char | |
| List | [address] l [count] | |
| Map | map
char commands | |
| Mark | [address]
ma
char | |
| Move | [address]
m
destination | |
| Next | n[!]
[[+command]
filelist] | |
| Number | [address]
nu
[count] | |
| Open | [address]
o
[/pattern/] | |
| Preserve | pre | |
[address]
p [count]
[address] P [count] | ||
| Put | [address]
pu
[char] | |
| Quit | q[!] | |
| Read | [address]
r
filename | |
| Read | [address]
r !
command | |
| Recover | rec
[filename] | |
| Rewind | rew[!] | |
| Set |
set
set option
set nooption
6
set
option=value
set option? | |
| Shell | sh | |
| Source | so
filename | |
| Substitute | [addr ] s [/pat/repl/][opts] | |
| T (to) | [address] t destination | |
| Tag | [address]
ta
tag | |
| Unabbreviate | una word | |
| Undo | u | |
| Unmap | unm char | |
| V (global exclude) | [address ]
v/pattern/[commands] | |
| Version | ve | |
| Visual | [address]
vi
[type]
[count] | |
| Visual | vi
[+n]
[filename] | |
| Write | [address]
w[!]
[[>>]filename] | |
| Write | [address]
w !command | |
| Wq (write + quit) | wq[!] | |
| Xit | x | |
| Yank | [address]
y
[char]
[count] | |
| Z (position line) | [address]
z[type]
[count]type can be one of:
| |
! | [address]
!command | |
= (line number) | [address]
= | |
< > (shift) | [address]
< [count]
[address] > [count] | |
| Address | ||
EXINIT environment variable exists,
execute the commands it contains.
Separate multiple commands by a pipe symbol (|).EXINIT doesn't exist,
look for the file $HOME/.exrc.
If it exists, read and execute it.EXINIT or $HOME/.exrc
turns on the exrc option, read and execute
the file ./.exrc, if it exists.+/pattern or
+n command-line options (POSIX: –c option)."). This is recommended.ex -r or vi -r
list any files you can recover. You then use the command:
$ vi -r file
to recover a particular file.:pre (preserve).Option | Default |
|---|---|
autoindent (ai) | noai |
autoprint (ap) | ap |
autowrite (aw) | noaw |
beautify (bf) | nobf |
directory (dir) | /tmp |
edcompatible | noedcompatible |
errorbells (eb) | errorbells |
exrc (ex) | noexrc |
hardtabs (ht) | 8 |
ignorecase (ic) | noic |
lisp | nolisp |
list | nolist |
magic | magic |
mesg | mesg |
novice | nonovice |
number (nu) | nonu |
open | open |
optimize (opt) | noopt |
paragraphs (para) | IPLPPPQP
LIpplpipbp |
prompt | prompt |
readonly (ro) | noro |
redraw (re) | |
remap | remap |
report | 5 |
scroll | half window |
sections (sect) | SHNHH HU |
shell (sh) | /bin/sh |
shiftwidth (sw) | 8 |
showmatch (sm) | nosm |
showmode | noshowmode |
slowopen (slow) | |
tabstop (ts) | 8 |
taglength (tl) | 0 |
tags | tags /usr/lib/tags |
tagstack | tagstack |
term | (from $TERM) |
terse | noterse |
timeout (to) | timeout |
ttytype | (from $TERM) |
warn | warn |
window (w) | |
wrapscan (ws) | ws |
wrapmargin (wm) | 0 |
writeany (wa) | nowa |
http://home.hiwaay.net/~darren/ctags/).
As of this writing, the current version is 2.0.3.;". 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 |
|---|---|
kind | The value is a single
letter that indicates the lexical type of
the tag |
file | For static tags, i.e., local to the file |
function | For local tags |
struct | For fields in a struct |
enum | For values in an enum
data type |
class | For C++ member functions and variables |
scope | Intended mostly for
C++ class member functions |
arity | For functions |
kind.\\, \t,
\r, and \n, respectively.Command | Function |
|---|---|
ta[g][!] tagstring | Edit the file containing
tagstring as defined in the tags
file |
po[p][!] | Pop the tag stack
by one element |
Command | Function |
|---|---|
^] | Look up the location of the identifier
under the cursor in the tags file and move to that
location; if tag stacking is enabled,
the current location is automatically pushed onto the
tag stack |
^T | Return to the previous location
in the tag stack, i.e., pop off one element |
Option | Function |
|---|---|
taglength, tl | 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 |
tags, tagpath | The value is a list of
filenames in which to look for tags; the default value is "tags /usr/lib/tags" |
tagstack | When set to true,
vi stacks each location on the tag stack |
–c command–F–Rreadonly
option.–Ssecure option set, disallowing
access to external programs.–sCommand | Function |
|---|---|
bg | Hide the current window |
di[splay] b[uffers] | Display all buffers, including
named, unnamed, and numeric buffers |
di[splay] s[creens] | Display the filenames of all backgrounded windows |
Edit filename | Edit filename in a new window |
Edit /tmp | Create a new window editing an empty
buffer; /tmp is interpreted especially to create
a new temporary file |
fg filename | Uncover filename into the current
window |
Fg filename | Uncover filename in a new window; the current window is split |
Next | Edit the next file in the argument list in a new window |
Previous | Edit the previous file in the argument list in a new window |
resize ±nrows | Increase or decrease the size of the current window by
nrows rows |
Tag tagstring | Edit the file containing tagstring in a
new window |
^W command cycles between windows, top to
bottom. The :q and ZZ commands
exit the current window.:set extended to enable
extended regular expression matching:|(…)+?{…}{n}{n,}{n,m}–a–R–i–ssafer 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–G gui–c command+command
syntax).–V–?Command | Function |
|---|---|
sp[lit] [file] | Create a new window;
load it with file
if supplied; otherwise, the new window shows the current file |
new | Create a new empty buffer
and then create a new window to show that buffer |
sne[w] | |
sn[ext] [file…] | Create a new window,
showing the next file in the argument list |
sN[ext] | Create a new window, showing the
previous file in the argument list |
sre[wind][!] | Create a new window,
showing the first file in the argument
list; reset the “current” file as the first with
respect to the :next command |
sl[ast] | Create a new window,
showing the last file in the argument list |
sta[g][!] tag | Create a new window showing the file
where the requested
tag is found |
sa[ll] | Create a new window for any
files named in the
argument list that don’t already have a window |
wi[ndow] [target] | With no target,
list all windows; the possible values for target are described
in the following table |
close | Close the current window; the buffer that the window was
displaying remains intact |
wquit | Write the buffer back to the file
and close the window; the file is saved whether or not it has been modified |
qall | Issue a :q command
for each window; buffers without windows are not affected |
Argument | Meaning |
|---|---|
+ | Switch to the next window,
like ^W k |
++ | Switch to the next window,
wrapping like ^W ^W |
- | Switch to the previous window,
like ^W j |
- - | Switch to the previous window,
wrapping |
num | Switch to the window whose
windowid =num |
buffer-name | Switch to the window
editing the named buffer |
–c command+command )–Rreadonly
option.–s–b–f–g–o [N]–i viminfo–n–q filename–u vimrc–U gvimrc–ZCommand | Function |
|---|---|
[N] sp[lit] [position] [file] | Split the current window in half |
[N] new [position] [file] | Create a new window, editing an empty buffer |
[N] sv[iew] [position] [file] | Same as :split, but set the
readonly option for the buffer |
q[uit][!] | Quit the current window
(exit if given in the last window) |
clo[se][!] | Close the current window; behavior affected by the hidden option |
hid[e] | Close the current window,
if it's not the last one on
the screen |
on[ly] | Make this window the only one on the screen |
res[ize] [± |