Setting Parameters


You can tailor the vim editor to your unique needs and habits by setting vim parameters. Parameters perform such functions as displaying line numbers, automatically inserting RETURNs for you, and establishing incremental and nonstandard searches.

You can set parameters in several ways. For example, you can set them to establish the environment for the current editing session while you are using vim. Alternatively, you can set the parameters in your ~/.bash_profile (bash) or ~/.login (tcsh) shell startup file or in the vim startup file, ~/.vimrc. When you set the parameters in any of these files, each time you use vim, the environment has been established and you can begin editing immediately.

Setting Parameters from Within vim

To set a parameter while you are using vim, enter a colon (:), the word set, a SPACE, and the parameter (refer to "Parameters" on page 181). The command appears on the status line as you type it and takes effect when you press RETURN. The following command establishes incremental searches for the current editing session:

:set incsearch


Setting Parameters in a Startup File

VIMINIT

If you are using bash, you can put a line with the following format in your ~/.bash_profile startup file (page 259):

export VIMINIT='set param1 param2 ...'


Replace param1 and param2 with parameters selected from Table 6-7. VIMINIT is a shell variable that vim reads. The following statement ignores the case of characters in searches, displays line numbers, uses the TC Shell to execute shell commands, and wraps text 15 characters from the right edge of the screen:

export VIMINIT='set autoindent number shell=/bin/tcsh wrapmargin=15'


Table 6-7. Parameters

Parameter

Effect

Allow special characters in searches
magic

Refer to "Special Characters in Search Strings" on page 170. By default the following characters have special meanings when used in a search string:

. [ ] *


When you set the nomagic parameter, these characters no longer have special meanings. The magic parameter restores their special meanings.

The ^ and $ characters always have special meanings within search strings, regardless of how you set this parameter.

Automatic indention
autoindent, ai

The automatic indention feature works with the shiftwidth parameter to provide a regular set of indentions for programs or tabular material. This feature is off by default. You can turn it on by setting autoindent and turn it off by setting noautoindent.

When automatic indention is on and vim is in Input mode, CONTROL-T moves the cursor from the left margin (or an indention) to the next indention position, RETURN moves the cursor to the left side of the next line under the first character of the previous line, and CONTROL-D backs up over indention positions. The CONTROL-T and CONTROL-D keys work only before text is placed on a line.

Automatic write
autowrite, aw

By default vim asks you before writing out the Work buffer when you have not explicitly told it to do so (as when you give a :n command to edit the next file). The autowrite option causes vim to write the Work buffer automatically when you use commands, such as :n, to edit to another file. You can disable this parameter by setting the noautowrite or noaw option.

Flash
flash, fl

The vim editor normally causes the terminal to beep when you give an invalid command or press ESCAPE when it is in Command mode. Setting the parameter flash causes the terminal to flash instead of beep. Set noflash to cause it to beep. Not all terminals and emulators support this parameter.

Ignore case in searches
ignorecase, ic

The vim editor normally performs case-sensitive searches, differentiating between uppercase and lowercase letters. It performs case-insensitive searches when you set the ignorecase parameter. Set noignorecase to restore case-sensitive searches.

Incremental search
incsearch, is

Refer to "Normal Versus Incremental Searches" on page 169. By default vim does not perform incremental searches. To cause vim to perform incremental searches, set the parameter incsearch. To cause vim not to perform incremental searches, set the parameter noincsearch.

Invisible characters
list

To cause vim to display each TAB as ^l and to mark the end of each line with a $, set the list parameter. To display TABs as whitespace and not mark ends of lines, set nolist.

Status line
laststatus=n, Is=n

Displays a status line that shows the name of the file you are editing, a [+] if the file has been changed since it was last written out, and the position of the cursor. Set the parameter laststatus=n, where n is 0 (zero) to turn off the status line, 1 to display the status line when at least two windows are displayed, or 2 to always display the status line.

Line numbers
number, nu

The vim editor does not normally display the line number associated with each line. To display line numbers, set the parameter number. To cause line numbers not to be displayed, set the parameter nonumber.

Line numbers are not part of the file, are not stored with the file, and are not displayed when the file is printed. They appear on the screen only while you are using vim.

Line wrap
wrap

The line wrap controls how vim displays lines that are too long to fit on the screen. To cause vim to wrap long lines and continue them on the next line, set wrap (set by default). If you set nowrap, vim truncates long lines at the right edge of the screen.

Line wrap margin
wrapmargin=nn, wm=nn

The line wrap margin causes vim to break the text that you are inserting at approximately the specified number of characters from the right margin. The vim editor breaks the text by inserting a NEWLINE character at the closest blank-delimited word boundary. Setting the line wrap margin is handy if you want all your text lines to be about the same length. It relieves you of having to remember to press RETURN to end each line of input.

Set the parameter wrapmargin=nn, where nn is the number of characters from the right side of the screen where you want vim to break the text. This number is not the column width of the text but the distance from the end of the text to the right edge of the screen. Setting the wrap margin to 0 (zero) turns this feature off. By default the line wrap margin is off (set to 0).

