This is Info file ../info/viper, produced by Makeinfo-1.63 from the
input file viper.texi.

Distribution
************

Copyright (C) 1995, 1996 Free Software Foundation, Inc.

   Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.

   Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided that
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.

   Permission is granted to copy and distribute translations of this
manual into another language, under the same conditions as for modified
versions.


File: viper,  Node: Viper Specials,  Next: Vi Macros,  Prev: Packages that Change Keymaps,  Up: Customization

Viper Specials
==============

   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.

`(vip-buffer-search-enable)'
`vip-buffer-search-char nil'
     Enable buffer search. Explicit call to `vip-buffer-search-enable'
     sets `vip-buffer-search-char' to `g'. Alternatively, the user can
     set `vip-buffer-search-char' in `.vip' to a key sequence to be
     used for buffer search. There is no need to call
     `vip-buffer-search-enable' in that case.

`vip-toggle-search-style'
     This function, bound to `C-c /', lets one toggle case-sensitive and
     case-insensitive search, and also switch between plain vanilla
     search and search via regular expressions. Without the prefix
     argument, the user is asked which mode to toggle. With prefix
     argument 1, this toggles case-sensitivity. With prefix argument 2,
     regular expression/vanilla search will be toggled.

     However, 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 vanilla search. Thus, quickly
     hitting `/' twice will switch Viper from case sensitive search to
     case-insensitive. Repeating this once again will restore the
     original state. Likewise, quickly hitting `/' three times will
     switch you from vanilla-style search to search via regular
     expressions.  If you hit something other than `/' after the first
     `/' or if the second `/' doesn't follow quickly enough, then Viper
     will issue the usual prompt `/' and will wait for input, as usual
     in Vi.  If you don't like this behavior, you can "unrecord" these
     macros in your `~/.vip' file. For instance, if u don't like the
     above feature, put this in `~/.vip':
          (vip-unrecord-kbd-macro "//" 'vi-state)
          (vip-unrecord-kbd-macro "///" 'vi-state)

     *Note Vi Macros::, for more information on Vi macros.

`vip-heading-start'
`vip-heading-end'
     Regular Expressions for `[[' and `]]'. Note that Emacs defines
     Regexps for paragraphs and sentences. *Note Paragraphs and
     Sentences: (emacs)Paragraphs, for details.

`M-x vip-set-expert-level'
     Change your user level interactively.

`vip-smart-suffix-list  '("" "tex" "c" "cc" "el" "p")'
     Viper supports Emacs-style file completion when it prompts the
     user for a file name. However, in many cases, the same directory
     may contain files with identical prefix but different suffixes,
     e.g., prog.c, prog.o, paper.tex, paper.dvi. In such cases,
     completion will stop at the `.'.  If the above variable is a list
     of strings representing suffixes, Viper will try these suffixes in
     the order listed and will check if the corresponding file exists.

     For instance, if completion stopped at `paper.' and the user typed
     RET, then Viper will check if the files `paper.', `paper.tex',
     `paper.c', etc., exist.  It will take the first such file. If no
     file exists, Viper will give a chance to complete the file name by
     typing the appropriate suffix. If `paper.' was the intended file
     name, hitting return will accept it.

     To turn this feature off, set the above variable to `nil'.

`vip-insertion-ring-size  14'
     Viper remembers what was previously inserted in Insert and Replace
     states.  Several such recent insertions are kept in a special ring
     of strings of size `vip-insertion-ring-size'.  If you enter Insert
     or Replace state you can reinsert strings from this ring by typing
     `C-c M-p' or `C-c M-n'. The former will search the ring in the
     direction of older insertions, and the latter will search in the
     direction of newer insertions. Hitting `C-c M-p' or `C-c M-n' in
     succession will undo the previous insertion from the ring and
     insert the next item on the ring. If a larger ring size is needed,
     change the value of the above variable in the `~/.vip' file.

     Since typing these sequences of keys may be tedious, it is
     suggested that the user should bind a function key, such as `f31',
     as follows:
          (define-key vip-insert-global-user-map [f31]
                      'vip-insert-prev-from-insertion-ring)
     This binds `f31' (which is usually `R11' on a Sun workstation) to
     the function that inserts the previous string in the insertion
     history.  To rotate the history in the opposite direction, you can
     either bind an unused key to `vip-insert-next-from-insertion-ring'
     or hit any digit (1 to 9) then `f31'.

     One should not bind the above functions to `M-p' or `M-n', since
     this will interfere with the Minibuffer histories and, possibly,
     other major modes.

`vip-command-ring-size  14'
     Viper keeps track of the recent history of destructive commands,
     such as `dw', `i', etc.  In Vi state, the most recent command can
     be re-executed by hitting ``.'', as in Vi.  However, repeated
     typing `C-c M-p' will cause Viper to show the previous destructive
     commands in the minibuffer. Subsequent hitting ``.'' will execute
     the command that was displayed last.  The key `C-c M-n' will cycle
     through the command history in the opposite direction.  Since
     typing `C-c M-p' may be tedious, it is more convenient to bind an
     appropriate function to an unused function key on the keyboard and
     use that key. For instance, the following
          (define-key vip-vi-global-user-map [f31]
                      'vip-prev-destructive-command)
     binds the key `f31' (which is usually `R11' on a Sun workstation)
     to the function that searches the command history in the direction
     of older commands. To search in the opposite direction, you can
     either bind an unused key to `vip-next-destructive-command' or hit
     any digit (1 to 9) then `f31'.

     One should not bind the above functions to `M-p' or `M-n', since
     this will interfere with the Minibuffer histories and, possibly,
     other major modes.

`vip-minibuffer-vi-face  'vip-minibuffer-vi-face'
`vip-minibuffer-insert-face  'vip-minibuffer-insert-face'
`vip-minibuffer-emacs-face  'vip-minibuffer-emacs-face'
     These faces control the appearance of the minibuffer text in the
     corresponding Viper states. For heavy-duty customization, consult
     the Lisp Reference to Emacs. You can also take a look how these
     faces are defined in `viper.el'.

     However, on a color workstation, the following method usually
     suffices:
          (set-face-foreground vip-minibuffer-vi-face "blue")
          (set-face-background vip-minibuffer-emacs-face "orchid")
     This will make a blue foreground in the Minibuffer when it is in Vi
     state; its background will turn to orchid when it switches to
     Emacs state.

     Note that only the text you type in is affected by the above faces.
     Prompts and Minibuffer messages are not affected.

     Purists who do not like adornments in the minibuffer can always
     zap them by putting
          (copy-face 'default 'vip-minibuffer-vi-face)
          (copy-face 'default 'vip-minibuffer-insert-face)
          (copy-face 'default 'vip-minibuffer-emacs-face)
     in the `~/.vip' file. However, in that case, the user will not
     have any indication of the current Viper state in the minibuffer.
     (This is important if the user accidentally switches to another
     Viper state by typing `ESC' or `C-z'.

   Viper provides some support for multi-file documents and programs.
If a document consists of several files we can designate one of them as
a master and put the following at the end of that file:
     ;;; Local Variables:
     ;;; eval: (vip-setup-master-buffer "file1" "file2" "file3" "file5" "file5")
     ;;; End:

where `file1' to `file5' are names of files related to the master file.
Next time, when the master file is visited, the command
`vip-setup-master-buffer' will be evaluated and the above files will be
associated with the master file. Then, the new Ex command
`:RelatedFile' (abbr. `:R') will display files 1 to 5 one after
another, so you can edit them. If a file is not in any Emacs buffer, it
will be visited.  The command `PreviousRelatedFile' (abbr., `:P') goes
through the file list in the opposite direction.

   These commands are akin to `:n' and `:N', but they allow the user to
focus on relevant files only.

   Note that only the master file needs to have the aforementioned
block of commands. Also, ";;;" above can be replaced by some other
markers. Semicolon is good for Lisp programs, since it is considered a
comment designator there. For LaTeX, this could be "%%%", and for C the
above block should be commented out.

   Even though these commands are sometimes useful, they are no
substitute for the powerful *tag table* facility of Emacs. Viper's
`:tag' command in a primitive interface to Emacs tags. *Note Tags:
(emacs)Tags, for more information on tags.

   The following two commands are normally bound to a mouse click and
are part of Viper. They work only if Emacs runs as an application under
X Windows (or under some other window system for which a port of Emacs
19 is available). Clicking the mouse when Emacs is invoked in an Xterm
window (using `emacs -nw') will do no good.

`M-S-mouse-1 (Emacs)'
`meta shift button1up (XEmacs)'
     Holding Meta and Shift while clicking mouse button 1 will initiate
     search for a region under the mouse pointer (defined below).  This
     command can take a prefix argument, which indicates the occurrence
     of the pattern to search for.

     Note: Viper binds this mouse action only if it is not already
     bound to something else. If you want to use this feature and
     `M-S-mouse-1' is already used for something else, you can rebind
     mouse-search as, for example, in the following example:
          (global-set-key [M-mouse-1] 'vip-mouse-click-search-word)
          (global-set-key [M-down-mouse-1] 'vip-mouse-catch-frame-switch)
     This would bind mouse search to the action invoked by pressing the
     Meta key and clicking mouse button 1. Note: if
     `vip-mouse-click-search-word' is bound to an action, then
     `vip-mouse-catch-frame-switch' must be bound to a down-action, as
     shown in the above example.

     In XEmacs, you can change bindings as follows:
          (global-set-key [(meta control button1up)]
                          'vip-mouse-click-search-word)
          (global-set-key [(meta control button1)]
                          'vip-mouse-catch-frame-switch)
     if, say, you prefer to hold both meta and control while clicking.

     Like in Emacs, there are special rules for binding these
     functions: the first must be bound to a button-up event while the
     second must be bound to a button-event (which is XEmacs'
     equivalent of a down-mouse event).  Also, in Emacs, the
     double-click and triple-click actions for the same button
     (`double-S-mouse-1', etc., if the above default binding is used)
     should not be bound (or it should be bound to the same function,
     `vip-mouse-click-search-word').

     The region that is chosen as a pattern to search for is determined
     as follows. If search is invoked via a single click, Viper chooses
     the region that lies between the beginning of the "word" under the
     pointer ("word" is understood in Vi sense) and the end of that
     word.  The only difference with Vi's words is that in Lisp major
     modes `-' is considered an alphanumeric symbol. This is done for
     the convenience of working with Lisp symbols, which often have an
     `-' in them.  Also, if you click on a non-alphanumeric character
     that is not a word separator (in Vi sense) then this character
     will also be considered alphanumeric, provided that it is adjacent
     (from either side) to an alphanumeric character.  This useful
     feature gives added control over the patterns selected by the
     mouse click.

     On a double-click, the region is determined by the beginning of
     the current Vi's "Word" (i.e., the largest non-separator chunk of
     text) and the End of that "Word" (as determined by the `E'
     command).

     On a triple-click, the region consists of the entire line where
     the click occurred with all leading and trailing spaces and tabs
     removed.

`M-S-mouse-2 (Emacs)'
`meta shift button2up (XEmacs)'
     Holding Meta and Shift while clicking mouse button 2 will insert
     the region surrounding the mouse pointer.  The rules defining this
     region are the same as for mouse-search.  This command takes an
     optional prefix argument, which indicates how many such regions to
     snarf from the buffer and insert.  (In case of a triple-click, the
     prefix argument is ignored.)

     Note: Viper binds this mouse action only if it not already bound to
     something else. If you want to use this feature and `S-mouse-2' is
     already used for something else, you can rebind mouse-insert as
     follows:
          (global-set-key [M-mouse-2] 'vip-mouse-click-insert-word)
          (global-set-key [M-down-mouse-2] 'vip-mouse-catch-frame-switch)
     In XEmacs, you can change the bindings as follows:
          (global-set-key [(meta control button2up)]
                          'vip-mouse-click-insert-word)
          (global-set-key [(meta control button2)]
                          'vip-mouse-catch-frame-switch)

`vip-multiclick-timeout'
     This variable controls the rate at which double-clicking must
     occur for the purpose of mouse search and mouse insert. By
     default, this is set to `double-click-time' in Emacs and to
     `mouse-track-multi-click-time' milliseconds in XEmacs.

   Note: The above functions search and insert in the selected window of
the latest active frame. This means that you can click in another
window or another frame and have search or insertion done in the frame
and window you just left.  This lets one use these functions in a
multi-frame configuration.  However, this may require some getting used
to. For instance, if you are typing in a frame, A, and then move the
mouse to frame B and click to invoke mouse search, search (or
insertion) will be performed in frame A. To perform search/insertion in
frame B, you will first have to shift focus there, which doesn't happen
until you type a character or perform some other action in frame
B--mouse search doesn't shift focus (in XEmacs, to shift focus to frame
B, you will have to select this frame with a mouse, by clicking.

   If you decide that you don't like the above feature and always want
search/insertion be performed in the frame where the click occurs, don't
bind (and unbind, if necessary) `vip-mouse-catch-frame-switch' from the
mouse event it is bound to.

   Mouse search is integrated with Vi-style search, so you can repeat
it with `n' and `N'. It should be also noted that, while
case-sensitivity of search in Viper is controlled by the variable
`vip-case-fold-search', the case of mouse search is controlled by the
Emacs variable `case-fold-search', which may be set differently from
`vip-case-fold-search'. Therefore, case-sensitivity of mouse search may
be different from that of the usual Vi-style search.

   Finally, if the way Viper determines the word to be searched for or
to be inserted is not what you want, there is a variable,
`vip-surrounding-word-function', which can be changed to indicate
another function for snarfing words out of the buffer. The catch is that
you will then have to write such a function and make it known to your
Emacs. The function `vip-surrounding-word' in `viper.el' can be used as
a guiding example.


File: viper,  Node: Vi Macros,  Prev: Viper Specials,  Up: Customization

Vi Macros
=========

   Viper supports much enhanced Vi-style macros and also facilitates
the use of Emacs-style macros.  To define a temporary macro, it is
generally more convenient to use Emacs keyboard macro facility. Emacs
keyboard macros are usually defined anonymously, and the latest macro
can be executed by typing `C-x e' (or `*', if Viper is in Vi state). If
you need to use several temporary macros, Viper lets you save them to a
register (a lowercase letter); such macros can then be executed by
typing `@a' in Vi state (if a macro was previously saved in register
`a').  *Note Macros and Registers::, for details.

   If, however, you need to use a macro regularly, it must be given a
permanent name and saved. Emacs manual explains how to do this, but
invocation of named Emacs macros is quite different from Vi's. First,
invocation of permanent Emacs macros takes time because of the extra
keys.  Second, binding such macros to function keys, for fast access,
hogs valuable real estate on the keyboard.

   Vi-style macros are better in that respect, since Vi lets the user
overload the meaning of key sequences: keys typed in fast succession
are treated specially, if this key sequence is bound to a macro.

   Viper provides keyboard macros through the usual Ex commands, `:map'
and `:map!'. Vi-style macros are much more powerful in Viper than they
are in the original Vi and in other emulators. This is because Viper
implements an enhanced vi-style interface to the powerful Emacs
keyboard macro facility.

   First, any Emacs command can be executed while defining a macro, not
just the Vi commands. In particular, the user can invoke Emacs commands
via `M-x command-name' or by pressing various function keys on the
keyboard. One can even use the mouse, although this is usually not
useful and is not recommended (and macros defined with the use of the
mouse cannot be saved in command history and in the startup file, for
future use).

   Macros defined by mixing Vi and Emacs commands are represented as
vectors. So, don't be confused when you see one (usually through the
history of Ex commands). For instance, if `gg' is defined by typing
`l', the up-arrow key and `M-x next-line', its definition will look as
follows in Emacs (in XEmacs, it looks slightly different, see below):

     [l up (meta x) n e x t - l i n e return]

   Second, Viper macros are defined in a WYSIWYG style. This means that
commands are executed as you type them, so you can see precisely what is
being defined.  Third, macros can be bound to arbitrary sequences of
keys, not just to printable keys. For instance, one can define a macro
that will be invoked by hitting `f3' then `f2' function keys. (The keys
`delete' and `backspace' are excluded; also, a macro invocation
sequence can't start with ESC. Some other keys, such as `f1' and
`help', can't be bound to macros under Emacs (not XEmacs), since they
are bound in `key-translation-map', which overrides any other binding
the user gives to keys. In general, keys that have a binding in
`key-translation-map' can't be bound to a macro.)

   Fourth, in Viper, one can define macros that are specific to a given
buffer, a given major mode, or macros that are defined for all buffers.
In fact, the same macro name can have several different definitions:
one global, several definitions for various major modes, and
definitions for various specific buffers. Buffer-specific definitions
override mode-specific definitions, which, in turn, override global
definitions.

   As if all that is not enough, Viper (through its interface to Emacs
macros) lets the user define keyboard macros that ask for confirmation
or even prompt the user for input and then continue. To do this, one
should type `C-x q' (for confirmation) or `C-u C-x q' (for prompt).
For details, *note Customization: (emacs)Kbd Macro Query.

   When the user finishes defining a macro (which is done by typing
`C-x)' -- a departure from Vi), you will be asked whether you want this
macro to be global, mode-specific, or buffer-specific. You will also be
given a chance to save the macro in your `~/.vip' file.  This is the
easiest way to save a macro and make it permanently available. If you
work your startup files with bare hands, here is how Viper saves the
above macro so that it will be available in Viper's Insert state (and
Replace state) in buffer `my-buf' only:

      (vip-record-kbd-macro "gg" 'insert-state
             [l up (meta x) n e x t - l i n e return]
             "my-buf")

To do the same for Vi state and all buffers with the major mode
`cc-mode', use:

      (vip-record-kbd-macro "gg" 'vi-state
             [l up (meta x) n e x t - l i n e return]
             'cc-mode)

Both macro names and macro definitions are vectors of symbols that
denote keys on the keyboard. Some keys, like `\', ` ', or digit-keys
must be escaped with a backslash. Modified keys are represented as
lists. For instance, holding Meta and Control and pressing `f4' is
represented as `(control meta f4)'.  If all members of a vectors are
printable characters (or sequences, such as `\e', `\t', for ESC and
TAB), then they can also be represented as strings:

      (vip-record-kbd-macro "aa" 'vi-state  "aaa\e"  "my-buffer")

Thus, typing `aa' fast in Vi state will switch Viper to Insert state
(due to the first `a'), insert `aa', and then it will switch back to Vi
state. All this will take effect only in the buffer named `my-buffer'.

   Note that the last argument to `vip-record-kbd-macro' must be either
a string (a buffer name), a symbol representing a major mode, or `t';
the latter says that the macro is to be defined for all buffers (which
is how macros are defined in original Vi).

   For convenience, Viper also lets you define Vi-style macros in its
Emacs state. There is no Ex command, like `:map' and `:map!' for doing
this, but the user can include such a macro in the `~/.vip' file. The
only thing is that the `vip-record-kbd-macro' command should specify
`'emacs-state' instead of `'vi-state' or `'insert-state'.

   The user can get rid of a macro either by using the Ex commands
`:unmap' and `:unmap!' or by issuing a call to `vip-unrecord-kbd-macro'.
The latter is more powerful, since it can delete macros even in
`'emacs-state'. However, `vip-unrecord-kbd-macro' is usually needed
only when the user needs to get rid of the macros that are already
predefined in Viper.  The syntax is:
     (vip-unrecord-kbd-macro macro state)

The second argument must be `'vi-state', `'insert-state', or
`'emacs-state'. The first argument is a name of a macro.  To avoid
mistakes in specifying names of existing macros, type `M-x
vip-describe-kbd-macros' and use a name from the list displayed by this
command.

   If an error occurs during macro definition, Emacs aborts the
process, and it must be repeated. This is analogous to Vi, except that
in Vi the user doesn't know there is an error until the macro is
actually run. All that means that in order for a definition to be
successful, the user must do some simple planning of the process in
advance, to avoid errors.  For instance, if you want to map `gg' to
`llll' in Vi state, you must make sure that there is enough room on the
current line. Since `l' moves the cursor forward, it may signal an
error on reaching the end of line, which will abort the definition.

   These precautions are necessary only when defining macros; they will
help avoid the need to redo the job. When macros are actually run, an
error during the execution will simply terminate the current execution
(but the macro will remain mapped).

   A macro name can be a string of characters or a vector of keys.  The
latter makes it possible to define macros bound to, say, double-hits on
a function key, such as `up' or `f13'.  This is very useful if you run
out of function keys on your keyboard; it makes Viper macro facility a
*keyboard doubler*, so to speak.

   Elsewhere (*Note Keybindings::, for details), we review the standard
Emacs mechanism for binding function keys to commands.  For instance,

     (global-set-key [f13] 'repeat-complex-command)

binds the key f13 to the Emacs function that repeats the last minibuffer
command. Under Viper, however, you may still use this key for additional
purposes, if you bind, say, a double-hitting action for that key to some
other function. Emacs doesn't allow the user to do that, but Viper does
this through its keyboard macro facility. To do this, type `:map '
first. When you are asked to enter a macro name, hit f13 twice,
followed by RET or SPC.

   Emacs will now start the mapping process by actually executing Vi
and Emacs commands, so that you could see what will happen each time the
macro is executed. Suppose now we wanted to bind the key sequence `f13
f13' to the command `eval-last-sexp'. To accomplish this, we can type
`M-x eval-last-sexp' followed by `C-x )'.  If you answer positively to
Viper's offer to save this macro in `~/.vip' for future uses, the
following will be inserted in that file:

     (vip-record-kbd-macro [f16 f16] 'vi-state
              [(meta x) e v a l - l a s t - s e x p]
              'lisp-interaction-mode)

   To illustrate the above point, Viper provides two canned macros,
which, by default, are bound to `[f12 \1]' and `[f12 \2]' (invoked by
typing `f12' then `1' and `2', respectively).  These macros are useful
shortcuts to Viper's command ring history.  The first macro will
execute the second-last destructive command (the last one is executed
by `.', as usual). The second macro executes the third-last command.

   If you need to go deeper into the command history, you will have to
use other commands, as described earlier in this section; or you can
bind, say, `f12 \3' like this:

     (vip-record-kbd-macro [f12 \3] 'vi-state
                           [(meta x) r e p e a t - f r o m - h i s t o r y]
                           t)

   Note that even though the macro uses the function key `f12', the key
is actually free and can still be bound to some Emacs function via
`define-key' or `global-set-key'.

   Viper allows the user to define macro names that are prefixes of
other macros.  For instance, one can define `[[' and `[[[[' to be
macros.  If you type the exact sequence of such keys and then pause,
Viper will execute the right macro. However, if you don't pause and,
say, type `[[[[text' then the conflict is resolved as follows. If only
one of the key sequences, `[[' or `[[[[' has a definition applicable to
the current buffer, then, in fact, there is no conflict and the right
macro will be chosen. If both have applicable definitions, then the
first one found will be executed. Usually this is the macro with a
shorter name. So, in our case, `[[[[text' will cause the macro `[[' to
be executed twice and then the remaining keys, `t e x t', will be
processed.

   When defining macros using `:map' or `:map!', the user enters the
actually keys to be used to invoke the macro. For instance, you should
hit the actual key `f6' if it is to be part of a macro name; you do
*not* write `f 6'. When entering keys, Viper displays them as strings or
vectors (e.g., "abc" or [f6 f7 a]). The same holds for unmapping.
Hitting TAB while typing a macro name in the `:unmap' or `:unmap!'
command will cause name completion. Completions are displayed as
strings or vectors.  However, as before, you don't actually type """,
"[", or "]" that appear in the completions. These are meta-symbols that
indicate whether the corresponding macro name is a vector or a string.

   One last difference from Vi: Vi-style keyboard macros cannot be
defined in terms of other Vi-style keyboard macros (but named Emacs
macros are OK).  More precisely, while defining or executing a macro,
the special meaning of key sequences (as Vi macros) is ignored.  This
is because it is all too easy to create an infinite loop in this way.
Since Viper macros are much more powerful than Vi's it is impossible to
detect such loops. In practice, this is not really a limitation but,
rather, a feature.

   We should also note that Vi macros are disabled in the Minibuffer,
which helps keep some potential troubles away.

   The rate at which the user must type keys in order for them to be
recognized as a timeout macro is controlled by the variable
`vip-fast-keyseq-timeout', which defaults to 200 milliseconds.

   For the most part, Viper macros defined in `~/.vip' can be shared
between Emacs, XEmacs, and X and TTY modes.  However, macros defined via
function keys may need separate definitions when XEmacs and Emacs have
different names for the same keyboard key. For instance, the `Page Up'
key may be known in Emacs as `prior' and in XEmacs as `pgup'.  The
problem with TTY may be that the function keys there generate sequences
of events instead of a single event (as under a window system).  Both
Emacs and XEmacs mape some of these sequences back to the logical keys
(e.g., the sequences generated by the arrow keys are mapped to `up',
`left', etc.). However, not all function keys are mapped in this way.
Macros that are bound to key sequences that contain such unmapped
function keys have to be redefined for TTY's (and possibly for every
type of TTY you may be using). To do this, start Emacs on an
appropriate TTY device and define the macro using `:map', as usual.

   Finally, Viper provides a function that conveniently displays all
macros currently defined. To see all macros along with their
definitions, type `M-x vip-describe-kbd-macros'.


File: viper,  Node: Commands,  Prev: Customization,  Up: Top

   Top

Commands
********

   This section is a semi-automatically bowdlerized version of the Vi
reference created by
`maart@cs.vu.nl' and others. It can be found on the Vi archives. Very
little has been changed for Viper.

* Menu:

* Groundwork::			Textual Conventions and Viper basics
* Text Handling::		Moving, Editing, Undoing.
* Display::			Scrolling.
* File and Buffer Handling::	Editing, Writing and Quitting.
* Mapping::			Mapping Keys, Keyboard Macros
* Shell Commands::		Accessing Shell Commands, Processing Text
* Options::			Ex options, the `:set' commands
* Emacs Related Commands::	Meta Keys, Windows
* Mouse-bound Commands::        Search and insertion of text


File: viper,  Node: Groundwork,  Next: Text Handling,  Prev: Commands,  Up: Commands

Groundwork
==========

   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', `'',  `[[',
     `]]', `[]'

Text Deletion Commands (*Note Deleting Text::), Change commands (*Note
Changing Text::), even Shell Commands (*Note Shell Commands::) use
these commands to describe a region of text to operate on.

   Viper adds two region descriptors, `r' and `R'. These describe the
Emacs regions (*Note Basics::), but they are not movement commands.

   The command description uses angle brackets `<>' to indicate
metasyntactic variables, since the normal conventions of using simple
text can be confusing with Viper where the commands themselves are
characters. Watch out where `<' shift commands and `<count>' are
mentioned together!!!

   `<move>' refers to the above movement commands, and `<a-z>' refers
to registers or textmarkers from `a' to `z'. Note that the `<move>'  is
described by full move commands, that is to say they will take counts,
and otherwise behave like normal move commands.  `<address>' refers to
Ex line addresses, which include

`. <No address>'
     Current line

`.+n .-n'
     Add or subtract for current line

`number'
     Actual line number, use `.=' to get the line number

`'<a-z>'
     Textmarker

`$'
     Last line

`x,y'
     Where x and y are one of the above

`%'
     For the whole file, same as (1,$).

`/pat/'
`?pat?'
     Next or previous line with pattern pat

   Note that `%' is used in Ex commands to mean current file. If you
want a `%' in your command, it must be escaped as `\%'.  Similarly, `#'
expands to the previous file. The previous file is the first file in
`:args' listing. This defaults to previous window in the VI sense if
you have one window only.

Others like `<args> -- arguments', `<cmd> -- command' etc.  should be
fairly obvious.

Common characters referred to include:

`<sp>'
     Space

`<ht>'
     Tab

`<lf>'
     Linefeed

`<esc>'
     Escape

`<cr>'
     Return, Enter

   We also use `word' for alphanumeric/non-alphanumeric words, and
`WORD' for whitespace delimited words. `char' refers to any ASCII
character, `CHAR' to non-whitespace character.  Brackets `[]' indicate
optional parameters; `<count>' also optional, usually defaulting to 1.
Brackets are elided for `<count>' to eschew obfuscation.

   Viper's idea of Vi's words is slightly different from Vi. First,
Viper words understand Emacs symbol tables. Therefore, all symbols
declared to be alphanumeric in a symbol table can automatically be made
part of the Viper word.  This is useful when, for instance, editing
text containing European, Cyrillic, etc., letters.

   Second, Viper lets you depart from Vi's idea of a word by changing
the value of `vip-syntax-preference'. By default, this variable is set
to `'strict-vi', which means that alphanumeric symbols are exactly as
in Vi.  However, if the value is `'reformed-vi' then 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 value of `vip-syntax-preference'.

   The above discussion concerns only the 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 order to not
thwart the various major modes that set these tables.

   The usual Emacs convention is used to indicate Control Characters,
i.e C-h for Control-h. *Do not confuse this to mean the separate
characters C - h!!!* The `^' is itself, never used to indicate a
Control character.


File: viper,  Node: Text Handling,  Next: Display,  Prev: Groundwork,  Up: Commands

Text Handling
=============

* Menu:

* Move Commands::		Moving, Searching
* Marking::		        Textmarkers in Viper and the Emacs Mark.
* Appending Text::		Text insertion, Shifting, Putting
* Editing in Insert State::	Autoindent, Quoting etc.
* Deleting Text::		Deleting
* Changing Text::		Changing, Replacement, Joining
* Search and Replace::		Searches, Query Replace, Pattern Commands
* Yanking::			Yanking, Viewing Registers
* Undoing::			Multiple Undo, Backups


File: viper,  Node: Move Commands,  Next: Marking,  Up: Text Handling

Move Commands
-------------

`<count>  h  C-h'
     <count> chars to the left.

`<count>  j  <lf> C-n'
     <count> lines downward.

`<count>  l  <sp>'
     <count> chars to the right.

`<count>  k  C-p'
     <count> lines upward.

`<count>  $'
     To the end of line <count> from the cursor.

`<count>  ^'
     To the first CHAR <count> - 1 lines lower.

`<count>  -'
     To the first CHAR <count> lines higher.

`<count>  +  <cr>'
     To the first CHAR <count> lines lower.

`0'
     To the first char of the line.

`<count> |'
     To column <count>

`<count>  f<char>'
     <count> <char>s to the right (find).

`<count>  t<char>'
     Till before <count> <char>s to the right.

`<count>  F<char>'
     <count> <char>s to the left.

`<count>  T<char>'
     Till after <count> <char>s to the left.

`<count>  ;'
     Repeat latest `f t F T' <count> times.

`<count>  ,'
     Repeat latest `f t F T' <count> times in opposite direction.

`<count>  w'
     <count> words forward.

`<count>  W'
     <count> WORDS forward.

`<count>  b'
     <count> words backward.

`<count>  B'
     <count> WORDS backward.

`<count>  e'
     To the end of word <count> forward.

`<count>  E'
     To the end of WORD <count> forward.

`<count>  G'
     Go to line <count> (default end-of-file).

`<count>  H'
     To line <count> from top of the screen (home).

`<count>  L'
     To line <count> from bottom of the screen (last).

`M'
     To the middle line of the screen.

`<count>  )'
     <count> sentences forward.

`<count>  ('
     <count> sentences backward.

`<count>  }'
     <count> paragraphs forward.

`<count>  {'
     <count> paragraphs backward.

`<count>  ]]'
     To the <count>th heading.

`<count>  [['
     To the <count>th previous heading.

`<count>  []'
     To the end of <count>th heading.

`m<a-z>'
     Mark the cursor position with a letter.

``<a-z>'
     To the mark.

`'<a-z>'
     To the first CHAR of the line with the mark.

`[<a-z>'
     Show contents of textmarker.

`]<a-z>'
     Show contents of register.

```'
     To the cursor position before the latest absolute jump (of which
     are examples `/' and `G').

`'''
     To the first CHAR of the line on which the cursor was placed
     before the latest absolute jump.

`<count>  /<string>'
     To the <count>th occurrence of <string>.

`<count>  /<cr>'
     To the <count>th occurrence of <string> from previous `/ or ?'.

`<count>  ?<string>'
     To the <count>th previous occurrence of <string>.

`<count>  ?<cr>'
     To the <count>th previous occurrence of <string> from previous `?
     or /'.

`n'
     Repeat latest `/' `?' (next).

`N'
     Repeat latest search in opposite direction.

`C-c /'
     Without a prefix argument, this command toggles
     case-sensitive/case-insensitive search modes and plain
     vanilla/regular expression search. With the prefix argument 1,
     i.e., `1 C-c /', this toggles case-sensitivity; with the prefix
     argument 2, toggles plain vanilla search and search using regular
     expressions. *Note Viper Specials::, for alternative ways to invoke
     this function.

`%'
     Find the next bracket and go to its match.


File: viper,  Node: Marking,  Next: Appending Text,  Prev: Move Commands,  Up: Text Handling

Marking
-------

   Emacs mark is referred to in the region specifiers `r' and `R'.
*Note Emacs Preliminaries:: and *note Basics::. for explanation. Also
see *Note Mark: (emacs)Mark, for an explanation of the Emacs mark ring.

`m<a-z>'
     Mark the current file and position with the specified letter.

`m .'
     Set the Emacs mark (*Note Emacs Preliminaries::) at point.

`m <'
     Set the Emacs mark at beginning of buffer.

`m >'
     Set the Emacs mark at end of buffer.

`m ,'
     Jump to the Emacs mark.

`:mark <char>'
     Mark position with text marker named <char>. This is an Ex command.

`:k <char>'
     Same as `:mark'.

```'
     Exchange point and mark.

`'''
     Exchange point and mark and go to the first CHAR on line.

`'<a-z>'
     Go to specified Viper mark.

`'
     Go to specified Viper mark and go to the first CHAR on line.


File: viper,  Node: Appending Text,  Next: Editing in Insert State,  Prev: Marking,  Up: Text Handling

Appending Text
--------------

   *Note Options:: to see how to change tab and shiftwidth size. See
the GNU Emacs manual, or try `C-ha tabs' (If you have turned Emacs help
on).  Check out the variable `indent-tabs-mode' to put in just spaces.
Also see options for word-wrap.

`<count>  a'
     <count> times after the cursor.

`<count>  A'
     <count> times at the end of line.

`<count>  i'
     <count> times before the cursor (insert).

`<count>  I'
     <count> times before the first CHAR of the line

`<count>  o'
     On a new line below the current (open).  The count is only useful
     on a slow terminal.

`<count>  O'
     On a new line above the current.  The count is only useful on a
     slow terminal.

`<count>  ><move>'
     Shift the lines described by <count><move> one shiftwidth to the
     right (layout!).

`<count>  >>'
     Shift <count> lines one shiftwidth to the right.

`<count>  ["<a-z1-9>]p'
     Put the contents of the (default undo) buffer <count> times after
     the cursor. The register will be automatically downcased.

`<count>  ["<a-z1-9>]P'
     Put the contents of the (default undo) buffer <count> times before
     the cursor. The register will

`[<a-z>'
     Show contents of textmarker.

`]<a-z>'
     Show contents of register.

`<count>  .'
     Repeat previous command <count> times. For destructive commands as
     well as undo.

`f1 1 and f1 2'
     While `.' repeats the last destructive command, these two macros
     repeat the second-last and the third-last destructive commands.
     *Note Vi Macros::, for more information on Vi macros.

`C-c M-p and C-c M-n'
     In Vi state, these commands help peruse the history of Vi's
     destructive commands.  Successive typing of `C-c M-p' causes Viper
     to search the history in the direction of older commands, while
     hitting `C-c M-n' does so in reverse order. Each command in the
     history is displayed in the Minibuffer. The displayed command can
     then be executed by typing ``.''.

     Since typing the above sequences of keys may be tedious, the
     functions doing the perusing can be bound to unused keyboard keys
     in the `~/.vip' file. *Note Viper Specials::, for details.


File: viper,  Node: Editing in Insert State,  Next: Deleting Text,  Prev: Appending Text,  Up: Text Handling

Editing in Insert State
-----------------------

   Minibuffer can be edited similarly to Insert state, and you can
switch between Insert/Replace/Vi states at will.  Some users prefer
plain Emacs feel in the Minibuffer. To this end, set
VIP-VI-STYLE-IN-MINIBUFFER to `nil'.

`C-v'
     Deprive the next char of its special meaning (quoting).

`C-h'
     One char back.

`C-w'
     One word back.

`C-u'
     Back to the begin of the change on the current line.


File: viper,  Node: Deleting Text,  Next: Changing Text,  Prev: Editing in Insert State,  Up: Text Handling

Deleting Text
-------------

   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.

`<count>  x'
     Delete <count> chars under and after the cursor.

`<count>  X'
     Delete <count> chars before the cursor.

`<count>  d<move>'
     Delete from point to endpoint of <count><move>.

`<count>  dd'
     Delete <count> lines.

`D'
     The rest of the line.

`<count>  <<move>'
     Shift the lines described by <count><move> one shiftwidth to the
     left (layout!).

`<count>  <<'
     Shift <count> lines one shiftwidth to the left.


File: viper,  Node: Changing Text,  Next: Search and Replace,  Prev: Deleting Text,  Up: Text Handling

Changing Text
-------------

`<count>  r<char>'
     Replace <count> chars by <char> - no <esc>.

`<count>  R'
     Overwrite the rest of the line, appending change COUNT - 1 times.

`<count>  s'
     Substitute <count> chars.

`<count>  S'
     Change <count> lines.

`<count>  c<move>'
     Change from begin to endpoint of <count><move>.

`<count>  cc'
     Change <count> lines.

`<count>  C'
     The rest of the line and <count> - 1 next lines.

`<count>  =<move>'
     Reindent the region described by move.

`<count>  ~'
     Switch lower and upper cases.

`<count>  J'
     Join <count> lines (default 2).

`:[x,y]s/<p>/<r>/<f>'
     Substitute (on lines x through y) the pattern <p> (default the
     last pattern) with <r>.  Useful flags <f> are `g' for `global'
     (i.e. change every non-overlapping occurrence of <p>) and `c' for
     `confirm' (type `y' to confirm a particular substitution, else `n'
     ).  Instead of `/' any punctuation CHAR unequal to <space> <tab>
     and <lf> can be used as delimiter.

`:[x,y]copy [z]'
     Copy text between `x' and `y' to the position after `z'.

`:[x,y]t [z]'
     Same as `:copy'.

`:[x,y]move [z]'
     Move text between `x' and `y' to the position after `z'.

`&'
     Repeat latest Ex substitute command, e.g.  `:s/wrong/good'.

`C-c /'
     Toggle case-sensitive search. With prefix argument, toggle
     vanilla/regular expression search.

`#c<move>'
     Change upper case characters in the region to lower case.

`#C<move>'
     Change lower case characters in the region to upper case.

`#q<move>'
     Insert specified string at the beginning of each line in the region

`C-c M-p and C-c M-n'
     In Insert and Replace states, these keys are bound to commands
     that peruse the history of the text previously inserted in other
     insert or replace commands. By repeatedly typing `C-c M-p' or `C-c
     M-n', you will cause Viper to insert these previously used strings
     one by one.  When a new string is inserted, the previous one is
     deleted.

     In Vi state, these keys are bound to functions that peruse the
     history of destructive Vi commands.  *Note Viper Specials::, for
     details.


File: viper,  Node: Search and Replace,  Next: Yanking,  Prev: Changing Text,  Up: Text Handling

Search and Replace
------------------

   *Note Groundwork::, for Ex address syntax. *Note Options:: to see
how to get literal (non-regular-expression) search and how to stop
search from wrapping around.

`<count>  /<string>'
     To the <count>th occurrence of <string>.

`<count>  ?<string>'
     To the <count>th previous occurrence of <string>.

`<count>  g<move>'
     Search for the text described by move. (off by default)

`n'
     Repeat latest `/' `?' (next).

`N'
     Idem in opposite direction.

`%'
     Find the next bracket and go to its match

`:[x,y]g/<string>/<cmd>'
     Search globally [from line x to y] for <string> and execute the Ex
     <cmd> on each occurrence.

`:[x,y]v/<string>/<cmd>'
     Execute <cmd> on the lines that don't match.

`#g<move>'
     Execute the last keyboard macro for each line in the region.
     *Note Macros and Registers::, for more info.

`Q'
     Query Replace.

`:ta <name>'
     Search in the tags file where <name> is defined (file, line), and
     go to it.

`:[x,y]s/<p>/<r>/<f>'
     Substitute (on lines x through y) the pattern <p> (default the last
     pattern) with <r>.  Useful flags <f> are `g' for `global' (i.e.
     change every non-overlapping occurrence of <p>) and `c' for
     `confirm' (type `y' to confirm a particular substitution, else
     `n').  Instead of `/' any punctuation CHAR unequal to <space>
     <tab> and <lf> can be used as delimiter.

`&'
     Repeat latest Ex substitute command, e.g. `:s/wrong/good'.


File: viper,  Node: Yanking,  Next: Undoing,  Prev: Search and Replace,  Up: Text Handling

Yanking
-------

`<count>  y<move>'
     Yank from begin to endpoint of <count><move>.

`<count>  "<a-z>y<move>'
     Yank from begin to endpoint of <count><move> to register.

`<count>  "<A-Z>y<move>'
     Yank from begin to endpoint of <count><move> and append to
     register.

`<count>  yy'
     <count> lines.

`<count>  Y'
     Idem (should be equivalent to `y$' though).

`m<a-z>'
     Mark the cursor position with a letter.

`[<a-z>'
     Show contents of textmarker.

`]<a-z>'
     Show contents of register.

`<count>  ["<a-z1-9>]p'
     Put the contents of the (default undo) buffer <count> times after
     the cursor. The register will be automatically downcased.

`<count>  ["<a-z1-9>]P'
     Put the contents of the (default undo) buffer <count> times before
     the cursor. The register will


File: viper,  Node: Undoing,  Prev: Yanking,  Up: Text Handling

Undoing
-------

`u U'
     Undo the latest change.

`.'
     Repeat undo.

`:q!'
     Quit Vi without writing.

`:e!'
     Re-edit a messed-up file.

`:rec'
     Recover file from autosave. Viper also creates backup files that
     have a `~' appended to them.

