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


10.10 Interesting Features

elvis has a number of interesting features:

Internationalization support

Like nvi , elvis also has a home-grown method for allowing translations of messages into different languages. The elvis.msg file is searched for along the elvispath and loaded into a buffer named Elvis messages .

Messages have the form "terse message : long message. " Before printing a message, elvis looks up the terse form, and if there is a corresponding long form, that message is used. Otherwise, the terse message is used.

Display modes

This is perhaps the most interesting of elvis ' features. For certain kinds of files, elvis formats the file content on the screen, giving a surprisingly good approximation of a WYSIWYG effect. elvis can also use the same formatting for printing the buffer to several kinds of printers. Display modes get their own subsection, below.

Pre- and post-operation command files

elvis loads four files (if they exist), that allow you to customize its behavior before and after reading and writing a file. This feature also gets its own subsection, below.

Open mode

elvis is the only one of the clones that actually implements vi 's open mode. (Think of open mode as like vi , but with only a one-line window. The "advantage" to open mode is that it can be used on terminals that don't have cursor motion capabilities.)

Security

The :safer command sets the safer option for execution of non-home-directory .exrc files, or any other untrusted files. When safer is set, "certain commands are disabled, wildcard expansion in filenames is disabled, and certain options are locked (including the safer option itself)". The elvis documentation is no more specific than this; don't blindly trust elvis to provide complete security for you.

Built-in calculator

elvis extends the ex command language with a built-in calculator (sometimes referred to as an expression evaluator in the documentation). It understands C expression syntax, and is most used in the :if , :calc , and :eval commands. See the online help for the details, as well as the sample initialization files in the elvis distribution for examples.

Macro debugger (2.1)

elvis 2.1 has a debugger for vi macros (the :map command). This can be useful when writing complicated input or command maps.

10.10.1 Display Modes

elvis has several display modes. Depending on the kind of file, elvis produces a formatted version of the file, producing a WYSIWYG effect. The display modes are outlined in Table 10.11 .


Table 10.11: elvis Display Modes
Mode Display Appearance
normal

No formatting, displays your text as it exists in the file.

syntax

Like normal , but with syntax coloring turned on.

hex

An interactive hex dump, reminiscent of mainframe hex dumps. This is good for editing binary files.

html

A simple Web page formatter. The tag commands can be used to follow links and return.

man

Simple man page formatter. Like the output of nroff -man .

The :normal command will switch the display from one of the formatted views to normal mode. Use :display mode to switch back. As a shortcut, the ^W d command will toggle the display modes for the window.

Of the available modes, html and man are the most WYSIWYG in nature. The online documentation clearly defines the subset of both markup languages that elvis understands.

elvis uses the html mode for displaying its online help, which is written in HTML and has many cross-referencing links within it.

The example below shows elvis editing one of the HTML help files. The screen is split. Both windows show the same buffer; the bottom window is using the html display mode, while the top is using the normal display mode:

<html><head>
<title>Elvis 2.0 Sessions</title>
</head><body>

<h1>10. SESSIONS, INITIALIZATION, AND RECOVERY</h1>

This section of the manual describes the life-cycle of an
edit session. We begin with the definition of an
<a href="#SESSION">edit session</a> and
what that means to elvis.
This is followed by sections discussing
<a href="#INIT">initialization</a>
and <a href="#RECOVER">recovery after a crash.</a>
_____________________________________________________________________


10.0 SESSIONS, INITIALIZATION, AND RECOVERY


        This section of the manual describes the life-cycle of an
        edit session. We begin with the definition of an edit
        session
 and what that means to elvis. This is
        followed by sections discussing initialization
 and 
        recovery after a crash.


    10.1 Sessions

The man mode is also interesting, since normally you have to format and print a man page to be sure you've done a decent job of laying it out. The following quote from the online help seems appropriate.

Troff source was never designed to be interactively edited, and although I did the best I could, attempting to edit in man mode is still a disorienting experience. I suggest you get in the habit of using normal mode when making changes, and man mode to preview the effect of those changes. The ^W d command makes switching between modes a pretty easy thing to do.

