Norm Matloff's Elvis Web Page

Professor Norm Matloff's Elvis Web Page

Check these first!

The documentation on elvis is a huge as the Manhattan phone directory. Actually, it is very well organized, in an HTML format. (At least mostly; also see the file elvis.man for command-line options.) Here is some quick information on some of the features:

Mouse operations:

If you are using elvis in an X11 environment, the mouse can be used very effectively. (In some cases you may be in this environment but wish not to use it, in which case you can put in the option "-G termcap" in the elvis command line.)

Here are some mouse operations:

Subwindows within elvis:

Type

   :sp

to split the current elvis image into two subwindows. This way you get to look at two parts of the file at the same time. If you are running elvis in ordinary terminal mode, the screen will split into two parts, while under X11 windows, the second subwindow will actually come up as a second window. (Keep in mind that either way, the two subwindows are views into the same file. If, however, you had originally invoked elvis on multiple files, then you can change the second window to another file by uisng the :b command.) Of course, you can then hit :sp again to make more windows.

For example, if you are editing a program source file, you can look at a call to a function in one subwindow and the function declaration in the other one. Note that you can move around independently within the various windows; for example, you can do a `/' search in one subwindow while the other subwindow cursor positions remain fixed.

If you are in X11, to move from one subwindow to the other simply move the mouse. In ordinary terminal mode, type

:window ++
I use this often, so I have it aliased to `,' in my ~/.elvisrc startup file:

map , :window ++^M
I then simply hit the comma key to go from one subwindow to the other when I am in this mode.

To delete a subwindow, type

:q

from within that subwindow.

Infinite undo/redo:

In ordinary vi, you hit the u key to undo only the most recent change. In elvis, you can keep hitting u, undoing many changes; if you hit the u key n times, you cancel the last n changes you've made to the file. This is VERY useful.

If you undo a change but then decide you want to make the change anyway---in other words, you want to ``undo the undo''---hit control-r. This will undo the most recent undo. Hitting control-r n times undoes the n most recent undo's.

However, unlike say, vim, there is a limit on this n, which you must set in your elvis startup file, say ~/.elvisrc. The documentation advises not setting the limit too high; I have this line in the file:

set undolevels=12

Paragraph formatting:

I use this constantly. It makes a paragraph of text look nicer, by making all the lines about equal length. This is especially nice when you are writing e-mail; if you send nicely-formatted paragraphs, the recipient will find the reading more pleasant.

To invoke this operation, type

{=}

which I have aliased to `q' in my ~/.elvisrc file:

map q {=}

Note that, unlike vim, elvis calls upon an external program named fmt to do this formatting. If such a program is not already on your system, one does come with the elvis source code distribution; compile it ("make fmt") and place it somewhere in your search path.

In any case, I strongly suggest using as your format program par. It handles the `>' marks in e-mail replies better than do standard fmt programs. You can specify using this as your format program by the "equalprg" setting in your elvis startup file. I also recommend that you set the environment variable used by par as recommended in the documentation:

setenv PARINIT "rTbgqR B=.?_A_a Q=_s>|"

Startup (initialization) files:

I recommend that you place your elvis-specific startup commands in a file ~/.elvisrc, and have that file source your general vi startup commands from ~/.exrc. This way you can keep the latter in case you wish to use more than one version of vi, not just elvis. So, near the beginning of the ~/.elvisrc place a line


source ~/.exrc

in order to have elvis uses the startup information from ~/.exrc.

To make elvis use ~/.elvisrc as its startup file, always invoke elvis as

elvis  -c "source ~/.elvisrc" name_of_file_to_be_edited

Read-only viewing of a file:

To view a file on a read-only basis, invoke elvis with the -R option on the command line.

coordinating compiling with elvis

Say you are using elvis to edit a file a.c. While a.c is still in elvis, you can type

:cc

to invoke the C compiler, or more generally, type

:make
to run the "make" program.

If there are compiler errors, you can keep typing

:errlist
to move the cursor successively to the various lines where errors were found. You may wish to alias this in your ~/.elvisrc, say as

map e :errlist^M

or much better, set up an X11 icon for it, as shown below.

Setting up neat X11 icons:

This is a really nice feature of elvis.

Here is an example from my ~/.elvisrc:


if gui=="x11"
then  {
   gui Save:w
   gui ExitNoSave:q!
   gui Split:sp
   gui Unsplit:q
   gui Make:make
   gui GoToError:errlist
   color blue on white
   set blinktime=0
}

This says that if elvis senses that it is being run under X11 (it will check the DISPLAY environment variable), then it will set up icons at the top of the elvis window, labeled Save and Split which will execute ":w" and ":sp" when clicked with the mouse.

The general form of such a command is

gui label:ex_command
where "ex_command" means any vi/elvis command invoked via ":".

The line concerning blinktime turns off the blinking of the cursor under X11, which I find bothersome.

The line "color blue on white" specifies blue letters on a white background; any X11 colors may be used.

I also use my Make icon when I am editing LaTeX files. Say my LaTeX source file is z.tex. Then I create a Makefile with contents

z.dvi: z.tex
TAB latex z.tex

While editing z.tex, when I wish to see an update (say I have xdvi running), I simply click on Save and then on Make.

HTML and TeX/LaTeX modes:

Starting with version 2.1j, elvis has (limited) ability to display HTML and follow URL links. If your Web pages are mostly text, you will find that this features allows you to use elvis as a primitive but very handy HTML editor---nice, in that you can use your familiar vi keystrokes for HTML editing.

Most of my Web pages are primarily text (including the one you are now reading), so I find this feature of elvis extremely convenient. I can make some changes to an HTML file, then quickly and easily switch elvis to HTML mode to view my changes, and then switch back to "normal" (vi) mode to make further changes. I can even make some of my changes while still in HTML mode. (See the documentation for the elvis author's advice on using elvis as an HTML editor.)

To use this feature, invoke elvis on the file, and then type

:display html

(I have this mapped to # in my .elvisrc file.) Moving the cursor to a link and hit return (or double-click with the mouse) to follow the link. (You may have to type ":display html" there too, if elvis does not automatically recognize the file there as consisting of HTML). Hit control-t to go back. To return to ordinary vi mode, type

:display normal

(which I have mapped to ^ in my .elvisrc file).

In my .elvisrc file I use the vi abb (abbreviation) command a lot for usage of elvis for HTML editing. Here is an excerpt:

 

map ^ :disp normal^M
map # :disp html^M
abb pr <P>
abb br <BR>
abb ahref <A HREF=""> </A>
abb h1 <H1> </H1>
...
...

For more sophisticated, WYSIWYG HTML editing, I use amaya, which is excellent.

Elvis also features a TeX/LaTeX mode, accessed via

:display tex

Man-page mode:

The Unix man pages, usually having a suffix of .1 or .man, need to be processed by a command like "nroff -man" to be read easily. Elvis can do it for you too. As an example, try viewing elvis.man using elvis, and typing

:display man

Recovery after a system crash or power failure:

There is quite a bit in the HTML elvis manual on this. Elvis's "-r" option will perform this operation on the previous session file. Such a file is created each time you use elvis, either in your home directory or somewhere else such as /usr/tmp (depending how elvis was configured at compile time).