Book HomeBook TitleSearch this book

8.10. Setting Up vi

This section describes the following:

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 xEnable option x.
:set noxDisable option x.
:set x=valGive value to option x.
:setShow changed options.
:set allShow all options.
:set x?Show value of option x.

8.10.2. Options Used by :set

Table 8-1 contains brief descriptions of the important set command options. In the first column, options are listed in alphabetical order; if the option can be abbreviated, that abbreviation is shown in parentheses. The second column shows the default setting vi uses unless you issue an explicit set command (either manually or in the .exrc file). The last column describes what the option does, when enabled.

Table 8-1. :set Options

OptionDefaultDescription
autoindent (ai)noai

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

autoprint (ap)ap

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

autowrite (aw)noaw

Automatically write (save) the 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 directory in which ex/vi stores buffer files. (Directory must be writable.)

edcompatible

noedcompatible

Remember the flags used with the most recent substitute command (global, confirming) and use them for the next substitute command. Despite the name, no version of ed actually behaves this way.

errorbells (eb)errorbellsSound 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.

lispnolisp

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

listnolist

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

magicmagic

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

mesgmesg

Permit system messages to display on terminal while editing in vi.

novicenonovice

Require the use of long ex command names, such as copy or read.

number (nu)nonu

Display line numbers on left of screen during editing session.

openopen

Allow entry to open or visual mode from ex. Although not in Solaris vi, this option has traditionally been in vi, and may be in your Unix's version of vi.

optimize (opt)noopt

Abolish carriage returns at the end of lines when printing multiple lines; speed output on dumb terminals when printing lines with leading whitespace (spaces or tabs).

paragraphs (para)

IPLPPPQP LIpplpipbp

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

promptprompt

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

readonly (ro)noro

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

redraw (re) 

vi redraws the 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 Escape.

remapremap

Allow nested map sequences.

report5

Display a message on the status 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[½ window]

Number of lines to scroll with ^D and ^U commands.

sections (sect)SHNHH HU

Define section delimiters for [[ and ]] movement. The pairs of characters in the value are the names of 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 environment, which varies on different systems.

shiftwidth (sw)8

Define number of spaces in backward (^D) tabs when using the autoindent option, and for the << and >> commands.

showmatch (sm)nosm

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

showmodenoshowmode

In insert mode, display 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 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

tags /usr/lib/tags

Define pathname of files containing tags. (See the Unix ctags command.) (By default, vi searches the file tags in the current directory and /usr/lib/tags.)

tagstacktagstack

Enable stacking of tag locations on a stack.

term Set terminal type.
tersenoterse

Display shorter error messages.

timeout (to)timeout

Keyboard maps time out after 1 second.[9]

ttytype 

Set terminal type. This is just another name for term.

warnwarn

Display the warning 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.

wrapscan (ws)ws

Searches wrap around either end of file.

wrapmargin (wm)0

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

writeany (wa)nowaAllow saving to any file.

[9] When you have mappings of several keys (for example, :map zzz 3dw), you probably want to use notimeout. Otherwise you need to type zzz within 1 second. When you have an insert mode mapping for a cursor key (for example, :map! ^[OB ^[ja), you should use timeout. Otherwise, vi won't react to Escape until you type another key.

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.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.