Some common problems with Vi and Ex have been solved in Viper. This includes better implementation of existing commands, new commands, and the facilities provided by Emacs.
The Vi command set is based on the idea of combining motion commands with other commands. The motion command is used as a text region specifier for other commands. We classify motion commands into point commands and line commands.
The point commands are:
h, l, 0, $, w, W, b, B, e, E, (, ), /, ?, `, f, F, t, T, %, ;, ,, ^
The line commands are:
j, k, +, -, H, M, L, {, }, G, ', [[, ]], []
If a point command is given as an argument to a modifying command, the region determined by the point command will be affected by the modifying command. On the other hand, if a line command is given as an argument to a modifying command, the region determined by the line command will be enlarged so that it will become the smallest region properly containing the region and consisting of whole lines (we call this process expanding the region), and then the enlarged region will be affected by the modifying command. Text Deletion Commands (See section Deleting Text), Change commands (See section Changing Text), even Shell Commands (See section Shell Commands) use these commands to describe a region of text to operate on. Thus, type dw to delete a word, >} to shift a paragraph, or !'afmt to format a region from `point' to textmarker `a'.
Viper adds the region specifiers `r' and `R'. Emacs has a special marker called mark. The text-area between the current cursor position point and the mark is called the region. `r' specifies the raw region and `R' is the expanded region (i.e., the minimal contiguous chunk of full lines that contains the raw region). dr will now delete the region, >r will shift it, etc. r,R are not motion commands, however. The special mark is set by m. and other commands. See section Marking, for more info.
Viper also adds counts to most commands for which it would make sense.
In the Overview chapter, some Multiple File issues were discussed
(See section Multiple Files in Viper). In addition to the files, Emacs has
buffers. These can be seen in the :args list and switched using
:next if you type :set ex-cycle-through-non-files t, or
specify (setq ex-cycle-through-non-files t)
in your `.vip'
file. See section Customization, for details.
Viper provides multiple undo. The number of undo's and the size is limited by the machine. The Viper command u does an undo. Undo can be repeated by typing . (a period). Another u will undo the undo, and further . will repeat it. Typing u does the first undo, and changes the direction.
Since the undo size is limited, Viper can create backup files and auto-save files. It will normally do this automatically. It is possible to have numbered backups, etc. For details, see section `Backup and Auto-Save' in The GNU Emacs Manual
The results of the 9 previous changes are available in the 9 numeric registers, as in Vi. The extra goody is the ability to view these registers, in addition to being able to access them through p and M-y (See section Insert State, for details.) The Viper command ] register will display the contents of any register, numeric or alphabetical. The related command [ textmarker will show the text around the textmarker. `register' and `textmarker' can be any letters from a through z.
History is provided for Ex commands, Vi searches, file names, pieces of text inserted in earlier commands that use Insert or Replace state, and for destructive commands in Vi state. These are useful for fixing those small typos that screw up searches and :s, and for eliminating routine associated with repeated typing of file names or pieces of text that need to be inserted frequently. At the : or / prompts in the Minibuffer, you can do the following:
The history of insertions can be perused by typing C-c M-p and C-c M-n while in Insert or Replace state. The history of destructive Vi commands can be perused via the same keys when Viper is in Vi state. See section Viper Specials, for details.
All Ex commands have a file history. For instance, typing :e, space and then M-p will bring up the name of the previously typed file name. Repeatedly typing M-p, M-n, etc., will let you browse through the file history.
Similarly, commands that have to do with switching buffers have a buffer history, and commands that expect strings or regular expressions keep a history on those items.
Viper facilitates the use of Emacs-style keyboard macros. @# will start a macro definition. As you type, the commands will be executed, and remembered (This is called "learn mode" in some editors.) @register will complete the macro, putting it into `register', where `register' is any character from `a' through `z'. Then you can execute this macro using @register. It is, of course, possible to yank some text into a register and execute it using @register. Typing @@, @RET, or @LF will execute the last macro that was executed using @register.
Viper will automatically lowercase the register, so that pressing the SHIFT key for @ will not create problems. This is for @ macros and "p only. In the case of y, "Ayy will append to register a. For [,],',`, it is an error to use a Uppercase register name.
The contents of a register can be seen by ]register. ([textmarker will show the contents of a textmarker).
The last keyboard macro can also be executed using *, and it can be yanked into a register using @!register. This is useful for Emacs style keyboard macros defined using C-x( and C-x). Emacs keyboard macros have more capabilities. See section `Keyboard Macros' in The GNU Emacs Manual, for details.
Keyboard Macros allow an interesting form of Query-Replace: /pattern or n to go to the next pattern (the query), followed by a Keyboard Macro execution @@ (the replace).
Viper also provides Vi-style macros. See section Vi Macros, for details.
Completion is done when you type TAB. The Emacs completer does not grok wildcards in filenames. Once you type a wildcard, the completer will no longer work for that path. Remember that Emacs interprets a file name of the form /foo//bar as /bar and /foo/~/bar as ~/bar.
Viper provides buffer search, the ability to search the buffer for a region under the cursor. You have to turn this on in `.vip' either by calling
(vip-buffer-search-enable)
or by setting vip-buffer-search-char
to, say, f3:
(setq vip-buffer-search-char [f3])
If the user calls vip-buffer-search-enable
explicitly (the first
method), then vip-buffer-search-char
will be set to g.
Regardless of how this feature is enabled, the key
vip-buffer-search-char
will take movement commands, like
w,/,e, to find a region and then search for the contents of that
region. This command is very useful for searching for variable names, etc.,
in a program. The search can be repeated by n or reversed by N.
Emacs provides incremental search. As you type the string in, the cursor will move to the next match. You can snarf words from the buffer as you go along. Incremental Search is normally bound to C-s and C-r. See section Customization, to find out how to change the bindings of C-r or C-s. For details, see section `Incremental Search' in The GNU Emacs Manual
Viper also provides a query replace function that prompts through the Minibuffer. It is invoked by the Q key in Vi state.
On a window display, Viper supports mouse search, i.e., you can search for a word by clicking on it. See section Viper Specials, for details.
Finally, on a window display, Viper highlights search patterns as it finds
them. This is done through what is known as faces in Emacs. The
variable that controls how search patterns are highlighted is
vip-search-face
.
If you don't want any highlighting at all, put
(copy-face 'default 'vip-search-face)
in `~/.vip'. If you want to change how patterns are highlighted, you
will have to set the variable vip-search-face
to some other face,
such as highlight
. If none of the existing faces fits the bill, you
may have to create your own. Further details on faces can be found
in the Emacs Lisp Manual.
It is possible in Emacs to define abbrevs based on the contents of the buffer. Sophisticated templates can be defined using the Emacs abbreviation facilities. See section `Abbreviations' in The GNU Emacs Manual, for details.
Emacs also provides Dynamic Abbreviations. Given a partial word, Emacs
will search the buffer to find an extension for this word. For instance,
one can type `Abbreviations' by typing `A', followed by a keystroke
that completed the `A' to `Abbreviations'. Repeated typing
will search further back in the buffer, so that one could get
`Abbrevs' by repeating the
keystroke, which appears earlier in the text. Emacs binds this to
ESC /, so you will have to find a key and bind the function
dabbrev-expand
to that key.
Facilities like this make Vi's :ab command obsolete.
Viper can be set free from the line--limited movements in Vi, such as l refusing to move beyond the line, ESC moving one character back, etc. These derive from Ex, which is a line editor. If your `.vip' contains
(setq vip-ex-style-motion nil)
the motion will be a true screen editor motion. One thing you must then watch out for is that it is possible to be on the end-of-line character. The keys x and % will still work correctly, i.e., as if they were on the last character.
The word-movement commands w, e, etc., and the associated
deletion/yanking commands, dw, yw, etc., can be made to
understand Emacs syntax tables. If the variable
vip-syntax-preference
is set to 'strict-vi
(the default) then
the meaning of word is the same as in
Vi. However, if the value is 'reformed-vi
then the alphanumeric
symbols will be those specified by the current Emacs syntax table (which
may be different for different major modes) plus the underscore symbol
_
. The user can also specify the value 'emacs
, which would
make Viper use exactly the Emacs notion of word. In particular, the
underscore may not be part of a word. Finally, if
vip-syntax-preference
is set to 'extended
, Viper words would
consist of characters that are classified as alphanumeric or as
parts of symbols. This is convenient for writing programs and in many other
situations.
vip-syntax-preference
is a local variable, so it can have different
values for different major modes. For instance, in programming modes it can
have the value 'extended
. In text modes where words contain special
characters, such as European (non-English) letters, Cyrillic letters, etc.,
the value can be 'reformed-vi
or 'emacs
.
Changes to vip-syntax-preference
should be done in the hooks to
various major modes. Furthermore, for these changes to take effect, you
should execute (vip-update-alphanumeric-class)
right after changing
The above discussion of the meaning of Viper's words concerns only Viper's
movement commands. In regular expressions, words remain the same as in
Emacs. That is, the expressions \w
, \>
, \<
, etc., use
Emacs' idea of what is a word, and they don't look into the value of
variable vip-syntax-preference
. This is because Viper doesn't change
syntax tables in fear of upsetting the various major modes that set these
tables.
Textmarkers in Viper remember the file and the position, so that you can switch files by simply doing 'a. If you set up a regimen for using Textmarkers, this is very useful. Contents of textmarkers can be viewed by [marker. (Contents of registers can be viewed by ]register).
These commands have no Vi analogs.
vip-no-multiple-ESC
to nil
in `.vip'. See section Customization. C-z
in Insert state will make Emacs think Meta has been hit.(setq vip-re-query-replace nil)
in your `.emacs' file to
turn this off. (For normal searches, :se nomagic will work. Note
that :se nomagic turns Regexps off completely, unlike Vi).
downcase-region
).
Emacs command M-l does the same for words.
upcase-region
).
Emacs command M-u does the same for words.
vip-global-execute
).vip-quote-region
).
spell-region
).
The function used for spelling is determined from the variable
vip-spell-function
.
Apart from the new commands, many old commands have been enhanced. Most notably, Vi style macros are much more powerful in Viper than in Vi. See section Vi Macros, for details.
Some Emacs packages are mentioned here as an aid to the new Viper user, to indicate what Viper is capable of. A vast number comes with the standard Emacs distribution, and many more exist on the net and on the archives.
This manual also mentions some Emacs features a new user should know about. The details of these are found in the GNU Emacs Manual.
The features first. For details, look up the Emacs Manual.
The packages, below, represents a drop in the sea of special-purpose packages that come with standard distribution of Emacs 19.
ange-ftp.el
can ftp from the editor to files on other machines
transparent to the user.
vc.el
for doing RCS commands from inside the editor
dired.el
for editing contents of directories and for navigating in
the file system.
hilit19.el
and font-lock.el
for automatic highlighting
various parts of a buffer
using different fonts and colors.
desktop.el
for saving/restoring configuration on Emacs exit/startup.
ispell.el
for spell checking the buffer, words, regions, etc.
ediff.el
for finding differences between files and for applying
patches.
Emacs Lisp archives exist on `archive.cis.ohio-state.edu' and `wuarchive.wustl.edu'