Section 9.5. vi Configuration


9.5. vi Configuration

This section describes the following:

  • The :set command

  • Options available with :set

  • Sample .exrc file

9.5.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 does not need to be typed if the command is put in .exrc:

Command

Action

:set x

Enable boolean option x, show value of other options.

:set nox

Disable option x.

:set x=value

Give value to option x.

:set

Show changed options.

:set all

Show all options.

:set x?

Show value of option x.


9.5.2. Options Used by :set

Table 9-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. The last column describes what the option does, when enabled.

This table lists set options for vi, with the addition of important vim options. Other versions of vi may have more or fewer or different options. See your local documentation, or use :set all to see the full list. Options that receive a value are marked with an =.

Table 9-1. :set Options

Option

Default

Description

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 a command such as :n, or before giving Unix command with :!.

background (bg)

 

Describe the background so the editor can choose appropriate highlighting colors. Default value of dark or light depends on the environment in which the editor is invoked. {vim}

backup (bk)

nobackup

Create a backup file when overwriting an existing file. {vim}

backupdir= (bdir)

.,~/tmp/,~/

Name directories in which to store backup files if possible. The list of directories is comma-separated and in order of preference. {vim}

beautify (bf)

nobf

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

backupext= (bex)

~

String to append to filenames for backup files. {vim}

cindent (cin)

nocindent

In insert mode, indent each line relative to the one above it, as is appropriate for C or C++ code. {vim}

compatible (cp)

cp

Make vim behave more like vi. Default is nocp when a ~/.vimrc file is found. {vim}

directory (dir)

/tmp

Name of directory in which ex/vi stores buffer files. (Directory must be writable.) This can be a comma-separated list for vim.

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 does this.

equalprg= (ep)

 

Use the specified program for the = command. When the option is blank (the default), the key invokes the internal C indention function or the value of the indentexpr option. {vim}

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.

formatprg= (fp)

 

The gq command will invoke the named external program to format text. It will call internal formatting functions when this option is empty (the default). {vim}

gdefault (gd)

nogdefault

Set the g flag on for substitutions by default. {vim}

hardtabs= (ht)

8

Define boundaries for terminal hardware tabs.

hidden (hid)

nohidden

Hide buffers rather than unload them when they are abandoned. {vim}

hlsearch (hls)

hlsearch

Highlight all matches of most recent search pattern. Use :nohlsearch to remove highlighting. {vim}

history= (hi)

20

Number of ex commands to store in the history table. {vim}

ignorecase (ic)

noic

Disregard case during a search.

incsearch (is)

noincsearch

Highlight matches to a search pattern as it is typed. {vim}

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.

mousehide (mh)

mousehide

When characters are typed, hide the mouse pointer. {vim}

novice

nonovice

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.

open

open

Allow entry to open or visual mode from ex. Although not in vim, this option has traditionally been in vi, and may be in your 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)

IPLPPPQPP LIpplpipnpbp

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

paste

nopaste

Change the defaults of various options to make pasting text into a terminal window work better. All options are returned to their original value when the paste option is reset. {vim}

prompt

prompt

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. noredraw is useful at slow speeds on a dumb terminal: the screen isn't fully updated until you press Escape. Default depends on line speed and terminal type.

remap

remap

Allow nested map sequences.

report=

5

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."

ruler (ru)

ruler

Show line and column numbers for the current cursor position. {vim}

scroll=

[1/2 window]

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

sections= (sect)

SHNHH HUnhsh+c

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 used when the indent in increased or decreased.

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.

showmode

noshowmode

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.

smartcase (scs)

nosmartcase

Override the ignorecase option when a search pattern contains uppercase characters. {vim}

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.)

tagstack

tagstack

Enable stacking of tag locations on a stack. (Solaris vi and vim.)

term=

 

Set terminal type.

terse

noterse

Display shorter error messages.

textwidth= (tw)

0

The maximum width of text to be inserted; longer lines are broken after whitespace. Default (zero) disables this feature, in which case wrapmargin is used. {vim}

timeout (to)

timeout

Keyboard maps timeout after 1 second.[a]

timeoutlen= (tm)

1000

Number of milliseconds after which keyboard maps timeout. Default value of 1000 provides traditional vi behavior. {vim}

ttytype=

 

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

undolevels= (ul)

1000

Number of changes that can be undone. {vim}

warn

warn

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.

wrap

 

When on, long lines wrap on the screen. When off, only the first part of the line is displayed. {vim}

wrapmargin (wm)

0

Define right margin. If greater than zero, vi 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.

writebackup (wb)

wb

Back up files before attempting to overwrite them. Remove the backup when the file has been successfully written, unless the backup option is set. {vim}


[a] 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.

9.5.3. Sample .exrc File

The following lines of code are an example of a customized .exrc file:

      set nowrapscan                      " Searches don't wrap at end of file      set wrapmargin=7                    " Wrap text at 7 columns from right margin      set sections=SeAhBhChDh nomesg      " Set troff macros, disallow message      map q :w^M:n^M                      " Alias to move to next file      map v dwElp                         " Move a word      ab ORA O'Reilly Media, Inc.         " Input shortcut 

NOTE

The q alias isn't needed for vim, which has the :wn command. The v alias would hide the vim command v, which enters character-at-a-time visual-mode operation.



Linux in a Nutshell
Linux in a Nutshell
ISBN: 0596154488
EAN: 2147483647
Year: 2004
Pages: 147

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net