home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: 8.9 Alphabetical List of Keys Chapter 8
The Vi Editor
Next: 9. The Ex Editor

8.10 Setting Up Vi

This subsection describes the following:

  • The :set command

  • Options available with :set

  • Example .exrc file

8.10.1 The :set Command

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 should not be typed if the command is put in .exrc .

:set x Enable option x .
:set no x Disable option x .
:set x = val Give value to option x .
:set Show changed options.
:set all Show all options.
:set x ? Show value of option x .

8.10.2 Options Used by :set

The following table describes the options to :set . The first column includes the optional abbreviation, if there is one, and uses an equal sign to show that the option takes a value. The second column gives the default, and the third column describes the behavior of the enabled option.

Option Default Description
autoindent (ai) noai

In insert mode, indent each line to the same level as the line above or below. Use with shiftwidth option.

autoprint (ap) ap

Display changes after each editor command. (For global replacement, display last replacement.)

autowrite (aw) noaw

Automatically write (save) file if changed before opening another file with :n or before giving UNIX command with :! .

beautify (bf) nobf

Ignore all control characters during input (except tab, newline, or formfeed).

directory= (dir) /tmp

Name the directory in which ex stores buffer files. (Directory must be writable.)

edcompatible noed-compatible

Use ed-like features on substitute commands.

errorbells (eb) errorbells Sound bell when an error occurs.
exrc (ex) noexrc

Allow the execution of .exrc files that reside outside the user's home directory.

hardtabs= (ht) 8 Define boundaries for terminal hardware tabs.
ignorecase (ic) noic Disregard case during a search.
lisp nolisp

Insert indents in appropriate lisp format. ( ), { }, [[, and ]] are modified to have meaning for lisp.

list nolist

Print tabs as ^I; mark ends of lines with $. (Use list to tell if end character is a tab or a space.)

magic magic

Wildcard characters . (dot), * (asterisk), and [ ] (brackets) have special meaning in patterns.

mesg mesg Permit system messages to display on terminal while editing in vi.
number (nu) nonu Display line numbers on left of screen during editing session.
open open Allow entry to open mode from ex.
optimize (opt) noopt

Abolish carriage returns at the end of lines when printing multiple lines, speeds output on dumb terminals when printing lines with leading white space (blanks or tabs).

paragraphs= (para> IPLPPPQP LIpplpipbp

Define paragraph delimiters for movement by { or }. The pairs of characters in the value are the names of nroff/troff macros that begin paragraphs.

prompt prompt

Display the ex prompt (:) when vi's Q command is given.

readonly (ro) noro

Any writes (saves) of a file will fail unless you use ! after the write (works with w , ZZ , or autowrite ).

redraw (re) noredraw

Terminal redraws screen whenever edits are made (in other words, insert mode pushes over existing characters, and deleted lines immediately close up). Default depends on line speed and terminal type. noredraw is useful at slow speeds on a dumb terminal: deleted lines show up as , and inserted text appears to overwrite existing text until you press ESC.

remap remap Allow nested map sequences.
report= 5

Display a message on the prompt line whenever you make an edit that affects at least a certain number of lines. For example, 6dd reports the message "6 lines deleted."

scroll= <1/2 window> Amount of screen to scroll.
sections= (sect) SHNHH HU

Define section delimiters for [[ ]] movement. The pairs of characters in the value are the names of nroff/troff macros that begin sections.

shell= (sh) /bin/sh

Pathname of shell used for shell escape ( :! ) and shell command ( :sh ). Default value is derived from SHELL variable, which varies on different systems.

shiftwidth= (sw) 8

Define number of spaces in backward ( ^D ) tabs when using the autoindent option.

showmatch (sm) nosm

In vi, when ) or } is entered, cursor moves briefly to matching ( or {. (If match is not on the screen, rings the error message bell.) Very useful for programming.

showmode noshowmode

In insert mode, displays a message on the prompt line indicating the type of insert you are making. For example, "Open Mode," or "Append Mode."

slowopen (slow)

Hold off display during insert. Default depends on line speed and terminal type.

tabstop= (ts) 8

Define number of spaces that a TAB indents during editing session. (Printer still uses system tab of 8.)

taglength= (tl) 0

Define number of characters that are significant for tags. Default (zero) means that all characters are significant.

tags= /usr/lib/tags tags

Define pathname of files containing tags (see the UNIX ctags command.) By default, the system looks for files tags (in the current directory) and /usr/lib/tags .

term= Set terminal type.
terse noterse Display shorter error messages.
timeout (to) timeout Keyboard maps "time out" after 1 second.
ttytype= Set terminal type.
warn warn

Display the message, "No write since last change."

window= (w)

Show a certain number of lines of the file on the screen. Default depends on line speed and terminal type.

wrapmargin= (wm) 0

Define right margin. If greater than zero, automatically inserts carriage returns to break lines.

wrapscan (ws) ws Searches wrap around either end of file.
writeany (wa) nowa Allow saving to any file.

8.10.3 Example .exrc File

set nowrapscan wrapmargin=7
set sections=SeAhBhChDh nomesg
map q :w^M:n^M
map v dwElp
ab ORA O'Reilly & Associates, Inc.

Previous: 8.9 Alphabetical List of Keys UNIX in a Nutshell: System V Edition Next: 9. The Ex Editor
8.9 Alphabetical List of Keys Book Index 9. The Ex Editor

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System