| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
1.1 Basic Concepts Basic concepts in Emacs. 1.2 Loading VIP How to load VIP automatically. 1.3 Modes in VIP VIP has three modes, which are orthogonal to modes in Emacs. 1.4 Differences from Vi Differences of VIP from Vi is explained.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The recommended way to load VIP automatically is to include the line:
(load "vip") |
(setq term-setup-hook 'vip-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.
M-x vip-mode |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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
vip-change-mode-to-vi by 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
M-x vip-mode.)
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------------ |
-----Vi: *scratch* (Lisp Interaction)----All------------ |
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------------ |
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).
The figure below shows the transition of three modes in VIP.
=== C-z ==> == i,o ... ==>
emacs mode vi mode insert mode
<== X-z === <=== ESC ====
|
1.3.1 Emacs Mode This is the mode you should know better. 1.3.2 Vi Mode Vi commands are executed in this mode. 1.3.3 Insert Mode You can enter text, and also can do editing if you know enough Emacs commands.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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
bound to vip-change-mode-to-vi. So, if you type C-z in this mode
then you will be in vi mode.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The major differences from Vi are explained below.
1.4.1 Undoing You can undo more in VIP. 1.4.2 Changing Commands for changing the text. 1.4.3 Searching Search commands. 1.4.4 z Command You can now use zH, zM and zL as well as z- etc. 1.4.5 Counts Some Vi commands which do not accept a count now accept one. 1.4.6 Marking You can now mark the current point, beginning of the buffer etc. 1.4.7 Region Commands You can now give a region as an argument for delete commands etc. 1.4.8 Some New Commands Some new commands not available in Vi are added. 1.4.9 New Key Bindings Bindings of some keys are changed for the convenience of editing under Emacs. 1.4.10 Window Commands Commands for moving among windows etc. 1.4.11 Buffer Commands Commands for selecting buffers etc. 1.4.12 File Commands Commands for visiting files etc. 1.4.13 Miscellaneous Commands Other useful commands.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 4. Customization, for how to do this.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Some Vi commands which do not accept a count now accept one
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Note that the keys below (except for R) are not used in Vi.
downcase-region).
upcase-region).
vip-global-execute).vip-quote-region).
spell-region).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 4.2 Customizing Key Bindings, for details.
In addition to these, ctl-x-map is slightly modified:
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In this and following subsections, we give a summary of key bindings for basic functions related to windows, buffers and files.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
vip-switch-to-buffer).
vip-switch-to-buffer-other-window).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Insert specified file at point.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |