UNIX Hints & Hacks |
||||||||||||||||||||||||||||||||
Chapter 8: Editors |
|
|||||||||||||||||||||||||||||||
|
The vi editor has 60 reserved settings that you can configure. Although you probably will not use all of them, there are some that aid you in whatever task you are trying to achieve.
The following is a list of the available reserved settings that you can manipulate and that enable you to function more easily within vi. To view the configurations of the parameters in your current vi session, go into the command mode and issue the command set all .
:set all
Or
:setall
Don't forget to begin the command with a colon ( :) to execute the command set all . A list of current settings for all the available parameters is displayed:
noautoindent flipcase="" nonumber nosync autoprint nohideformat nooptimize tabstop=8 autotab noignorecase paragraphs="PPppIPLPQP" taglength=0 noautowrite noinputmode prompt tags="tags" nobeautify keytime=2 noreadonly tagstack cc="cc -c" keywordprg="ref" remap term="vt100" nocharattr lines=24 report=5 noterse columns=80 nolist noruler timeout nodigraph magic nosafer warn directory="/tmp" make="make" scroll=11 window=0 noedcompatible mesg sections="NHSHSSSEse" wrapmargin=0 equalprg="fmt" nomodelines shell="/bin/csh" wrapscan errorbells more noshowmatch nowriteany noexrc nearscroll=24 noshowmode exrefresh newfile shiftwidth=8 noflash nonovice sidescroll=8
Even though many parameters can be set within vi, you will use only a small number of them. Here are some of the more important parameters you should be aware of and possibly modify for your particular needs. To change any of the settings, again use the set command while in the command mode.
Syntax:
:set option
:set nooption
:set option=nn
Autoindentation--The autoindent parameter works with the shiftwidth=nn setting. nn is the number of spaces that vi uses as a regular set of indentations for programs and tabular documents. In the insert mode, use Ctrl-T to move the cursor from the left margin to the next indentation position. Using Ctrl-D backs up over the indentation position, similar to a Backtab key.
Case-sensitive searches --When a search pattern is entered, the normal search performed by vi is set to case-sensitive by having the parameter set to noignorecase. This can be turned off with the ignorecase setting. If certain log files or auto-generated reports are brought into the vi editor, you might not know whether the keywords you're looking for are upper or lowercase.
Shell--In vi, it is possible to spawn a new shell. There is a parameter shell=pathname available that you can set to the type of shell you want to use. Set pathname to the actual shell you want to spawn, for example /bin/csh. When you are working in the new shell, don't forget that the shell was created. It is easy to get pulled away and at the end of the day log off the system, forgetting that you had a vi session open and the contents where never saved.
Show mode --If you are new to the vi editor you might want to toggle this to showmode. By default, it is disabled and set to noshowmode. When this parameter is enabled and you are in insert mode, the right corner of the screen displays INSERT MODE . When you enter command mode, nothing is displayed.
Terminal settings --Within vi, there are various terminal-related parameters available for setting. Depending on your flavor, there is windows=nn or lines=nn for the visual size of the screen, columns=nn, and term="termtype" you are using.
Wrap margin -- The wrapmargin=nn parameter enables you to continue typing without having to type the Enter key. It is similar to the effect you experience on a word processor when you exceed the right margin setting and the full typed word wraps to the next line. The setting of nn does not equal the distance from the beginning of the line; rather, it is the distance in characters from the right side of the screen. By default the setting is 0, which disables the wrapping of text. Be aware that word wrapping works only while text is being written to a line for the first time. If text is appended to a previously wrapped line, the text will continue past the wrapmargin setting.
There are six common parameters that require more modifications than any of the others. There are a couple places where you can hardcode the modifications so that the parameters will be set to your preference each time you go into vi.
Any changes you want to make to the vi parameters can be hardcoded into the variable EXINIT from inside the startup file for the shell that you are logging in to the system with. Declare the EXINIT variable by passing the settings of each parameter to the variable. Separate each command with a space or a vertical bar ( |), depending on the versions of vi you are using. If one doesn't work try the other.
Place the necessary parameters into the .profile in your home directory if you are using the Bourne or Korn shells:
EXINIT='autoindent wrapmargin=5 showmode' export EXINIT
If you use the csh or tcsh shells then make the additions to your .cshrc or .login file.
setenv EXINIT 'set autoindent|wrapmargin=5|showmode'
You have to reference your startup files again for the EXINIT variable to take effect. When this is finished, verify that the variable was set correctly:
% set TERM=vt100 SHELL=/bin/csh MAIL=/var/mail/ugu PWD=/local/home/user/ugu EXINIT=set autoindent list wrapmargin=40
When the variable is confirmed and valid, go into the vi editor and execute :set from the command mode and you should see the changes you placed in your startup file.
:set autoindent wrapmargin=40 showmode
The vi editor also supports a configuration file called .exrc that is read when vi is executed. When vi is started, it looks for the .exrc file in the current directory from which vi was started. If there is no .exrc file in this directory, it checks for the existence of the .exrc file in the home directory of the account that is logged in.
Use this file to set any parameters that you want vi to have when it starts up. The .exrc file accepts multiple parameter settings on a single line or one parameter per line.
vi .exrc
" Indent lines and show modes set autoindent showmode " " Wrap the text 10 characters from the end set wrapmargin=10 " " Number each of the line set number
When the entries are made in the .exrc file, start vi back up on the file you want to edit. A :set command shows that the settings configured in .exrc were accepted.
% vi /tmp/foobar :set autoindent showmode wrapmargin=10 number
Everyone has the ability to configure settings within vi to provide the ease-of-use that people look for in applications, and, of course, you are always looking for ways to make your routine operations easier.
The vi editor is a versatile editor from any point of view. When you use it to create a program and write source code, the editor can automatically indent and number each line and, in general, make source code creation much easier than it is with a plain text editor. Even if you decide to use it only for creating text files, documentation, or Web pages, vi can be configured to wrap text around to a new line and display its different modes when you toggle between the text. These features help speed up editing and modification times.
Man pages:
set, vi
World Wide Web:
Sven's VI Setup File-- http://www.math.fu-berlin.de/~guckes/vi/exrc
Vi settings options-- http://www.linuxbox.com/~taylor/4ltrwrd/VRoptions.html
UNIX Hints & Hacks |
||||||||||||||||||||||||||||||||
Chapter 8: Editors |
|
|||||||||||||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.