We believe that one or more of the following statements are adequate descriptions of Viper:
Viper Is a Package for Emacs Rebels;
it is a VI Plan for Emacs Rescue
and/or a venomous VI PERil.
Technically speaking, Viper is a Vi emulation package for Emacs. It implements all Vi and Ex commands, occasionally improving on them and adding many new features. It gives the user the best of both worlds: Vi keystrokes for editing combined with the power of the Emacs environment.
Viper emulates Vi at several levels, from the one that closely follows Vi conventions to the one that departs from many of them. It has many customizable options, which can be used to tailor Viper to the work habits of various users. This manual describes Viper, concentrating on the differences from Vi and new features of Viper.
Viper, formerly known as VIP-19, was written by Michael Kifer. It is based on VIP version 3.5 by Masahiko Sato and VIP version 4.4 by Aamod Sane. About 15% of the code still comes from those older packages.
Viper is intended to be usable without reading this manual — the defaults are set to make Viper as close to Vi as possible. At startup, Viper will try to set the most appropriate default environment for you, based on your familiarity with Emacs. It will also tell you the basic GNU Emacs window management commands to help you start immediately.
Although this manual explains how to customize Viper, some basic familiarity with Emacs Lisp is a plus.
It is recommended that you read the Overview node. The other nodes may be visited as needed.
Comments and bug reports are welcome.
kifer@cs.stonybrook.edu is the current address for Viper bug reports.
Please use the Ex command :submitReport for this purpose.
Viper is a Vi emulation on top of Emacs. At the same time, Viper provides a virtually unrestricted access to Emacs facilities. Perfect compatibility with Vi is possible but not desirable. This chapter tells you about the Emacs ideas that you should know about, how to use Viper within Emacs and some incompatibilities.
This manual is written with the assumption that you are an experienced Vi user who wants to switch to Emacs while retaining the ability to edit files Vi style. Incredible as it might seem, there are experienced Emacs users who use Viper as a backdoor into the superior (as every Vi user already knows) world of Vi! These users are well familiar with Emacs bindings and prefer them in some cases, especially in the Vi Insert state. John Hawkins <jshawkin@eecs.umich.edu> has provided a set of customizations, which enables additional Emacs bindings under Viper. These customizations can be included in your ~/.viper file and are found at the following URL: http://traeki.freeshell.org/files/viper-sample.
Emacs can edit several files at once. A file in Emacs is placed in a buffer that usually has the same name as the file. Buffers are also used for other purposes, such as shell interfaces, directory editing, etc. See Directory Editor, for an example.
A buffer has a distinguished position called the point. A point is always between 2 characters, and is looking at the right hand character. The cursor is positioned on the right hand character. Thus, when the point is looking at the end-of-line, the cursor is on the end-of-line character, i.e. beyond the last character on the line. This is the default Emacs behavior.
The default settings of Viper try to mimic the behavior of Vi, preventing the cursor from going beyond the last character on the line. By using Emacs commands directly (such as those bound to arrow keys), it is possible to get the cursor beyond the end-of-line. However, this won't (or shouldn't) happen if you restrict yourself to standard Vi keys, unless you modify the default editing style. See Customization.
In addition to the point, there is another distinguished buffer position called the mark. See Mark, for more info on the mark. The text between the point and the mark is called the region of the buffer. For the Viper user, this simply means that in addition to the Vi textmarkers a–z, there is another marker called mark. This is similar to the unnamed Vi marker used by the jump commands `` and '', which move the cursor to the position of the last absolute jump. Viper provides access to the region in most text manipulation commands as r and R suffix to commands that operate on text regions, e.g., dr to delete region, etc.
Furthermore, Viper lets Ex-style commands to work on the current region. This is done by typing a digit argument before :. For instance, typing 1: will prompt you with something like :123,135, assuming that the current region starts at line 123 and ends at line 135. There is no need to type the line numbers, since Viper inserts them automatically in front of the Ex command.
See Basics, for more info.
Emacs divides the screen into tiled windows. You can see the contents of a buffer through the window associated with the buffer. The cursor of the screen is positioned on the character after point. Every window has a mode line that displays information about the buffer. You can change the format of the mode line, but normally if you see `**' at the beginning of a mode line it means that the buffer is modified. If you write out the contents of a buffer to a file, then the buffer will become not modified. Also if you see `%%' at the beginning of the mode line, it means that the file associated with the buffer is write protected. The mode line will also show the buffer name and current major and minor modes (see below). A special buffer called Minibuffer is displayed as the last line in a Minibuffer window. The Minibuffer window is used for command input output. Viper uses Minibuffer window for / and : commands.
An Emacs buffer can have a major mode that customizes Emacs for editing text of a particular sort by changing the functionality of the keys. Keys are defined using a keymap that records the bindings between keystrokes and functions. The global keymap is common to all the buffers. Additionally, each buffer has its local keymap that determines the mode of the buffer. If a function is bound to some key in the local keymap then that function will be executed when you type the key. If no function is bound to a key in the local map, however, the function bound to the key in the global map will be executed. See Major Modes, for more information.
A buffer can also have a minor mode. Minor modes are options that
you can use or not. A buffer in text-mode can have
auto-fill-mode as minor mode, which can be turned off or on at
any time. In Emacs, a minor mode may have it own keymap,
which overrides the local keymap when the minor mode is turned on. For
more information, see Minor Modes
Viper is implemented as a collection of minor modes. Different minor modes are involved when Viper emulates Vi command mode, Vi insert mode, etc. You can also turn Viper on and off at any time while in Vi command mode. See States in Viper, for more information.
Emacs uses Control and Meta modifiers. These are denoted as C and M, e.g. ^Z as C-z and Meta-x as M-x. The Meta key is usually located on each side of the Space bar; it is used in a manner similar to the Control key, e.g., M-x means typing x while holding the Meta key down. For keyboards that do not have a Meta key, <ESC> is used as Meta. Thus M-x is typed as <ESC> x. Viper uses <ESC> to switch from Insert state to Vi state. Therefore Viper defines C-\ as its Meta key in Vi state. See Vi State, for more info.
Emacs is structured as a Lisp interpreter around a C core. Emacs keys cause Lisp functions to be called. It is possible to call these functions directly, by typing M-x function-name.
The most common way to load it automatically is to include the following lines (in the given order!):
(setq viper-mode t)
(require 'viper)
in your ~/.emacs file. The .emacs file is placed in your home directory and it is be executed every time you invoke Emacs. This is the place where all general Emacs customization takes place. Beginning with version 20.0, Emacsen have an interactive interface, which simplifies the job of customization significantly.
Viper also uses the file ~/.viper for Viper-specific customization.
The location of Viper customization file can be changed by setting the
variable viper-custom-file-name in .emacs prior to loading
Viper.
The latest versions of Emacs have an interactive customization facility, which allows you to (mostly) bypass the use of the .emacs and .viper files. You can reach this customization facility from within Viper's VI state by executing the Ex command :customize.
Once invoked, Viper will arrange to bring up Emacs buffers in Vi state whenever this makes sense. See Packages that Change Keymaps, to find out when forcing Vi command state on a buffer may be counter-productive.
Even if your .emacs file does not invoke Viper automatically, you can still load Viper and enter the Vi command state by typing the following from within Emacs:
M-x viper-mode
When Emacs first comes up, if you have not specified a file on the command line, it will show the `*scratch*' buffer, in the `Lisp Interaction' mode. After you invoke Viper, you can start editing files by using :e, :vi, or v commands. (See File and Buffer Handling, for more information on v and other new commands that, in many cases, are more convenient than :e, :vi, and similar old-style Vi commands.)
Finally, if at some point you would want to de-Viperize your running
copy of Emacs after Viper has been loaded, the command M-x
viper-go-away will do it for you. The function toggle-viper-mode
toggles Viperization of Emacs on and off.
Viper has four states, Emacs, Vi, Insert, and Replace.
For users who chose to set their user level to 1 at Viper setup time,
switching to Emacs state is deliberately made harder in order to not
confuse the novice user. In this case, C-z will either iconify Emacs
(if Emacs runs as an application under X) or it will stop Emacs (if
Emacs runs on a dumb terminal or in an Xterm window).
In Viper, Ex commands can be made to work on the current Emacs region.
This is done by typing a digit argument before :.
For instance, typing 1: will prompt you with something like
:123,135, assuming that the current region starts at line 123 and
ends at line 135. There is no need to type the line numbers, since Viper
inserts them automatically in front of the Ex command.
The modes are indicated on the mode line as <E>, <I>, <V>, and <R>, so that the multiple modes do not confuse you. Most of your editing can be done in Vi and Insert states. Viper will try to make all new buffers be in Vi state, but sometimes they may come up in Emacs state. C-z will take you to Vi state in such a case. In some major modes, like Dired, Info, Gnus, etc., you should not switch to Vi state (and Viper will not attempt to do so) because these modes are not intended for text editing and many of the Vi keys have special meaning there. If you plan to read news, browse directories, read mail, etc., from Emacs (which you should start doing soon!), you should learn about the meaning of the various keys in those special modes (typing C-h m in a buffer provides help with key bindings for the major mode of that buffer).
If you switch to Vi in Dired or similar modes—no harm is done. It is just that the special key bindings provided by those modes will be temporarily overshadowed by Viper's bindings. Switching back to Viper's Emacs state will revive the environment provided by the current major mode.
States in Viper are orthogonal to Emacs major modes, such as C mode or Dired mode. You can turn Viper on and off for any Emacs state. When Viper is turned on, Vi state can be used to move around. In Insert state, the bindings for these modes can be accessed. For beginners (users at Viper levels 1 and 2), these bindings are suppressed in Insert state, so that new users are not confused by the Emacs states. Note that unless you allow Emacs bindings in Insert state, you cannot do many interesting things, like language sensitive editing. For the novice user (at Viper level 1), all major mode bindings are turned off in Vi state as well. This includes the bindings for key sequences that start with C-c, which practically means that all major mode bindings are unsupported. See Customization, to find out how to allow Emacs keys in Insert state.
You will be in this mode only by accident (hopefully). This is the state Emacs is normally in (imagine!!). Now leave it as soon as possible by typing C-z. Then you will be in Vi state (sigh of relief) :-).
Emacs state is actually a Viperism to denote all the major and minor modes (see Emacs Preliminaries) other than Viper that Emacs can be in. Emacs can have several modes, such as C mode for editing C programs, LaTeX mode for editing LaTeX documents, Dired for directory editing, etc. These are major modes, each with a different set of key-bindings. Viper states are orthogonal to these Emacs major modes. The presence of these language sensitive and other modes is a major win over Vi. See Improvements over Vi, for more.
The bindings for these modes can be made available in the Viper Insert state as well as in Emacs state. Unless you specify your user level as 1 (a novice), all major mode key sequences that start with C-x and C-c are also available in Vi state. This is important because major modes designed for editing files, such as cc-mode or latex-mode, use key sequences that begin with C-x and C-c.
There is also a key that lets you temporarily escape to Vi command state from the Insert state: typing C-z will let you execute a single Vi command while staying in Viper's Insert state.
This is the Vi command mode. When Viper is in Vi state, you will see the sign <V> in the mode line. Most keys will work as in Vi. The notable exceptions are:
viper-info-on-file
function instead.
Note: Emacs binds C-\ to a function that offers to change the keyboard input method in the multilingual environment. Viper overrides this binding. However, it is still possible to switch the input method by typing \ C-\ in the Vi command state and C-z \ C-\ in the Insert state. Or you can use the MULE menu in the menubar.
viper-undo.
csh regular expressions
(globbing, wildcards, what have you).
However, the function viper-toggle-search-style, bound to C-c /,
lets the user switch from search with regular expressions to plain vanilla
search and vice versa. It also lets one switch from case-sensitive search
to case-insensitive and back.
See Viper Specials, for more details.
The command :cd will change the default directory for the
current buffer. The command :e will interpret the
filename argument in csh. See Customization, if you
want to change the default shell.
The command :next takes counts from
:args, so that :rew is obsolete. Also, :args will show only
the invisible files (i.e., those that are not currently seen in Emacs
windows).
When applicable, Ex commands support file completion and history. This means that by typing a partial file name and then <TAB>, Emacs will try to complete the name or it will offer a menu of possible completions. This works similarly to Tcsh and extends the behavior of Csh. While Emacs is waiting for a file name, you can type M-p to get the previous file name you typed. Repeatedly typing M-p and M-n will let you browse through the file history.
Like file names, partially typed Ex commands can be completed by typing <TAB>, and Viper keeps the history of Ex commands. After typing :, you can browse through the previously entered Ex commands by typing M-p and M-n. Viper tries to rationalize when it puts Ex commands on the history list. For instance, if you typed :w! foo, only :w! will be placed on the history list. This is because the last history element is the default that can be invoked simply by typing : <RET>. If :w! foo were placed on the list, it would be all to easy to override valuable data in another file. Reconstructing the full command, :w! foo, from the history is still not that hard, since Viper has a separate history for file names. By typing : M-p, you will get :w! in the Minibuffer. Then, repeated M-p will get you through the file history, inserting one file name after another.
In contrast to :w! foo, if the command were :r foo, the entire command will appear in the history list. This is because having :r alone as a default is meaningless, since this command requires a file argument.
To avoid confusing the beginner (at Viper level 1 and 2), Viper makes only the standard Vi keys available in Insert state. The implication is that Emacs major modes cannot be used in Insert state. It is strongly recommended that as soon as you are comfortable, make the Emacs state bindings visible (by changing your user level to 3 or higher). See Customization, to see how to do this.
Once this is done, it is possible to do quite a bit of editing in Insert state. For instance, Emacs has a yank command, C-y, which is similar to Vi's p. However, unlike p, C-y can be used in Insert state of Viper. Emacs also has a kill ring where it keeps pieces of text you deleted while editing buffers. The command M-y is used to delete the text previously put back by Emacs' C-y or by Vi's p command and reinsert text that was placed on the kill-ring earlier.
This works both in Vi and Insert states. In Vi state, M-y is a much better alternative to the usual Vi's way of recovering the 10 previously deleted chunks of text. In Insert state, you can use this as follows. Suppose you deleted a piece of text and now you need to re-insert it while editing in Insert mode. The key C-y will put back the most recently deleted chunk. If this is not what you want, type M-y repeatedly and, hopefully, you will find the chunk you want.
Finally, in Insert and Replace states, Viper provides the history of pieces of text inserted in previous insert or replace commands. These strings of text can be recovered by repeatedly typing C-c M-p or C-c M-n while in Insert or Replace state. (This feature is disabled in the minibuffer: the above keys are usually bound to other histories, which are more appropriate in the minibuffer.)
You can call Meta functions from Insert state. As in Vi state, the Meta key is C-\. Thus M-x is typed as C-\ x.
Other Emacs commands that are useful in Insert state are C-e and C-a, which move the cursor to the end and the beginning of the current line, respectively. You can also use M-f and M-b, which move the cursor forward (or backward) one word. If your display has a Meta key, these functions are invoked by holding the Meta key and then typing f and b, respectively. On displays without the Meta key, these functions are invoked by typing C-\ f and C-\ b (C-\ simulates the Meta key in Insert state, as explained above).
The key C-z is sometimes also useful in Insert state: it allows you to execute a single command in Vi state without leaving the Insert state! For instance, C-z d2w will delete the next two words without leaving the Insert state.
When Viper is in Insert state, you will see <I> in the mode line.
This state is entered through Vi replacement commands, such as C, cw, etc., or by typing R. In Replace state, Viper puts <R> in the mode line to let you know which state is in effect. If Replace state is entered through R, Viper stays in that state until the user hits <ESC>. If this state is entered via the other replacement commands, then Replace state is in effect until you hit <ESC> or until you cross the rightmost boundary of the replacement region. In the latter case, Viper changes its state from Replace to Insert (which you will notice by the change in the mode line).
Since Viper runs under Emacs, it is possible to switch between buffers while in Replace state. You can also move the cursor using the arrow keys (even on dumb terminals!) and the mouse. Because of this freedom (which is unattainable in regular Vi), it is possible to take the cursor outside the replacement region. (This may be necessary for several reasons, including the need to enable text selection and region-setting with the mouse.)
The issue then arises as to what to do when the user hits the <ESC> key. In Vi, this would cause the text between cursor and the end of the replacement region to be deleted. But what if, as is possible in Viper, the cursor is not inside the replacement region?
To solve the problem, Viper keeps track of the last cursor position while it was still inside the replacement region. So, in the above situation, Viper would delete text between this position and the end of the replacement region.
The Minibuffer is where commands are entered in. Editing can be done by commands from Insert state, namely:
Most of the Emacs keys are functional in the Minibuffer. While in the Minibuffer, Viper tries to make editing resemble Vi's behavior when the latter is waiting for the user to type an Ex command. In particular, you can use the regular Vi commands to edit the Minibuffer. You can switch between the Vi state and Insert state at will, and even use the replace mode. Initially, the Minibuffer comes up in Insert state.
Some users prefer plain Emacs bindings in the Minibuffer. To this end, set
viper-vi-style-in-minibuffer to nil in .viper.
See Customization, to learn how to do this.
When the Minibuffer changes Viper states, you will notice that the appearance of the text there changes as well. This is useful because the Minibuffer has no mode line to tell which Vi state it is in. The appearance of the text in the Minibuffer can be changed. See Viper Specials, for more details.
Viper can edit multiple files. This means, for example that you never need
to suffer through No write since last change errors.
Some Viper elements are common over all the files.
There is one difference in text deletion that you should be
aware of. This difference comes from Emacs and was adopted in Viper
because we find it very useful. In Vi, if you delete a line, say, and then
another line, these two deletions are separated and are put back
separately if you use the `p' command. In Emacs (and Viper), successive
series of deletions that are not interrupted by other commands are
lumped together, so the deleted text gets accumulated and can be put back
as one chunk. If you want to break a sequence of deletions so that the
newly deleted text could be put back separately from the previously deleted
text, you should perform a non-deleting action, e.g., move the cursor one
character in any direction.
You should be aware that Emacs interprets /foo/bar//bla as /bla and /foo/~/bar as ~/bar. This is designed to minimize the need for erasing file names that Emacs suggests in its prompts, if a suggested file name is not what you wanted.
The command :cd will change the default directory for the current Emacs buffer. The Ex command :e will interpret the filename argument in `csh', by default. See Customization, if you want to change this.
Currently undisplayed files can be listed using the :ar command. The command :n can be given counts from the :ar list to switch to other files. For example, use `:n3' to move to the third file in that list.
Unimplemented features include:
cat -t -e file. Unfortunately, it cannot
be used directly inside Emacs, since Emacs will obdurately change `^I'
back to normal tabs.
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.
h, l, 0, $, w, W, b, B, e, E, (, ), /, ?, `, f, F, t, T, %, ;, ,, ^
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 Deleting Text), Change commands (see Changing Text), even Shell Commands (see 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 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 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 .viper
file. See 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 Backup and Auto-Save
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 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 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 @C-j 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 Keyboard Macros, 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 Vi Macros, for details.
Completion is done when you type <TAB>. The Emacs completer does not grok wildcards in file names. Once you type a wildcard, the completer will no longer work for that file name. 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 .viper either by calling
(viper-buffer-search-enable)
or by setting viper-buffer-search-char to, say, f3:
(setq viper-buffer-search-char ?g)
If the user calls viper-buffer-search-enable explicitly (the first
method), then viper-buffer-search-char will be set to g.
Regardless of how this feature is enabled, the key
viper-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 Customization, to find out how to change the bindings of C-r or C-s. For details, see Incremental Search
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 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
viper-search-face. If you don't want any highlighting at all, put
(copy-face 'default 'viper-search-face)
in ~/.viper. If you want to change how patterns are highlighted, you
will have to change viper-search-face to your liking. The easiest
way to do this is to use Emacs customization widget, which is accessible
from the menubar. Viper customization group is located under the
Emulations customization group, which in turn is under the
Editing group (or simply by typing :customize). All Viper
faces are grouped together under Viper's
Highlighting group.
Try it: it is really simple!
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 Abbreviations, 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 .viper contains
(setq viper-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
viper-syntax-preference is set to strict-vi then
the meaning of word is the same as in
Vi. However, if the value is reformed-vi (the default) 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 _, minus some non-word symbols, like '.;,|, etc.
Both strict-vi and reformed-vi work close to Vi in
traditional cases, but reformed-vi does a better job when editing
text in non-Latin alphabets.
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
viper-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.
viper-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 viper-syntax-preference should be done in the hooks to
various major modes by executing viper-set-syntax-preference as in
the following example:
(viper-set-syntax-preference nil "emacs")
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 viper-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.
viper-no-multiple-ESC to nil
in .viper. See Customization. C-\ in Insert, Replace, or Vi
states will make Emacs think Meta has been hit.
(setq viper-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.
viper-global-execute).
viper-quote-region). The default string is composed of the comment
character(s) appropriate for the current major mode.
spell-region).
The function used for spelling is determined from the variable
viper-spell-function.
In Vi state, these commands let the user peruse the history of Vi-style destructive commands, such as dw, J, a, etc. By repeatedly typing C-c M-p or C-c M-n you will cycle Viper through the recent history of Vi commands, displaying the commands one by one. Once an appropriate command is found, it can be executed by typing `.'.
Since typing C-c M-p is tedious, it is more convenient to bind an
appropriate function to a function key on the keyboard and use that key.
See Viper Specials, for details.
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 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.
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.
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'
Customization can be done in 2 ways.
(require
'viper) line. This method is not recommended, unless you know what
you are doing. Only two variables, viper-mode and
viper-custom-file-name, are supposed to be customized in .emacs,
prior to loading Viper (i.e., prior to (require 'viper) command.
Some advanced customization cannot be accomplished this way, however, and has to be done in Emacs Lisp in the .viper file. For the common cases, examples are provided that you can use directly.
An easy way to customize Viper is to change the values of constants used in
Viper. Here is the list of the constants used in Viper and their default
values. The corresponding :se command is also indicated. (The symbols
t and nil represent “true” and “false” in Lisp).
Viper supports both the abbreviated Vi variable names and their full names. Variable completion is done on full names only. <TAB> and <SPC> complete variable names. Typing `=' will complete the name and then will prompt for a value, if applicable. For instance, :se au <SPC> will complete the command to :set autoindent; :se ta <SPC> will complete the command and prompt further like this: :set tabstop = . However, typing :se ts <SPC> will produce a “No match” message because ts is an abbreviation for tabstop and Viper supports completion on full names only. However, you can still hit <RET> or =, which will complete the command like this: :set ts = and Viper will be waiting for you to type a value for the tabstop variable. To get the full list of Vi variables, type :se <SPC> <TAB>.
viper-auto-indent nil:se ai (:se autoindent):se ai-g (:se autoindent-global)t, enable auto indentation.
by <RET>, o or O command.
viper-auto-indent is a local variable. To change the value globally, use
setq-default. It may be useful for certain major modes to have their
own values of viper-auto-indent. This can be achieved by using
setq to change the local value of this variable in the hooks to the
appropriate major modes.
:se ai changes the value of viper-auto-indent in the current
buffer only; :se ai-g does the same globally.
viper-electric-mode tnil, auto-indentation becomes electric, which means that
<RET>, O, and o indent cursor according to the current
major mode. In the future, this variable may control additional electric
features.
This is a local variable: setq changes the value of this variable
in the current buffer only. Use setq-default to change the value in
all buffers.
viper-case-fold-search nil:se ic (:se ignorecase)nil, search ignores cases.
This can also be toggled by quickly hitting / twice.
viper-re-search nil:se magicnil, search will use regular expressions; if nil then
use vanilla search.
This behavior can also be toggled by quickly hitting / trice.
buffer-read-only:se ro (:se readonly)(setq-default buffer-read-only t) in your .emacs file.
blink-matching-paren t:se sm (:se showmatch)tab-width t (default setting via setq-default):se ts=value (:se tabstop=value):se ts-g=value (:se tabstop-global=value)tab-width is a local variable that controls the width of the tab stops.
To change the value globally, use setq-default; for local settings,
use setq.
The command :se ts sets the tab width in the current buffer only; it has no effect on other buffers.
The command :se ts-g sets tab width globally, for all buffers where the tab is not yet set locally, including the new buffers.
Note that typing <TAB> normally
doesn't insert the tab, since this key is usually bound to
a text-formatting function, indent-for-tab-command (which facilitates
programming and document writing). Instead, the tab is inserted via the
command viper-insert-tab, which is bound to S-tab (shift + tab).
On some non-windowing terminals, Shift doesn't modify the <TAB> key, so
S-tab behaves as if it were <TAB>. In such a case, you will have
to bind viper-insert-tab to some other convenient key.
viper-shift-width 8:se sw=value (:se shiftwidth=value)viper-search-wrap-around t:se ws (:se wrapscan)nil, search wraps around the end/beginning of buffer.
viper-search-scroll-threshold 2viper-tags-file-name "TAGS"viper-re-query-replace nilnil, use reg-exp replace in query replace.
viper-want-ctl-h-help nilnil, C-h is bound to help-command;
otherwise, C-h is bound as usual in Vi.
viper-vi-style-in-minibuffer tnil, Viper provides a high degree of compatibility with Vi
insert mode when you type text in the Minibuffer; if nil, typing in
the Minibuffer feels like plain Emacs.
viper-no-multiple-ESC tnil, you can use <ESC> as Meta in Vi state.
Normally, this is not necessary, since graphical displays have separate
Meta keys (usually on each side of the space bar). On a dumb terminal, Viper
sets this variable to twice, which is almost like nil, except
that double <ESC> beeps. This, too, lets <ESC> to be used as a Meta.
viper-ESC-keyseq-timeout 200 on tty, 0 on windowing displayviper-fast-keyseq-timeout 200Setting this variable too high may slow down your typing. Setting it too
low may make it hard to type macros quickly enough.
viper-translate-all-ESC-keysequences t on tty, nil on windowing displaynil. Try and see which
way suits you best.
viper-ex-style-motion tnil, if you want l,h to cross
lines, etc. See Movement and Markers, for more info.
viper-ex-style-editing tnil, if you want
C-h and <DEL> to not stop
at the beginning of a line in Insert state, <X> and <x> to delete
characters across lines in Vi command state, etc.
viper-ESC-moves-cursor-back tt, cursor moves back 1 character when switching from insert state to vi
state. If nil, the cursor stays where it was before the switch.
viper-always tt means: leave it to Viper to decide when a buffer must be brought
up in Vi state,
Insert state, or Emacs state. This heuristics works well in virtually all
cases. nil means you either has to invoke viper-mode manually
for each buffer (or you can add viper-mode to the appropriate major mode
hooks using viper-load-hook).
This option must be set in the file ~/.viper.
viper-custom-file-name "~/.viper"viper-spell-function 'ispell-regionviper-glob-functionviper-glob-unix-files and viper-glob-mswindows-files in
viper-util.el as examples.
This feature is used to expand wildcards in the Ex command :e.
Note that Viper doesn't support wildcards in the :r and :w
commands, because file completion is a better mechanism.
ex-cycle-other-window tnil, :n and :b will cycle through files in another
window, if one exists.
ex-cycle-through-non-files nilviper-want-emacs-keys-in-insertnil for user levels 1 and 2 and to t for user
levels 3 and 4. Users who specify level 5 are allowed to set this variable
as they please (the default for this level is t). If set to
nil, complete Vi compatibility is provided in Insert state. This is
really not recommended, as this precludes you from using language-specific
features provided by the major modes.
viper-want-emacs-keys-in-vinil for user
level 1 and to t for user levels 2–4.
At level 5, users are allowed to set this variable as they please (the
default for this level is t).
If set to nil, complete Vi compatibility is provided
in Vi command state. Setting this to nil is really a bad idea,
unless you are a novice, as this precludes the use
of language-specific features provided by the major modes.
viper-keep-point-on-repeat tnil, point is not moved when the user repeats the previous
command by typing `.' This is very useful for doing repeated changes with
the . key.
viper-repeat-from-history-key 'f12viper-repeat-from-history,
which checks the second key by which it is invoked to see which of the
previous commands to invoke. Viper binds f12 1 and f12 2 only,
but the user can bind more in ~/.viper. See Vi Macros, for how to do
this.
viper-keep-point-on-undo nilnil, Viper tries to not move point when undoing commands.
Instead, it will briefly move the cursor to the place where change has
taken place. However, if the undone piece of text is not seen in window,
then point will be moved to the place where the change took place.
Set it to t and see if you like it better.
viper-delete-backwards-in-replace nilnil, <DEL> key will delete characters while moving the cursor
backwards. If nil, the cursor will move backwards without deleting
anything.
viper-replace-overlay-face 'viper-replace-overlay-faceBy default, viper-replace-overlay-face underlines the replacement on
monochrome displays and also lays a stipple over them. On color displays,
replacement regions are highlighted with color.
If you know something about Emacs faces and don't like how Viper highlights
replacement regions, you can change viper-replace-overlay-face by
specifying a new face. (Emacs faces are described in the Emacs Lisp
reference.) On a color display, the following customization method is
usually most effective:
(set-face-foreground viper-replace-overlay-face "DarkSlateBlue")
(set-face-background viper-replace-overlay-face "yellow")
For a complete list of colors available to you, evaluate the expression
(x-defined-colors). (Type it in the buffer *scratch* and then
hit the C-j key.
viper-replace-overlay-cursor-color "Red"viper-insert-state-cursor-color nilviper-emacs-state-cursor-color nilviper-replace-region-end-delimiter "$"viper-use-replace-region-delimiters is non-nil.
viper-replace-region-start-delimiter ""viper-use-replace-region-delimiters is non-nil.
viper-use-replace-region-delimitersnil, Viper will always use viper-replace-region-end-delimiter and
viper-replace-region-start-delimiter to delimit replacement regions,
even on color displays (where this is unnecessary). By default, this
variable is non-nil only on TTYs or monochrome displays.
viper-allow-multiline-replace-regions tnil, multi-line text replacement regions, such as those produced by
commands c55w, 3C, etc., will stay around until the user exits
the replacement mode. In this variable is set to nil, Viper will
emulate the standard Vi behavior, which supports only intra-line
replacement regions (and multi-line replacement regions are deleted).
viper-toggle-key "\C-z"In Insert state, this key acts as a temporary escape to Vi state, i.e., it
will set Viper up so that the very next command will be executed as if it
were typed in Vi state.
viper-ESC-key "\e"viper-buffer-search-char nilviper-surrounding-word-function 'viper-surrounding-wordviper-search-face 'viper-search-faceviper-vi-state-hook nilviper-insert-state-hook nilviper-replace-state-hook nilviper-insert-state-hook).
viper-emacs-state-hook nilviper-load-hook nil(setq viper-case-fold-search t)
Viper lets you define hot keys, i.e., you can associate keyboard keys such as F1, Help, PgDn, etc., with Emacs Lisp functions (that may already exist or that you will write). Each key has a "preferred form" in Emacs. For instance, the Up key's preferred form is [up], the Help key's preferred form is [help], and the Undo key has the preferred form [f14]. You can find out the preferred form of a key by typing M-x describe-key-briefly and then typing the key you want to know about.
Under the X Window System, every keyboard key emits its preferred form, so you can just type
(global-set-key [f11] 'calendar) ; L1, Stop
(global-set-key [f14] 'undo) ; L4, Undo
to bind L1 (a key that exists on some SUN workstations) so it will invoke
the Emacs Calendar and to bind L4 so it will undo changes.
However, on a dumb terminal or in an Xterm window, even the standard arrow
keys may
not emit the right signals for Emacs to understand. To let Emacs know about
those keys, you will have to find out which key sequences they emit
by typing C-q and then the key (you should switch to Emacs state
first). Then you can bind those sequences to their preferred forms using
function-key-map as follows:
(cond ((string= (getenv "TERM") "xterm")
(define-key function-key-map "\e[192z" [f11]) ; L1
(define-key function-key-map "\e[195z" [f14]) ; L4, Undo
The above illustrates how to do this for Xterm. On VT100, you would have to replace "xterm" with "vt100" and also change the key sequences (the same key may emit different sequences on different types of terminals).
The above keys are global, so they are overwritten by the local maps defined by the major modes and by Viper itself. Therefore, if you wish to change a binding set by a major mode or by Viper, read this.
Viper users who wish to specify their own key bindings should be concerned
only with the following three keymaps:
viper-vi-global-user-map for Vi state commands,
viper-insert-global-user-map for Insert state commands,
and viper-emacs-global-user-map for Emacs state commands (note:
customized bindings for Emacs state made to viper-emacs-global-user-map
are not inherited by Insert state).
For more information on Viper keymaps, see the header of the file
viper.el.
If you wish to change a Viper binding, you can use the
define-key command, to modify viper-vi-global-user-map,
viper-insert-global-user-map, and viper-emacs-global-user-map, as
explained below. Each of these key maps affects the corresponding Viper state.
The keymap viper-insert-global-user-map also affects Viper's Replace
state.
If you want to bind a key, say C-v, to the function that scrolls page down and to make 0 display information on the current buffer, putting this in .viper will do the trick in Vi state:
(define-key viper-vi-global-user-map "\C-v" 'scroll-down)
To set a key globally,
(define-key viper-emacs-global-user-map "\C-c m" 'smail)
(define-key viper-vi-global-user-map "0" 'viper-info-on-file)
Note, however, that this binding may be overwritten by other keymaps, since the global keymap has the lowest priority. To make sure that nothing will override a binding in Emacs state, you can write this:
(define-key viper-emacs-global-user-map "\C-c m" 'smail)
To customize the binding for C-h in Insert state:
(define-key viper-insert-global-user-map "\C-h" 'my-del-backwards-function)
Each Emacs command key calls some Lisp function. If you have enabled the Help, (see Rudimentary Changes) C-h k will show you the function for each specific key; C-h b will show all bindings, and C-h m will provide information on the major mode in effect. If Help is not enabled, you can still get help in Vi state by prefixing the above commands with \, e.g., \ C-h k (or you can use the Help menu in the menu bar, if Emacs runs under X).
Viper users can also change bindings on a per major mode basis. As with
global bindings, this can be done separately for each of the three main Viper
states. To this end, Viper provides the function
viper-modify-major-mode.
To modify keys in Emacs state for my-favorite-major-mode, the user
needs to create a sparse keymap, say, my-fancy-map, bind whatever
keys necessary in that keymap, and put
(viper-modify-major-mode 'dired-mode 'emacs-state my-fancy-map)
in ~/.viper. To do the same in Vi and Insert states, you should use
vi-state and insert-state. Changes in Insert state are also
in effect in Replace state. For instance, suppose that the user wants to
use dd in Vi state under Dired mode to delete files, u to unmark
files, etc. The following code in ~/.viper will then do the job:
(setq my-dired-modifier-map (make-sparse-keymap))
(define-key my-dired-modifier-map "dd" 'dired-flag-file-deletion)
(define-key my-dired-modifier-map "u" 'dired-unmark)
(viper-modify-major-mode 'dired-mode 'vi-state my-dired-modifier-map)
A Vi purist may want to modify Emacs state under Dired mode so that k, l, etc., will move around in directory buffers, as in Vi. Although this is not recommended, as these keys are bound to useful Dired functions, the trick can be accomplished via the following code:
(setq my-dired-vi-purist-map (make-sparse-keymap))
(define-key my-dired-vi-purist-map "k" 'viper-previous-line)
(define-key my-dired-vi-purist-map "l" 'viper-forward-char)
(viper-modify-major-mode 'dired-mode 'emacs-state my-dired-vi-purist-map)
Yet another way to customize key bindings in a major mode is to edit the
list viper-major-mode-modifier-list using the customization widget.
(This variable is in the Viper-misc customization group.)
The elements of this list are triples of the form: (major-mode viper-state
keymap), where the keymap contains bindings that are supposed to be active
in the given major mode and the given viper-state.
Effects similar to key binding changes can be achieved by defining Vi keyboard macros using the Ex commands :map and :map!. The difference is that multi-key Vi macros do not override the keys they are bound to, unless these keys are typed in quick succession. So, with macros, one can use the normal keys alongside with the macros. If per-mode modifications are needed, the user can try both ways and see which one is more convenient. See Vi Macros, for details.
Note: in major modes that come up in Emacs state by default, the
aforesaid modifications may not take place immediately (but only after the
buffer switches to some other Viper state and then back to Emacs state). To
avoid this, one should add viper-change-state-to-emacs to an
appropriate hook of that major mode. (Check the function
viper-set-hooks in viper.el for examples.) However, if you
did not set viper-always to nil, chances are that you won't
need to perform the above procedure, because Viper will take care of most
useful defaults.
Finally, Viper has a facility that lets the user define per-buffer
bindings, i.e., bindings that are in effect in some specific buffers
only. Unlike per-mode bindings described above, per-buffer bindings can be
defined based on considerations other than the major mode. This is done
via the function viper-add-local-keys, which lets one specify bindings
that should be in effect in the current buffer only and for a specific Viper
state. For instance,
(viper-add-local-keys 'vi-state '(("ZZ" . TeX-command-master)
("ZQ" . viper-save-kill-buffer)))
redefines ZZ to invoke TeX-command-master in vi-state
and ZQ to save-then-kill the current buffer. These bindings take
effect only in the buffer where this command is executed. The typical use
of this function is to execute the above expression from within a function
that is included in a hook to some major mode. For instance, the above
expression
could be called from a function, my-tex-init, which may be added to
tex-mode-hook as follows:
(add-hook 'tex-mode-hook 'my-tex-init)
When TeX mode starts, the hook is executed and the above Lisp expression is evaluated. Then, the bindings for ZZ and ZQ are changed in Vi command mode for all buffers in TeX mode.
Another useful application is to bind ZZ to send-mail
in the Mail mode buffers (the specifics of this depend on which mail
package you are using, rmail, mh-e, vm, etc.
For instance, here is how to do this for mh-e, the Emacs interface
to MH:
(defun mh-add-vi-keys ()
"Set up ZZ for MH-e and XMH."
(viper-add-local-keys 'vi-state '(("ZZ" . mh-send-letter))))
(add-hook 'mh-letter-mode-hook 'mh-add-vi-keys)
You can also use viper-add-local-keys to set per buffer
bindings in Insert state and Emacs state by passing as a parameter the
symbols insert-state and emacs-state, respectively.
As with global bindings, customized local bindings done to Emacs state
are not inherited by Insert state.
On rare occasions, local keys may be added by mistake. Usually this is done
indirectly, by invoking a major mode that adds local keys (e.g.,
shell-mode redefines <RET>). In such a case, exiting the wrong
major mode won't rid you from unwanted local keys, since these keys are
local to Viper state and the current buffer, not to the major mode.
In such situations, the remedy is to type M-x viper-zap-local-keys.
So much about Viper-specific bindings. See Customization, and the Emacs quick reference card for the general info on key bindings in Emacs.
Viper is designed to coexist with all major and minor modes of Emacs. This
means that bindings set by those modes are generally available with Viper
(unless you explicitly prohibit them by setting
viper-want-emacs-keys-in-vi and viper-want-emacs-keys-in-insert to
nil).
If viper-always is set to t (which is the default), Viper
will try to bring each buffer
in the Viper state that is most appropriate for that buffer.
Usually, this would be the Vi state, but sometimes it could be the Insert
state or the Emacs state.
Some major mode bindings will necessarily be overwritten by Viper. Indeed, in Vi state, most of the 1-character keys are used for Vi-style editing. This usually causes no problems because most packages designed for editing files typically do not bind such keys. Instead, they use key sequences that start with C-x and C-c. This is why it was so important for us to free up C-x and C-c. It is common for language-specific major modes to bind <TAB> and C-j (the line feed) keys to various formatting functions. This is extremely useful, but may require some getting used to for a Vi user. If you decide that this feature is not for you, you can re-bind these keys as explained earlier (see Customization).
Binding for <TAB> is one of the most unusual aspects of Viper for many novice users. In Emacs, <TAB> is used to format text and programs, and is extremely useful. For instance, hitting <TAB> causes the current line to be re-indented in accordance with the context. In programming, this is very important, since improper automatic indentation would immediately alert the programmer to a possible error. For instance, if a ) or a " is missing somewhere above the current line, <TAB> is likely to mis-indent the line.
For this reason, Viper doesn't change the standard Emacs binding of <TAB>, thereby sacrificing Vi compatibility (except for users at level 1). Instead, in Viper, the key S-tab (shift+ tab) is chosen to emulate Vi's <TAB>.
We should note that on some non-windowing terminals, Shift doesn't modify
the <TAB> key, so S-tab behaves as if it were <TAB>. In such
a case, you will have to bind viper-insert-tab to some other
convenient key.
Some packages, notably Dired, Gnus, Info, etc., attach special meaning to common keys like <SPC>, x, d, v, and others. This means that Vi command state is inappropriate for working with these packages. Fortunately, these modes operate on read-only buffers and are designed not for editing files, but for special-purpose browsing, reading news, mail, etc., and Vi commands are meaningless in these situations. For this reason, Viper doesn't force Vi state on such major modes—it brings them in Emacs state. You can switch to Vi state by typing C-z if, for instance, you want to do Vi-style search in a buffer (although, usually, incremental search, which is bound to C-s, is sufficient in these situations). But you should then switch back to Emacs state if you plan to continue using these major modes productively. You can also switch to Vi temporarily, to execute just one command. This is done by typing C-c \. (In some of these modes, / and : are bound Vi-style, unless these keys perform essential duties.)
If you would like certain major modes to come up in Emacs state rather than
Vi state (but Viper thinks otherwise), you should put these major modes
on the viper-emacs-state-mode-list list and delete them from
viper-vi-state-mode-list.
Likewise, you can force Viper's Insert state on a major mode by putting it
in viper-insert-state-mode-list.
It is also possible to impose Vi on some major modes, even though they may
bind common keys to specialized commands. This might make sense for modes
that bind only a small number of common keys. For instance, Viper subverts
the Shell mode by changing the bindings for C-m and C-d using
viper-add-local-keys described in the section on customization
(see Customization).
In some cases, some minor modes might override certain essential
bindings in Vi command state. This is not a big problem because this
can happen only in the beginning, when the minor mode kicks in. Typing
M-x viper-mode will correct the situation. Viper knows about
several such minor modes and takes care of them, so the above trick
is usually not necessary. If you find that some minor mode, e.g.,
nasty-mode interferes with Viper, putting the following in
.viper should fix the problem:
(viper-harness-minor-mode "nasty-mode")
The argument to viper-harness-minor-mode is the name of the file for the
offending minor mode with the suffixes .el and .elc removed.
It may not be always obvious which minor mode is at fault. The only
guidance here is to look into the file that defines the minor mode you are
suspecting, say nasty-mode.el, and see if it has a variable called
nasty-mode-map. Then check if there is a statement of the form
(define-key nasty-mode-map key function)
that binds the misbehaving
keys. If so, use the above line to harness nasty-mode. If your
suspicion is wrong, no harm is done if you harness a minor mode that
doesn't need to be harnessed.
It is recommended to harness even those minor modes that don't override
Viper keys, but still have their own keymaps. A general way to
make a minor mode, my-mode,
compatible with Viper is to have the file my-mode.el include the following code:
(when (fboundp 'viper-harness-minor-mode)
(let ((lib (file-name-sans-extension
(file-name-nondirectory load-file-name))))
(viper-harness-minor-mode lib)))
Viper extends Vi with a number of useful features. This includes various search functions, histories of search strings, Ex commands, insertions, and Vi's destructive commands. In addition, Viper supports file name completion and history, completion of Ex commands and variables, and many other features. Some of these features are explained in detail elsewhere in this document. Other features are explained here.
(viper-buffer-search-enable)viper-buffer-search-char nilviper-buffer-search-enable
sets viper-buffer-search-char to g. Alternatively, the user can
set viper-buffer-search-char in .viper to a key sequence
to be used for buffer search. There is no need to call
viper-buffer-search-enable in that case.
viper-toggle-search-styleHowever, we found that the most convenient way to toggle these options is to bind a Vi macro to bind // to toggles case sensitivity and to /// to toggles va