7. Set Commands
Vi has a number of internal variables and switches which can be
set to achieve special affects.
These options come in three forms, those that are switches, which toggle
from off to on and back, those that require a numeric value, and those
that require an alphanumeric string value.
The toggle options are set by a command of the form:
-
:set option<nl>
and turned off with the command:
-
:set nooption<nl>
Commands requiring a value are set with a command of the form:
-
:set option=value<nl>
To display the value of a specific option type:
-
:set option?<nl>
To display only those that you have changed type:
-
:set<nl>
and to display the long table of all the settable parameters and
their current values type:
-
:set all<nl>
Most of the options have a long form and an abbreviation. Both are
listed in the following table as well as the normal default value.
To arrange to have values other than the default used every time you
enter
vi,
place the appropriate
set
command in EXINIT in your environment, e.g.
-
EXINIT='set ai aw terse sh=/bin/csh'
export EXINIT
or
-
setenv EXINIT 'set ai aw terse sh=/bin/csh'
for
sh
and
csh,
respectively.
These are usually placed in your .profile or .login.
If you are running a system without environments (such as version 6)
you can place the set command in the file .exrc in your home
directory.
- autoindent ai
-
Default: noai Type: toggle
When in autoindent mode, vi helps you indent code by starting each
line in the same column as the preceding line.
Tabbing to the right with <tab> or <^T> will move this boundary to
the right, and it can be moved to the left with <^D>.
- autoprint ap
-
Default: ap Type: toggle
Causes the current line to be printed after each ex text modifying command.
This is not of much interest in the normal vi visual mode.
- autowrite aw
-
Default: noaw type: toggle
Autowrite causes an automatic write to be done if there are unsaved
changes before certain commands which change files or otherwise
interact with the outside world.
These commands are :!, :tag, :next, :rewind, ^^, and ^].
- beautify bf
-
Default: nobf Type: toggle
Causes all control characters except <tab>, <nl>, and <ff> to be discarded.
- directory dir
-
Default: dir=/tmp Type: string
This is the directory in which vi puts its temporary file.
- errorbells eb
-
Default: noeb Type: toggle
Error messages are preceded by a <bell>.
- hardtabs ht
-
Default: hardtabs=8 Type: numeric
This option contains the value of hardware tabs in your terminal, or
of software tabs expanded by the Unix system.
- ignorecase ic
-
Default: noic Type: toggle
All upper case characters are mapped to lower case in regular expression
matching.
- lisp
-
Default: nolisp Type: toggle
Autoindent for lisp code. The commands ( ) [[ and ]]
are modified appropriately to affect s-expressions and functions.
- list
-
Default: nolist Type: toggle
All printed lines have the <tab> and <nl> characters displayed visually.
- magic
-
Default: magic Type: toggle
Enable the metacharacters for matching. These include . * < > [string]
[^string] and [<chr>-<chr>].
- number nu
-
Default: nonu Type: toggle
Each line is displayed with its line number.
- open
-
Default: open Type: toggle
When set, prevents entering open or visual modes from ex or edit.
Not of interest from vi.
- optimize opt
-
Default: opt Type: toggle
Basically of use only when using the ex capabilities. This
option prevents automatic <cr>s from taking place,
and speeds up output of indented lines,
at the expense of losing typeahead on some versions of UNIX.
- paragraphs para
-
Default: para=IPLPPPQPP bp Type: string
Each pair of characters in the string indicate nroff macros
which are to be treated as the beginning of a paragraph for the
{ and } commands. The default string is for the -ms
and -mm macros.
To indicate one letter nroff macros, such as .P or .H,
quote a space in for the second character position. For example:
:set paragraphs=P\ bp<nl>
would cause vi to consider .P and .bp as paragraph
delimiters.
- prompt
-
Default: prompt Type: toggle
In
ex
command mode the prompt character : will be printed when
ex is waiting for a command. This is not of interest from vi.
- redraw
-
Default: noredraw Type: toggle
On dumb terminals, force the screen to always be up to date,
by sending great amounts of output. Useful only at high speeds.
- report
-
Default: report=5 Type: numeric
This sets the threshold for the number of lines modified. When
more than this number of lines are modified, removed, or yanked,
vi will report the number of lines changed at the bottom of
the screen.
- scroll
-
Default: scroll={1/2 window} Type: numeric
This is the number of lines that the screen scrolls up or down when
using the <^U> and <^D> commands.
- sections
-
Default: sections=SHNHH HU Type: string
Each two character pair of this string specify nroff macro names
which are to be treated as the beginning of a section by the
]] and [[ commands. The default string is for the -ms
and -mm macros.
To enter one letter nroff macros, use a quoted space as the
second character.
See paragraphs for a fuller explanation.
- shell sh
-
Default: sh=from environment SHELL or /bin/sh Type: string
This is the name of the sh to be used for "escaped" commands.
- shiftwidth sw
-
Default: sw=8 Type: numeric
This is the number of spaces that a <^T> or <^D> will move over for
indenting, and the amount < and > shift by.
- showmatch sm
-
Default: nosm Type: toggle
When a ) or } is typed, show the matching ( or {
by moving the cursor to it for one second if it is on the current screen.
- slowopen slow
-
Default: terminal dependent Type: toggle
On terminals that are slow and unintelligent, this option prevents the
updating of the screen some of the time to improve speed.
- tabstop ts
-
Default: ts=8 Type: numeric
<tab>s are expanded to boundaries that are multiples of this value.
- taglength tl
-
Default: tl=0 Type: numeric
If nonzero, tag names are only significant to this many characters.
- term
-
Default: (from environment TERM, else dumb) Type: string
This is the terminal and controls the visual displays. It cannot be
changed when in "visual" mode,
you have to Q to command mode, type a
set term command, and do ``vi.'' to get back into visual.
Or exit vi, fix $TERM, and reenter.
The definitions that drive a particular
terminal type are found in the file /etc/termcap.
- terse
-
Default: terse Type: toggle
When set, the error diagnostics are short.
- warn
-
Default: warn Type: toggle
The user is warned if she/he tries to escape to
the shell without writing out the current changes.
- window
-
Default: window={8 at 600 baud or less, 16 at 1200 baud, and screen
size - 1 at 2400 baud or more} Type: numeric
This is the number of lines in the window whenever vi must redraw
an entire screen. It is useful to make this size smaller if you are
on a slow line.
- w300, w1200, w9600
-
These set window, but only within the corresponding speed ranges.
They are useful in an EXINIT to fine tune window sizes.
For example,
-
set w300=4 w1200=12
causes a 4 lines window at speed up to 600 baud, a 12 line window at 1200
baud, and a full screen (the default) at over 1200 baud.
- wrapscan ws
-
Default: ws Type: toggle
Searches will wrap around the end of the file when is option is set. When
it is off, the search will terminate when it reaches the end or the
beginning of the file.
- wrapmargin wm
-
Default: wm=0 Type: numeric
Vi will automatically insert a <nl> when it finds a natural
break point (usually a <sp> between words) that occurs within
"wm" spaces of the right margin.
Therefore with "wm=0" the option is off. Setting it to 10 would
mean that any time you are within 10 spaces of the right margin
vi would be looking for a <sp> or <tab> which it could
replace with a <nl>. This is convenient for people who forget
to look at the screen while they type.
(In version 3, wrapmargin behaves more like nroff, in that the
boundary specified by the distance from the right edge of the screen
is taken as the rightmost edge of the area where a break is allowed,
instead of the leftmost edge.)
- writeany wa
-
Default: nowa Type: toggle
Vi normally makes a number of checks before it writes out a file.
This prevents the user from inadvertently destroying a file. When the
"writeany" option is enabled, vi no longer makes these checks.