As an interesting adjunct, both the html and man modes also work with the :color command described in Section 10.9.2, "Syntax Highlighting" . This is particularly nice with man mode. For example, by default on a Linux console, only bold text (.B) is distinguishable from normal text. But with syntax coloring on, both bold and italic (.I) text become distinct. The mode commands are summarized in Table 10.12 .


Table 10.12: elvis Display Mode Commands
Command Function
di [splay ] [mode [lang ]]

Change the display mode to mode . Use lang for syntax mode.

no[rmal ]

Same as :display normal , but much easier to type.

Associated with each window is the bufdisplay option, which should be set to one of the supported display modes. The standard elvis.arf file (see the next subsection) will look at the extension of the buffer's filename and attempt to set the display to a more interesting mode than normal .

Finally, elvis can also apply its WYSIWYG formatting to printing the contents of a buffer. The :lpr command formats a line range (or the whole buffer, by default) for printing. You can print to a file or down a pipe to a command. By default, elvis prints to a pipe that executes the system print spooling command.

The :lpr command is controlled by several options, described in Table 10.13 .


Table 10.13: elvis Options for Print Management
Option Function
lptype , lp

The printer type.

lpconvert , lpcvt

If set, convert Latin-8 extended ASCII to PC-8 extended ASCII.

lpcrlf , lpc

The printer needs CR-LF to end each line.

lpout , lpo

The file or command to print to.

lpcolumns , lpcols

The printer's width.

lpwrap , lpw

Simulate line wrapping.

lplines , lprows

The length of the printer's page.

lpformfeed , lpff

Send a form-feed after the last page.

lppaper , lpp

The size of the paper (letter, a4, etc.). This only matters for PostScript printers.

Most of the options are self-explanatory. elvis supports several printer types, as described in Table 10.14 .


Table 10.14: Values for the lptype Option
Name Printer Type
ps

PostScript, one logical page per sheet of paper.

ps2

PostScript, two logical pages per sheet of paper.

epson

Most dot-matrix printers, no graphic characters supported.

pana

Panasonic dot-matrix printers.

ibm

Dot-matrix printers with IBM graphic characters.

hp

Hewlett-Packard printers, and most non-PostScript laser printers.

cr

Line printers, overtyping is done with carriage-return.

bs

Overtyping is done via backspace characters. This setting is the closest to traditional UNIX nroff .

dumb

Plain ASCII, no font control.

If you have a PostScript printer, by all means use an lptype of ps or ps2 . Use the latter to save paper, which is particularly handy when printing drafts.

10.10.2 Pre- and Post-Operation Control Files

elvis gives you the ability to control its actions at four points when reading and writing files: before and after reading a file, and before and after writing a file. It does this by executing the contents of four ex scripts at those respective points. These scripts are searched for using the directories listed in the elvispath option.

elvis.brf

This file is executed Before Reading a File. The default version looks at the file's extension, and attempts to guess whether or not the file is binary. If it is, the binary option is turned on, to prevent elvis from converting newlines (which may be actual CR-LF pairs in the file) into linefeeds internally.

elvis.arf

This file is executed After Reading a File. The default version examines the file's extension in order to turn on syntax highlighting.

elvis.bwf

This file is executed Before Writing a File, in particular, before completely replacing an original file with the contents of the buffer. The default version implements copying the original file to a file with a .bak extension. You must set the backup option for this to work.

elvis.awf

This file is executed After Writing a File. There is no default file for this, although it might be a good place to add hooks into a source code control system.

The use of command files to control these actions is quite powerful. It allows you to easily tailor elvis ' behavior to suit your needs; in other editors these kinds of features are much more hardwired into the code.


Previous: 10.9 Programming Assistance Learning the vi Editor Next: 10.11 elvis Futures
10.9 Programming Assistance Book Index 10.11 elvis Futures

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