Report
report=nn

Causes vim to display a report on the status line whenever you make a change that affects at least nn lines. For example, if report is set to 7 and you delete seven lines, vim displays the message 7 lines deleted. When you delete six or fewer lines, vim does not display a message. The default for report is 5.

Scroll
scroll=nn, scr=nn

Controls the number of lines that CONTROL-D and CONTROL-U (page 162) scroll text on the screen. By default scroll is set to half the window height.

There are two ways to change the value of scroll. First you can enter a number before giving a CONTROL-D or CONTROL-U command; vim sets scroll to that number. Alternatively, you can set scroll explicitly with scroll=nn, where nn is the number of lines you want to scroll with each CONTROL-D or CONTROL-U command.

Shell
shell=path, sh=path

While you are using vim, you can cause it to spawn a new shell. You can either create an interactive shell (if you want to run several commands) or run a single command. The shell parameter determines which shell vim invokes. By default vim sets the shell parameter to your login shell. To change it, set the parameter shell=path, where path is the absolute pathname of the shell you want to use.

Shift width
shiftwidth=nn, sw=nn

Controls the functioning of CONTROL-T and CONTROL-D in Input mode when automatic indention is on (see "Automatic indention" in this table). Set the parameter shiftwidth=nn, where nn is the spacing of the indention positions (8 by default). Setting the shift width is similar to setting the TAB stops on a typewriter; with shiftwidth, however, the distance between TAB stops remains constant.

Show match
showmatch, sm

Useful for programmers working in languages that use braces ({}) or parentheses as expression delimiters (Lisp, C, Tcl, and so on). When showmatch is set and you are entering code (in Input mode) and type a closing brace or parenthesis, the cursor jumps briefly to the matching opening brace or parenthesis (that is, the preceding corresponding element at the same nesting level). After it highlights the matching element, the cursor resumes its previous position. When you type a right brace or parenthesis that does not have a match, vim beeps. Use noshowmatch to turn off automatic matching.

Show mode
showmode, smd

Set the parameter showmode to display the mode in the lower-right corner of the screen when vim is in Input mode (default). Set noshowmode to cause vim not to display the mode.

vi compatibility
compatible, cp

Refer to "The compatible Parameter" on page 153. By default except when you have a .vimrc startup file (page 180), vim attempts to be compatible with vi. To cause vim to be compatible with vi, set the parameter compatible. To cause vim not to be compatible with vi, set the parameter nocompatible.

Wrap scan
wrapscan, ws

By default when a search for the next occurrence of a search string reaches the end of the Work buffer, vim continues the search at the beginning of the Work buffer. The reverse is true of a search for the previous occurrence of a search string. The nowrapscan parameter stops the search at either end of the Work buffer. Set the wrapscan parameter if you want searches to wrap around the ends of the Work buffer.


If you use the parameter abbreviations, it looks like this:

export VIMINIT='set ai nu sh=/bin/tcsh wm=15'


If you are using tcsh, put the following line in your ~/.tcshrc startup file (page 340).

setenv VIMINIT 'set param1 param2 ...'


Again, replace param1 and param2 with parameters from Table 6-7. The values between the single quotation marks are the same as shown in the preceding examples.

The .vimrc Startup File

Instead of setting vim parameters in your shell startup file, you can create a ~/.vimrc file in your home directory and set them there. Creating a .vimrc file causes vim to start with the compatible parameter unset (page 153). Lines in a .vimrc file use the following format:

set param1 param2 ...


Following are examples of .vimrc files that perform the same function as VIMINIT described previously:

$ cat ~/.vimrc set ignorecase set number set shell=/bin/tcsh set wrapmargin=15 $ cat ~/.vimrc set ic nu sh=/bin/tcsh wm=15


Parameters set by the VIMINIT variable take precedence over those set in the .vimrc file.

Parameters

Table 6-7 lists some of the most useful vim parameters. The vim editor displays a complete list of parameters and indicates how they are currently set when you give the command :set all followed by a RETURN. The command :set RETURN displays a list of options that are set to values other than their default values. Two classes of parameters exist: those that contain an equal sign (and can take on a value) and those that are optionally prefixed with no (switches that are on or off). You can change the sense of a switch parameter by giving the command :set [no]param. For example, give the command :set number (or :set nonumber) to turn on (or off) line numbering. To change the value of a parameter that takes on a value (and uses an equal sign), give a command such as :set shiftwidth=15.

Most parameters have abbreviations such as nu for number, nonu for no number, and sw for shiftwidth. The abbreviations are listed in the left column of Table 6-7, following the name of the parameter.




A Practical Guide to UNIX[r] for Mac OS[r] X Users
A Practical Guide to UNIX for Mac OS X Users
ISBN: 0131863339
EAN: 2147483647
Year: 2005
Pages: 234

Similar book on Amazon

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