In this chapter we describe basics of VIP with emphasis on the features not found in Vi and on how to use VIP under GNU Emacs.
We begin by explaining some basic concepts of Emacs. These concepts are explained in more detail in the GNU Emacs Manual.
Conceptually, a buffer is just a string of ASCII characters and two special characters PNT (point) and MRK (mark) such that the character PNT occurs exactly once and MRK occurs at most once. The text of a buffer is obtained by deleting the occurrences of PNT and MRK. If, in a buffer, there is a character following PNT then we say that point is looking at the character; otherwise we say that point is at the end of buffer. PNT and MRK are used to indicate positions in a buffer and they are not part of the text of the buffer. If a buffer contains a MRK then the text between MRK and PNT is called the region of the buffer.
Emacs provides (multiple) windows on the screen, and you can see the content of a buffer through the window associated with the buffer. The cursor of the screen is always positioned on the character after PNT.
A keymap is a table that records the bindings between characters and command functions. There is the global keymap common to all the buffers. Each buffer has its local keymap that determines the mode of the buffer. Local keymap overrides global keymap, so that 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 becomes in effect.
The recommended way to load VIP automatically is to include the line:
in your `.emacs' file. The `.emacs' file is placed in your home directory and it will be executed every time you invoke Emacs. If you wish to be in vi mode whenever Emacs starts up, you can include the following line in your `.emacs' file instead of the above line:
(setq term-setup-hook 'vip-mode)
(See section Vi Mode, for the explanation of vi mode.)
Even if your `.emacs' file does not contain any of the above lines, you can load VIP and enter vi mode by typing the following from within Emacs.
Loading VIP has the effect of globally binding C-z (Control-z)
to the function
vip-change-mode-to-vi. The default binding of C-z
in GNU Emacs is
suspend-emacs, but, you can also call
suspend-emacs by typing C-x C-z. Other than this, all the
key bindings of Emacs remain the same after loading VIP.
Now, if you hit C-z, the function
vip-change-mode-to-vi will be
called and you will be in vi mode. (Some major modes may locally bind
C-z to some special functions. In such cases, you can call
execute-extended-command which is
invoked by M-x. Here M-x means Meta-x, and if your
terminal does not have a META key you can enter it by typing
ESC x. The same effect can also be achieve by typing
You can observe the change of mode by looking at the mode line. For instance, if the mode line is:
-----Emacs: *scratch* (Lisp Interaction)----All------------
then it will change to:
-----Vi: *scratch* (Lisp Interaction)----All------------
Thus the word `Emacs' in the mode line will change to `Vi'.
You can go back to the original emacs mode by typing C-z in vi mode. Thus C-z toggles between these two modes.
Note that modes in VIP exist orthogonally to modes in Emacs. This means that you can be in vi mode and at the same time, say, shell mode.
Vi mode corresponds to Vi's command mode. From vi mode you can enter insert mode (which corresponds to Vi's insert mode) by usual Vi command keys like i, a, o ... etc.
In insert mode, the mode line will look like this:
-----Insert *scratch* (Lisp Interaction)----All------------
You can exit from insert mode by hitting ESC key as you do in Vi.
That VIP has three modes may seem very complicated, but in fact it is not so. VIP is implemented so that you can do most editing remaining only in the two modes for Vi (that is vi mode and insert mode).
You will be in this mode just after you loaded VIP. You can do all
normal Emacs editing in this mode. Note that the key C-z is globally
vip-change-mode-to-vi. So, if you type C-z in this mode
then you will be in vi mode.
This mode corresponds to Vi's command mode. Most Vi commands work as they do in Vi. You can go back to emacs mode by typing C-z. You can enter insert mode, just as in Vi, by typing i, a etc.
The key bindings in this mode is the same as in the emacs mode except for the following 4 keys. So, you can move around in the buffer and change its content while you are in insert mode.
The major differences from Vi are explained below.
You can repeat undoing by the . key. So, u will undo a single change, while u . . ., for instance, will undo 4 previous changes. Undo is undoable as in Vi. So the content of the buffer will be the same before and after u u.
Some commands which change a small number of characters are executed slightly differently. Thus, if point is at the beginning of a word `foo' and you wished to change it to `bar' by typing c w, then VIP will prompt you for a new word in the minibuffer by the prompt `foo => '. You can then enter `bar' followed by RET or ESC to complete the command. Before you enter RET or ESC you can abort the command by typing C-g. In general, you can abort a partially formed command by typing C-g.
As in Vi, searching is done by / and ?. The string will be
searched literally by default. To invoke a regular expression search,
first execute the search command / (or ?) with empty search
string. (I.e, type / followed by RET.)
A search for empty string will toggle the search mode between vanilla
search and regular expression search. You cannot give an offset to the
search string. (It is a limitation.) By default, search will wrap around
the buffer as in Vi. You can change this by rebinding the variable
vip-search-wrap-around. See section Customization, for how to do this.
For those of you who cannot remember which of z followed by RET, . and - do what. You can also use z followed by H, M and L to place the current line in the Home (Middle, and Last) line of the window.
Some Vi commands which do not accept a count now accept one
Typing an m followed by a lower case character ch marks the point to the register named ch as in Vi. In addition to these, we have following key bindings for marking.
Vi operators like d, c etc. are usually used in combination with motion commands. It is now possible to use current region as the argument to these operators. (A region is a part of buffer delimited by point and mark.) The key r is used for this purpose. Thus d r will delete the current region. If R is used instead of r the region will first be enlarged so that it will become the smallest region containing the original region and consisting of whole lines. Thus m . d R will have the same effect as d d.
Note that the keys below (except for R) are not used in Vi.
In VIP the meanings of some keys are entirely different from Vi. These key bindings are done deliberately in the hope that editing under Emacs will become easier. It is however possible to rebind these keys to functions which behave similarly as in Vi. See section Customizing Key Bindings, for details.
In addition to these,
ctl-x-map is slightly modified:
In this and following subsections, we give a summary of key bindings for basic functions related to windows, buffers and files.