If you're using Elvis to view this file, you can search for a topic simply by using the / command. To limit the search to topic lines only, begin the regular expression with "^<dt>.*". For example you could search for "spaces" in a topic line via the following:
/^<dt>.*spaces
Sometimes there are multiple topics that use the same word or phrase. If the first one that it finds isn't the one you want, then you can use the n command to find the next one.
In addition, the lib/elvis.ali script distributed with Elvis contains a :howto alias which loads this file and searches for a given topic. The aliases from lib/elvis.ali are loaded automatically, so you should be able to display any topic in a a separate window via a command such as this:
:howto spaces
Alternatively, you could use the :au command, with an event such as BufRead.
/* ex:set bufdisplay="syntax c": */
Alternatively, you could modify the
elvis.arf script to detect
your type of file, and set the bufdisplay
option appropriately.
For example, adding the following line into elvis.arf
would
cause any file that looks like a patch to be displayed using "syntax cdiff"
1s/---\|***/set bufdisplay="syntax cdiff"/g
If you don't want to modify elvis.arf
, you could achieve
a similar effect via the BufReadPost
autocmd event.
knownsyntax()
function to check the
language, like this:
:if knownsyntax(filename) == "perl" :then set ccprg="perl -c ($1?$1:$2) 2>&1 | perlerr"
(The perlerr
Perl script converts perl's error messages
into a form that Elvis can parse.
It is given in the Tips chapter.)
You could also use the dirext()
function to check the filename
extension directly, instead of knownsyntax()
;
it doesn't depend on the lib/elvis.syn file.
As a last resort, you might consider using the x
flag of
the :s command.
~/.exrc
file changes the default for all buffers/windows.
However, the lib/elvis.brf and lib/elvis.arf files typically change some of those options, so the defaults might not be used very long before they're changed.
.elvisrc
and runs it if it exists;
else it looks for .exrc
and runs that.
If you want Elvis to run both of them, then add the following line
to your .elvisrc
file:
:source ~/.exrc
Now Elvis has a prefersyntax
option, which makes this pretty easy.
Just run ":set prefersyntax=writable
".
The :mkexrc command always completely overwrites whatever file it writes to. Because of this, you must save your hand-coded initialization commands in a separate file. In the following example, we'll store the hand-coded commands in ~/.elvisrc and allow :mkexrc to store the automatically generated commands in ~/.elvismkexrc.
elvis ~/.elvisrc
". This starts Elvis, loads your
settings, and then starts editing the ~/.elvisrc file.
:mkexrc ~/.elvismkexrc
".
This will change the mkexrcfile
option to ~/.elvismkexrc, and then write your current settings out
to that file.
The settings will include "set mkexrcfile=~/.elvismkexrc
",
so when you load those settings again later, ~/.elvismkexrc will become
the default file used by the :mkexrc
command.
source ~/.elvismkexrc
" command line.
This way, when Elvis runs the ~/.elvisrc script during startup, it'll
automatically run the commands in ~/.elvismkexrc too.
(Elvis ex history)
buffer to "tab".
You can do that via the following command:
:(Elvis ex history)set inputtab=tab
(Elvis regexp history)
buffer, like this:
:(Elvis regexp history)set inputtab=tab
.exrc
file
(or elvis.rc
for non-Unix systems).
The command is:
:set inputtab=identifier
After that, each time you hit the <Tab> key Elvis will search through the tags file for any matching tags, and add as many characters as possible. If it completes the entire tag name, it does not append a space or other character, which is a little different from other types of name completion. Also, in the syntax display mode it will not attempt completion if the partial word happens to be a complete keyword or "other" word.
In Elvis, you can set the inputtab option to "spaces" to make the <Tab> key insert the appropriate number of spaces into a line. This works even if the cursor isn't in the line's indentation whitespace.
In addition, the autotab option controls the shifting commands (the :< and :> commands in ex, and the < and > operators in visual mode). To make those commands use only spaces, autotab should be off.
:set inputtab=spaces noautotab
To convert existing files to use only spaces, you should use an external
program such as "col -bx
" under Unix.
Alternatively, you can use Elvis to change the indentation
(but not tabs elsewhere in a line)
to use only spaces by shifting the entire file right, and then left again
while the noautotab setting is in effect.
However, you almost certainly do not want to change the
tabstop option because most other
software, and most printers and terminals, also assume that tabs are 8
characters wide.
If you edit files with tabstop
set to 4 or 5, then your
files will look very strange when viewed with anything other than Elvis,
or by anyone other than you.
So leave tabstop=8
.
Instead, set the shiftwidth option to the desired indentation amount, and either get in the habit of typing ^T to increase indentation, or :map! the <Tab> key to ^T in input mode.
:set shiftwidth=5 :map! ^V^I ^V^T
Note that when you're typing in the above :map
command,
you'll need to type an extra ^V before each ^V
or ^T.
Also, this map has the unfortunate side-effect of making the <Tab> increase indentation even if the cursor is somewhere later in the line (unless you type ^V before it). This is one good reason to skip the map, and get in the habit of using ^T to increase indentation. The autotab option helps here, too.
:(#1
Or you can switch to "main.c" like this:
:(main.c
Of course, the buffer must exist before you can switch to it. Another thing to keep in mind is, switching buffers doesn't necessarily force you to save the old buffer first. Any changes you made to the old buffer are not lost -- you can switch back to the original buffer again if you wish.
:(#1)split
Or, create a window showing the "main.c" buffer:
:(main.c)split
(Elvis cut buffer X)
, where X is the name
of the cut buffer (a single letter or digit).
Consequently, you could create a window showing cut buffer "a
like this:
:(Elvis cut buffer a)split
Of course, the "a
cut buffer must exist for this to work.
Since the name is so long, Elvis supports a special short-hand notation
for cut buffer names.
In parentheses, if the first character is " and the remainder of the buffer
name is a single letter, then Elvis uses the buffer which contains that
cut buffer's contents.
The following command also creates a window showing the "a
cut buffer:
:("a)sp
Elvis doesn't store "undo" versions for cut buffers, and you can't yank a buffer into itself. Other than that, editing should be pretty normal. The type of data in the buffer (characters, lines, or rectangle) is stored in an option named putstyle.
-Gtermcap
flag.
If you do this often, you may wish to create a shell script, alias, or shell
function which runs Elvis with -Gtermcap
.
Here's an example of shell script:
#!/bin/sh exec elvis -Gtermcap "$@"
If you never want to use the "x11" user interface, then you should probably reconfigure Elvis to leave it out. This will make Elvis considerably smaller. To do this, go into the directory where Elvis' source code resides and execute the following shell commands:
make clean configure --with-x=no make
The solution is to add an explicit -Gx11
command line flag
when it is invoked from a window manager's menu.
.exrc
file:
:set blinktime=0
:color cursor red on green
.exrc
file, you can set the
font,
boldfont, and
italicfont options to anything you want.
(Fixed-pitch only!)
These settings will override the defaults.
If you set only the font
and leave the others unset,
then Elvis will derive the others from the normal font.
:set font=7x14
If you just want to use a smaller size of the Courier font, you can use the :courier alias. It takes a single parameter: the point size of the font to use. The default font is 18-point Courier, and most systems also have 12-, 14-, and 24-point Courier fonts which work well.
:courier 14
The simplest way to change the font is to pass Elvis a
-fc
fontname parameter.
I suggest you use that to experiment with the available fonts, to find
one you like.
(You can use the standard xlsfonts
program to list the available
fonts.)
To make the change permanent, you can either set the controlfont option in your ~/.exrc file, or you can set the elvis.control.font resource in your ~/.Xdefaults file.
:!xeyes >/dev/null 2>&1 &
If you want to write data out to the program (:w !program
)
then it becomes even more complex.
This is because pipes can only contain a finite amount of data, so when
Elvis is redirecting stdin as well as stdout/stderr, it uses a temporary
file for stdin.
Elvis deletes that file as soon as the program returns -- which, for a program
run in parallel, happens immediately even though the program hasn't had a chance
to read the data from that file yet.
The solution is to write the data into a temporary file sequentially, and
then start a parallel command line which runs the program and then deletes
the temporary file, like this:
:w !cat >$$; (xv $$; rm $$) >/dev/null 2>&1 &
Yes, that's nasty. I plan to clean that up some day, by making Elvis smart enough to avoid reading stdout/stderr when the command line ends with a '&' character.
However, by using the "termcap" interface inside an xterm,
you should be able to run interactive programs such as "crypt" or "pgp"
exactly as you can under vi.
In an xterm (or any other terminal emulator), just run
"elvis -Gtermcap
" instead of plain "elvis
".
Buttons 5
' and `ZAxisMapping 4 5
'.
Also, for serial mice you may need to specify
`Protocol "Intellimouse"
';
for PS/2 mice, tryProtocol "IMPS/2"
'.
The Rxvt terminal emulator and most Gtk/Gnome programs will also support
the scroll wheel when it is configured this way.
In addition, many other programs can be configured to support it by specifying
the appropriate translations in their app-defaults.
For example, Netscape can be configured to respond to the scroll wheel by
inserting the following lines into the
Netscape*drawingArea.translations
resource string:
<Btn4Down>: LineUp() \ LineUp() \ LineUp() \ LineUp() \ LineUp() \n\ <Btn5Down>: LineDown() \ LineDown() \ LineDown() \ LineDown() \ LineDown() \n\
There is also a program named "imwheel" which can be configured to translate wheel motions into <PgUP> and <PgDn> keystrokes (or other keys) for specific applications.
But it you really want to do this, then you should add the following line to the end of your lib/elvis.arf file:
try cd (dirdir(filename))
Although there is no PRN: device, Windows98 does allow you to associate an LPTn: device with a print queue, via mechanism called "capturing a printer port". I suggest you configure your computer's default print queue to capture LPT9:, and the set Elvis' lpout option to "LPT9". The steps for capturing the printer port are:
After that, you just need to set up Elvis. Give Elvis the command
":set lpout=lpt9
", and then ":mkexrc
".
You're done!
"C:\usr\bin\WinElvis.exe" "%1"
That should be all that is required. Double-clicking on files of that type will now cause WinElvis to open that file, and if you right-click on the file you'll see "Open with Elvis" as one of the options.
#!/bin/sh
".
One nice trick is to use the x
flag of Elvis'
:s command.
It not only detects text, but can incorporate that text into the commands.
For example, to compute the total of all numbers in all lines, you could...
:set t=0 :%s/\<[[:digit:]]\+\>/let t = t + &/gx :set t?
Note that this series of commands does not affect the edit buffer.
The x
flag prevents the substitution from taking place;
the replacement text is executed instead.
You can also use the :try command to run a search command, and then use :then and :else to act differently depending on whether the search succeeded or not.
:try /Yow! :then echo Zippy was here :else echo Where in the world is Zippy the Pinhead?
You can also use the current("word")
and line()
functions to fetch the word at the cursor
location, or a whole line, respectively.
:let w=current("word") :let l=line(1)
!
) and
the long option name, followed by a ?
character.
(For non-Boolean options, the ?
is optional.)
:set! wrapmargin?
This will produce output like "win.wm=0", indicating that the short name is "wm", the group name is "win" (so each window has its own margin), and the value is 0.
elvis -r
" to start a new Elvis process on the
old session file, and then use the :buffer
command to list the buffers.
You can then use other commands to save those buffers; for example, to
save a buffer named "main.c" into a file named "main.c.recovered", you
would give this command:
:(main.c)w main.c.recovered
However, it is usually possible to construct a little "filter" program to convert other error message formats into one that Elvis can recognize. The Tips chapter has an example of how to make Elvis handle PERL's error messages.
If you're having trouble displaying non-ASCII characters, then you may want to look into the nonascii option. Also, on Unix systems you should verify that your terminal is configured correctly (8 bits, not 7 -- and the Latin-1 character set is installed).
The most straightforward way to do this is to use the !(default)% notation. Specifically, !(.)% will make any command in an alias default to using just the current line, and !(%)% will make any command default to using all lines.
Here's a simple word-counting alias which uses this technique to count the words in all lines by default...
alias wcw { local w=0 !(%)% s/\w\+/let w=w+1/gx calc w }
Note that the :g command can be used with an address range. This is often convenient.
Here's an alias which uses this technique to search for the longest line (assuming all characters are of equal width -- no tabs or control characters)...
alias widest { local w=0 l !%g/^/ { if strlen(line()) > w then let w = strlen(line()) then let l = current("line") } calc "Line" l "is the longest, at" w "characters." }
alias inregion { normal mz !%g/^/ { if current("region") == "!1" then !2* } normal `z }
And here's an example of how to use it. This example converts any lines in a "mixed" region to uppercase.
:inregion mixed s/.*/\U&/
The most straightforward method is to build an alias which performs a series of substitutions. The problem with this method is that it must be rewritten for each type of input text. Here's an example of a fairly simple alias that converts plain text to HTML. (There is a more powerful version of :makehtml in the standard distribution's elvis.ali file.)
alias makehtml { "Convert plain text to HTML local report=0 " "Protect characters which are special to HTML try !(%)%s/&/\&/g try !(%)%s/</\</g try !(%)%s/>/\>/g " "Convert blank lines to <p> tags try !(%)s/^$/<p>/ " "If converting the whole file, then add <html>...</html> if "!%" == "" then { $a </body></html> 1i <html><body> } }
The other way is simpler and more versatile, but it requires the use of an external file. It uses the :lpr command with lptype=html. Since Elvis' print mechanism supports all of Elvis' display modes, you can use this technique to convert any type of text (or even a hex dump of a binary file) into HTML. The main disadvantage of this method is, the resulting HTML is rendered exactly as it looks on the screen -- so plain text basically just has <pre> and </pre> wrapped around it, nothing else.
:set lptype=html lplines=0 nolpheader :lp foo.html
:map select B c<strong>^P</strong>^[(Note: When typing that :map command into Elvis, you'll need to type <Ctrl-V><Ctrl-P> to get the ^P, and <Ctrl-V><Esc> to get the ^[ character.)
:au OptChanged lines,columns message (columns)x(lines)
elvis --version
"), and your operating system.
For general bug reports, you should contact the primary author, Steve Kirkendall, at kirkenda@cs.pdx.edu.
Either way, be sure to mention the version of Elvis you're using (as reported by "elvis --version"), and your operating system.