consistently use @insertcopying, @direntry, @contents
[bpt/emacs.git] / doc / misc / viper.texi
CommitLineData
4009494e
GM
1% -*-texinfo-*-
2\input texinfo
3
4@comment Using viper.info instead of viper in setfilename breaks DOS.
5@comment @setfilename viper
6@comment @setfilename viper.info
db78a8cb 7@setfilename ../../info/viper
4009494e
GM
8
9@copying
10Copyright @copyright{} 1995, 1996, 1997, 2001, 2002, 2003, 2004,
6ed161e1 112005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4009494e
GM
12
13@quotation
14Permission is granted to copy, distribute and/or modify this document
6a2c4aec 15under the terms of the GNU Free Documentation License, Version 1.3 or
4009494e 16any later version published by the Free Software Foundation; with no
debf4439
GM
17Invariant Sections, with the Front-Cover texts being ``A GNU Manual'',
18and with the Back-Cover Texts as in (a) below. A copy of the license
19is included in the section entitled ``GNU Free Documentation License''.
4009494e 20
6f093307
GM
21(a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
22modify this GNU manual. Buying copies from the FSF supports it in
23developing GNU and promoting software freedom.''
4009494e
GM
24@end quotation
25@end copying
26
27@dircategory Emacs
28@direntry
29* VIPER: (viper). The newest Emacs VI-emulation mode.
30 (also, A VI Plan for Emacs Rescue
31 or the VI PERil.)
32@end direntry
33
34@finalout
35
36@titlepage
37@title Viper Is a Package for Emacs Rebels
38@subtitle a Vi emulator for Emacs
c7cac5cc 39@subtitle November 2008, Viper Version 3.11.2
4009494e
GM
40
41@author Michael Kifer (Viper)
42@author Aamod Sane (VIP 4.4)
43@author Masahiko Sato (VIP 3.5)
44
45@page
46@vskip 0pt plus 1filll
47@insertcopying
48@end titlepage
49
5dc584b5
KB
50@contents
51
4009494e
GM
52@ifnottex
53@node Top, Overview,, (DIR)
54
55@unnumbered Viper
56
57We believe that one or more of the following statements are adequate
58descriptions of Viper:
59
60@example
61Viper Is a Package for Emacs Rebels;
62it is a VI Plan for Emacs Rescue
63and/or a venomous VI PERil.
64@end example
65
66Technically speaking, Viper is a Vi emulation package for Emacs. It
67implements all Vi and Ex commands, occasionally improving on them and
68adding many new features. It gives the user the best of both worlds: Vi
69keystrokes for editing combined with the power of the Emacs environment.
70
71Viper emulates Vi at several levels, from the one that closely follows Vi
72conventions to the one that departs from many of them. It has many
73customizable options, which can be used to tailor Viper to the work habits
74of various users.
75This manual describes Viper, concentrating on the differences from Vi and
76new features of Viper.
77
78Viper, formerly known as VIP-19, was written by Michael Kifer. It is based
79on VIP version 3.5 by Masahiko Sato and VIP version 4.4 by Aamod Sane.
80About 15% of the code still comes from those older packages.
81
82Viper is intended to be usable without reading this manual --- the defaults
83are set to make Viper as close to Vi as possible. At startup, Viper will
84try to set the most appropriate default environment for you, based on
85your familiarity with Emacs. It will also tell you the basic GNU Emacs window
86management commands to help you start immediately.
87
88Although this manual explains how to customize Viper, some basic
89familiarity with Emacs Lisp is a plus.
90
91It is recommended that you read the Overview node. The other nodes may
92be visited as needed.
93
94Comments and bug reports are welcome.
95@code{kifer@@cs.stonybrook.edu} is the current address for Viper bug reports.
96Please use the Ex command @kbd{:submitReport} for this purpose.@refill
97
5dc584b5 98@insertcopying
4009494e
GM
99@end ifnottex
100
101@menu
102* Overview:: Read for a smoother start
103* Improvements over Vi:: New features, Improvements
104* Customization:: How to customize Viper
105* Commands:: Vi and Ex Commands
106
107* Key Index:: Index of Vi and Ex Commands
108* Function Index:: Index of Viper Functions
109* Variable Index:: Index of Viper Variables
110* Package Index:: Index of Packages Mentioned in this Document
111* Concept Index:: Vi, Ex and Emacs concepts
112
113* Acknowledgments::
114* GNU Free Documentation License:: The license for this documentation.
115
116@end menu
117@iftex
118@unnumbered Introduction
119
120We believe that one or more of the following statements are adequate
121descriptions of Viper:
122
123@example
124Viper Is a Package for Emacs Rebels;
125it is a VI Plan for Emacs Rescue
126and/or a venomous VI PERil.
127@end example
128
129Viper is a Vi emulation package for Emacs. Viper contains virtually all
130of Vi and Ex functionality and much more. It gives you the best of both
131worlds: Vi keystrokes for editing combined with the GNU Emacs
132environment. Viper also fixes some common complaints with Vi commands.
133This manual describes Viper, concentrating on the differences from Vi
134and on the new features of Viper.
135
136Viper was written by Michael Kifer. It is based on VIP version 3.5 by
137Masahiko Sato and VIP version 4.4 by Aamod Sane. About 15% of the code
138still comes from those older packages.
139
140Viper is intended to be usable out of the box, without reading this manual
141--- the defaults are set to make Viper as close to Vi as possible. At
142startup, Viper will attempt to set the most appropriate default environment
143for you, based on your familiarity with Emacs. It will also tell you the
144basic GNU Emacs window management commands to help you start immediately.
145
146Although this manual explains how to customize Viper, some basic
147familiarity with Emacs Lisp is a plus.
148
149It is recommended that you read the chapter Overview. The other chapters
150will be useful for customization and advanced usage.
151
152You should also learn to use the Info on-line hypertext manual system that
153comes with Emacs. This manual can be read as an Info file. Try the command
154@kbd{@key{ESC} x info} with vanilla Emacs sometime.
155
156Comments and bug reports are welcome.
157@code{kifer@@cs.stonybrook.edu} is the current address for Viper bug reports.
158Please use the Ex command @kbd{:submitReport} for this purpose.@refill
159
160@end iftex
161
162@node Overview,Improvements over Vi,Top,Top
163@chapter Overview of Viper
164
165Viper is a Vi emulation on top of Emacs. At the same time, Viper provides a
166virtually unrestricted access to Emacs facilities. Perfect compatibility
167with Vi is possible but not desirable. This chapter tells you about the
168Emacs ideas that you should know about, how to use Viper within Emacs and
169some incompatibilities.
170
171This manual is written with the assumption that you are an experienced Vi
172user who wants to switch to Emacs while retaining the ability to edit files
173Vi style. Incredible as it might seem, there are experienced Emacs users
174who use Viper as a backdoor into the superior (as every Vi user already knows)
175world of Vi! These users are well familiar with Emacs bindings and prefer them
176in some cases, especially in the Vi Insert state. John Hawkins
177<jshawkin@@eecs.umich.edu> has provided a set of customizations, which
178enables additional Emacs bindings under Viper. These customizations can be
179included in your @file{~/.viper} file and are found at the following URL:
180@file{http://traeki.freeshell.org/files/viper-sample}.
181
182@menu
183* Emacs Preliminaries:: Basic concepts in Emacs.
184* Loading Viper:: Loading and Preliminary Configuration.
185* States in Viper:: Viper has four states orthogonal to Emacs
186 modes.
187* The Minibuffer:: Command line in Emacs.
188* Multiple Files in Viper:: True multiple file handling.
189* Unimplemented Features:: That are unlikely to be implemented.
190@end menu
191
192@node Emacs Preliminaries, Loading Viper, Overview, Overview
193@section Emacs Preliminaries
194
195@cindex buffer
196@cindex point
197@cindex mark
198@cindex text
199@cindex looking at
200@cindex end (of buffer)
201@cindex end (of line)
202@cindex region
203
204Emacs can edit several files at once. A file in Emacs is placed in a
205@dfn{buffer} that usually has the same name as the file. Buffers are also used
206for other purposes, such as shell interfaces, directory editing, etc.
207@xref{Dired,,Directory Editor,emacs,The
208GNU Emacs Manual}, for an example.@refill
209
210A buffer has a distinguished position called the @dfn{point}.
211A @dfn{point} is always between 2 characters, and is @dfn{looking at}
212the right hand character. The cursor is positioned on the right hand
213character. Thus, when the @dfn{point} is looking at the end-of-line,
214the cursor is on the end-of-line character, i.e.@: beyond the last
215character on the line. This is the default Emacs behavior.@refill
216
217The default settings of Viper try to mimic the behavior of Vi, preventing
218the cursor from going beyond the last character on the line. By using
219Emacs commands directly (such as those bound to arrow keys), it is possible
220to get the cursor beyond the end-of-line. However, this won't (or
221shouldn't) happen if you restrict yourself to standard Vi keys, unless you
222modify the default editing style. @xref{Customization}.@refill
223
224In addition to the @dfn{point}, there is another distinguished buffer
225position called the @dfn{mark}. @xref{Mark,,Mark,emacs,The GNU Emacs
226manual}, for more info on the mark. The text between the @dfn{point} and
227the @dfn{mark} is called the @dfn{region} of the buffer. For the Viper
228user, this simply means that in addition to the Vi textmarkers a--z, there
229is another marker called @dfn{mark}. This is similar to the unnamed Vi
230marker used by the jump commands @kbd{``} and @kbd{''}, which move the
231cursor to the position of the last absolute jump. Viper provides access to
232the region in most text manipulation commands as @kbd{r} and @kbd{R} suffix
233to commands that operate on text regions, e.g., @kbd{dr} to delete region,
234etc.
235
236Furthermore, Viper lets Ex-style commands to work on the current region.
237This is done by typing a digit argument before @kbd{:}. For instance,
238typing @kbd{1:} will prompt you with something like @emph{:123,135},
239assuming that the current region starts at line 123 and ends at line
240135. There is no need to type the line numbers, since Viper inserts them
241automatically in front of the Ex command.
242
243@xref{Basics}, for more info.@refill
244
245@cindex window
246@cindex mode line
247@cindex buffer information
248@cindex Minibuffer
249@cindex command line
250@cindex buffer (modified)
251
252Emacs divides the screen into tiled @dfn{windows}. You can see the
253contents of a buffer through the window associated with the buffer. The
254cursor of the screen is positioned on the character after @dfn{point}.
255Every window has a @dfn{mode line} that displays information about the buffer.
256You can change the format of the mode
257line, but normally if you see @samp{**} at the beginning of a mode line it
258means that the buffer is @dfn{modified}. If you write out the contents of
259a buffer to a file, then the buffer will become not modified. Also if
260you see @samp{%%} at the beginning of the mode line, it means that the file
261associated with the buffer is write protected. The mode line will also
262show the buffer name and current major and minor modes (see below).
263A special buffer called @dfn{Minibuffer} is displayed as the last line
264in a Minibuffer window. The Minibuffer window is used for command input
265output. Viper uses Minibuffer window for @kbd{/} and @kbd{:}
266commands.@refill
267
268@cindex mode
269@cindex keymap
270@cindex local keymap
271@cindex global keymap
272@cindex major mode
273@cindex minor mode
274
275An Emacs buffer can have a @dfn{major mode} that customizes Emacs for
276editing text of a particular sort by changing the functionality of the keys.
277Keys are defined using a @dfn{keymap} that records the bindings between
278keystrokes and
279functions. The @dfn{global keymap} is common to all the
280buffers. Additionally, each buffer has its @dfn{local keymap} that determines the
281@dfn{mode} of the buffer. If a function is bound to some key in the local
282keymap then that function will be executed when you type the key.
283If no function is bound to a key in the
284local map, however, the function bound to the key in the global map
285will be executed. @xref{Major Modes,Major Modes,Major Modes,emacs,The
286GNU Emacs Manual}, for more information.@refill
287
288A buffer can also have a @dfn{minor mode}. Minor modes are options that
289you can use or not. A buffer in @code{text-mode} can have
290@code{auto-fill-mode} as minor mode, which can be turned off or on at
291any time. In Emacs, a minor mode may have it own keymap,
292which overrides the local keymap when the minor mode is turned on. For
293more information, @pxref{Minor Modes,Minor Modes,Minor Modes,emacs,The
294GNU Emacs Manual} @refill
295
296@cindex Viper as minor mode
297@cindex Control keys
298@cindex Meta key
299
300Viper is implemented as a collection of minor modes. Different minor modes
301are involved when Viper emulates Vi command mode, Vi insert mode, etc.
302You can also turn Viper on and off at any time while in Vi command mode.
303@xref{States in Viper}, for
304more information.@refill
305
306Emacs uses Control and Meta modifiers. These are denoted as C and M,
307e.g.@: @kbd{^Z} as @kbd{C-z} and @kbd{Meta-x} as @kbd{M-x}. The Meta key is
308usually located on each side of the Space bar; it is used in a manner
309similar to the Control key, e.g., @kbd{M-x} means typing @kbd{x} while
310holding the Meta key down. For keyboards that do not have a Meta key,
311@key{ESC} is used as Meta. Thus @kbd{M-x} is typed as @kbd{@key{ESC}
312x}. Viper uses @key{ESC} to switch from Insert state to Vi state. Therefore
313Viper defines @kbd{C-\} as its Meta key in Vi state. @xref{Vi State}, for
314more info.@refill
315
316Emacs is structured as a Lisp interpreter around a C core. Emacs keys
317cause Lisp functions to be called. It is possible to call these
318functions directly, by typing @kbd{M-x function-name}.
319
320@node Loading Viper, States in Viper, Emacs Preliminaries, Overview
321@section Loading Viper
322
323The most common way to load it automatically is to include the following
324lines (in the given order!):
325
326@lisp
327(setq viper-mode t)
328(require 'viper)
329@end lisp
330
331@noindent
332in your @file{~/.emacs} file. The @file{.emacs} file is placed in your
333home directory and it is be executed every time you invoke Emacs. This is
334the place where all general Emacs customization takes place. Beginning with
335version 20.0, Emacsen have an interactive interface, which simplifies the
336job of customization significantly.
337
338Viper also uses the file @file{~/.viper} for Viper-specific customization.
339The location of Viper customization file can be changed by setting the
340variable @code{viper-custom-file-name} in @file{.emacs} @emph{prior} to loading
341Viper.
342
343The latest versions of Emacs have an interactive customization facility,
344which allows you to (mostly) bypass the use of the @file{.emacs} and
345@file{.viper} files. You can reach this customization
346facility from within Viper's VI state by executing the Ex command
347@kbd{:customize}.
348
349Once invoked, Viper will arrange to bring up Emacs buffers in Vi state
350whenever this makes sense.
351@xref{Packages that Change Keymaps}, to find out when forcing Vi command state
352on a buffer may be counter-productive.
353
354Even if your @file{.emacs} file does not invoke Viper automatically,
355you can still load Viper and enter the Vi command state by typing the
356following from within Emacs:
357
358@lisp
359M-x viper-mode
360@end lisp
361
362When Emacs first comes up, if you have not specified a file on the
363command line, it will show the @samp{*scratch*} buffer, in the
364@samp{Lisp Interaction} mode. After you invoke Viper, you can start
365editing files by using @kbd{:e}, @kbd{:vi}, or @kbd{v} commands.
366(@xref{File and Buffer Handling}, for more information on @kbd{v} and other
367new commands that, in many cases, are more convenient than @kbd{:e},
368@kbd{:vi}, and similar old-style Vi commands.)@refill
369
370Finally, if at some point you would want to de-Viperize your running
371copy of Emacs after Viper has been loaded, the command @kbd{M-x
372viper-go-away} will do it for you. The function @code{toggle-viper-mode}
373toggles Viperization of Emacs on and off.
374
375@node States in Viper, The Minibuffer, Loading Viper,Overview
376@section States in Viper
377
378@kindex @kbd{C-z}
379@kindex @key{ESC}
380@kindex @kbd{i}
381@cindex Emacs state
382@cindex Vi state
383@cindex Insert state
384@cindex Replace state
385@cindex Ex commands
386@findex @code{viper-go-away}
387@findex @code{toggle-viper-mode}
388
389Viper has four states, Emacs, Vi, Insert, and Replace.
390
391@table @samp
392@item Emacs state
393This is the state plain vanilla Emacs is normally in. After you have loaded
394Viper, @kbd{C-z} will normally take you to Vi command state. Another
395@kbd{C-z} will take you back to Emacs state. This toggle key can be
396changed, @pxref{Customization} You can also type @kbd{M-x viper-mode} to
397change to Vi state.@refill
398
399
400For users who chose to set their user level to 1 at Viper setup time,
401switching to Emacs state is deliberately made harder in order to not
402confuse the novice user. In this case, @kbd{C-z} will either iconify Emacs
403(if Emacs runs as an application under X) or it will stop Emacs (if
404Emacs runs on a dumb terminal or in an Xterm window).
405
406@item Vi state
407This is the Vi command mode. Any of the Vi commands, such as @kbd{i, o, a},
408@dots{}, will take you to Insert state. All Vi commands may
409be used in this mode. Most Ex commands can also be used.
410For a full list of Ex commands supported by Viper, type
411@kbd{:} and then @key{TAB}. To get help on any issue, including the Ex
412commands, type @kbd{:help}. This will invoke Viper Info
413(if it is installed). Then typing @kbd{i} will prompt you for a topic to
414search in the index. Note: to search for Ex commands in the index, you
415should start them with a @kbd{:}, e.g., @kbd{:WW}.
416
417In Viper, Ex commands can be made to work on the current Emacs region.
418This is done by typing a digit argument before @kbd{:}.
419For instance, typing @kbd{1:} will prompt you with something like
420@emph{:123,135}, assuming that the current region starts at line 123 and
421ends at line 135. There is no need to type the line numbers, since Viper
422inserts them automatically in front of the Ex command.
423
424@item Insert state
425Insert state is the Vi insertion mode. @key{ESC} will take you back to
426Vi state. Insert state editing can be done, including auto-indentation. By
427default, Viper disables Emacs key bindings in Insert state.
428
429@item Replace state
430Commands like @kbd{cw} invoke the Replace state. When you cross the
431boundary of a replacement region (usually designated via a @samp{$} sign),
432it will automatically change to Insert state. You do not have to worry
433about it. The key bindings remain practically the same as in Insert
434state. If you type @key{ESC}, Viper will switch to Vi command mode, terminating the
435replacement state.@refill
436@end table
437
438@cindex mode line
439
440The modes are indicated on the @dfn{mode line} as <E>, <I>, <V>, and <R>,
441so that the multiple modes do not confuse you. Most of your editing can be
442done in Vi and Insert states. Viper will try to make all new buffers be in Vi
443state, but sometimes they may come up in Emacs state. @kbd{C-z}
444will take you to Vi state in such a case. In some major modes, like Dired,
445Info, Gnus, etc., you should not switch to Vi state (and Viper will not
446attempt to do so) because these modes are not intended for text editing and
447many of the Vi keys have special meaning there. If you plan to read news,
448browse directories, read mail, etc., from Emacs (which you should start
449doing soon!), you should learn about the meaning of the various keys in
450those special modes (typing @kbd{C-h m} in a buffer provides
451help with key bindings for the major mode of that buffer).
452
453If you switch to Vi in Dired or similar modes---no harm is done. It is just
454that the special key bindings provided by those modes will be temporarily
455overshadowed by Viper's bindings. Switching back to Viper's Emacs state
456will revive the environment provided by the current major mode.
457
458States in Viper are orthogonal to Emacs major modes, such as C mode or Dired
459mode. You can turn Viper on and off for any Emacs state. When Viper is turned
460on, Vi state can be used to move around. In Insert state, the bindings for
461these modes can be accessed. For beginners (users at Viper levels 1 and 2),
462these bindings are suppressed in Insert state, so that new users are not
463confused by the Emacs states. Note that unless you allow Emacs bindings in
464Insert state, you cannot do many interesting things, like language
465sensitive editing. For the novice user (at Viper level 1), all major mode
466bindings are turned off in Vi state as well. This includes the bindings for
467key sequences that start with @kbd{C-c}, which practically means that all
468major mode bindings are unsupported. @xref{Customization}, to find out how
469to allow Emacs keys in Insert state.
470
471@menu
472* Emacs State:: This is the state you should learn more about when
473 you get up to speed with Viper.
474* Vi State:: Vi commands are executed in this state.
475* Insert State:: You can enter text, and also can do sophisticated
476 editing if you know enough Emacs commands.
477* Replace State:: Like Insert mode, but it is invoked via the
478 replacement commands, such as cw, C, R, etc.
479@end menu
480
481@node Emacs State, Vi State, States in Viper, States in Viper
482@subsection Emacs State
483
484@kindex @kbd{C-z}
485@cindex Emacs state
486
487
488You will be in this mode only by accident (hopefully). This is the state
489Emacs is normally in (imagine!!). Now leave it as soon as possible by
490typing @kbd{C-z}. Then you will be in Vi state (sigh of relief) :-).
491
492Emacs state is actually a Viperism to denote all the major and minor modes
493(@pxref{Emacs Preliminaries}) other than Viper that Emacs can be in. Emacs
494can have several modes, such as C mode for editing C programs, LaTeX mode
495for editing LaTeX documents, Dired for directory editing, etc. These are
496major modes, each with a different set of key-bindings. Viper states are
497orthogonal to these Emacs major modes. The presence of these language
498sensitive and other modes is a major win over Vi. @xref{Improvements over
499Vi}, for more.@refill
500
501The bindings for these modes can be made available in the Viper Insert state
502as well as in Emacs state. Unless you specify your user level as 1 (a
503novice), all major mode key sequences that start with @kbd{C-x} and
504@kbd{C-c} are also available in Vi state. This is important because major
505modes designed for editing files, such as cc-mode or latex-mode, use key
506sequences that begin with @kbd{C-x} and @kbd{C-c}.
507
508There is also a key that lets you temporarily escape to Vi command state
509from the Insert state: typing @kbd{C-z} will let you execute a
510single Vi command while staying in Viper's Insert state.
511
512
513@node Vi State, Insert State, Emacs State, States in Viper
514@subsection Vi State
515
516@cindex Vi state
517
518This is the Vi command mode. When Viper is in Vi state, you will see the sign
519<V> in the mode line. Most keys will work as in Vi. The notable
520exceptions are:
521
522@table @kbd
523@item C-x
524@kindex @kbd{C-x}
525@kbd{C-x} is used to invoke Emacs commands, mainly those that do window
526management. @kbd{C-x 2} will split a window, @kbd{C-x 0} will close a
527window. @kbd{C-x 1} will close all other windows. @kbd{C-xb} is used to
528switch buffers in a window, and @kbd{C-xo} to move through windows.
529These are about the only necessary keystrokes.
530For the rest, see the GNU Emacs Manual.
531
532@item C-c
533@kindex @kbd{C-c}
534For user levels 2 and higher, this key serves as a prefix key for the key
535sequences used by various major modes. For users at Viper level 1, @kbd{C-c}
536simply beeps.
537
538@item C-g and C-]
539@kindex @kbd{C-g}
540@kindex @kbd{C-]}
541
542These are the Emacs @samp{quit} keys.
543There will be cases where you will have to
544use @kbd{C-g} to quit. Similarly, @kbd{C-]} is used to exit
545@samp{Recursive Edits} in Emacs for which there is no comparable Vi
546functionality and no key-binding. Recursive edits are indicated by
547@samp{[]} brackets framing the modes on the mode line.
548@xref{Recursive Edit,Recursive
549Edit,Recursive Edit,emacs,The GNU Emacs Manual}.
550At user level 1, @kbd{C-g} is bound to @code{viper-info-on-file}
551function instead.
552@refill
553@item C-\
554@kindex @kbd{C-\}
555@cindex Meta key
556
557Viper uses @key{ESC} as a switch between Insert and Vi states. Emacs uses
558@key{ESC} for Meta. The Meta key is very important in Emacs since many
559functions are accessible only via that key as @kbd{M-x function-name}.
560Therefore, we need to simulate it somehow. In Viper's Vi, Insert, and
561Replace states, the meta key is set to be @kbd{C-\}. Thus, to get
562@kbd{M-x}, you should type @kbd{C-\ x} (if the keyboard has no Meta key,
563which is rare these days).
564This works both in the Vi command state and in the Insert and Replace
565states. In Vi command state, you can also use @kbd{\ @key{ESC}} as the
566meta key.
567
568Note: Emacs binds @kbd{C-\} to a function that offers to change the
569keyboard input method in the multilingual environment. Viper overrides this
570binding. However, it is still possible to switch the input method by typing
571@kbd{\ C-\} in the Vi command state and @kbd{C-z \ C-\} in the Insert state.
572Or you can use the MULE menu in the menubar.
573@end table
574@noindent
575Other differences are mostly improvements. The ones you should know
576about are:
577
578@table @samp
579@item Undo
580@kindex @kbd{u}
581@kbd{u} will undo. Undo can be repeated by the @kbd{.} key. Undo itself
582can be undone. Another @kbd{u} will change the direction. The presence
583of repeatable undo means that @kbd{U}, undoing lines, is not very
584important. Therefore, @kbd{U} also calls @code{viper-undo}.
585@cindex multiple undo
586@cindex undo
587
588
589@item Counts
590Most commands, @kbd{~}, @kbd{[[}, @kbd{p}, @kbd{/}, @dots{}, etc., take counts.
591
592@comment ]] Just to balance parens
593@item Regexps
594Viper uses Emacs Regular Expressions for searches. These are a superset of
595Vi regular
596expressions, excepting the change-of-case escapes @samp{\u}, @samp{\L},
597@dots{}, etc. @xref{Regexps,,Syntax of Regular Expressions,emacs,The
598GNU Emacs Manual}, for details.
599Files specified to @kbd{:e} use @code{csh} regular expressions
600(globbing, wildcards, what have you).
601However, the function @code{viper-toggle-search-style}, bound to @kbd{C-c /},
602lets the user switch from search with regular expressions to plain vanilla
603search and vice versa. It also lets one switch from case-sensitive search
604to case-insensitive and back.
605@xref{Viper Specials}, for more details.
606@cindex regular expressions
607@cindex vanilla search
608@cindex case-sensitive search
609@cindex case-insensitive search
610@kindex @kbd{C-c /}
611
612@item Ex commands
613@cindex Ex commands
614The current working directory of a buffer is automatically inserted in the
615minibuffer if you type @kbd{:e} then space. Absolute filenames are
616required less often in Viper. For file names, Emacs uses a convention that
617is slightly different from other programs. It is designed to minimize the
618need for deleting file names that Emacs provides in its prompts. (This is
619usually convenient, but occasionally the prompt may suggest a wrong file
620name for you.) If you see a prompt @kbd{/usr/foo/} and you wish to edit the
621file @kbd{~/.viper}, you don't have to erase the prompt. Instead, simply
622continue typing what you need. Emacs will interpret @kbd{/usr/foo/~/.viper}
623correctly. Similarly, if the prompt is @kbd{~/foo/} and you need to get to
624@kbd{/bar/file}, keep typing. Emacs interprets @kbd{~/foo//bar/} as
625@kbd{/bar/file}, since when it sees @samp{//}, it understands that
626@kbd{~/foo/} is to be discarded.
627
628The command @kbd{:cd} will change the default directory for the
629current buffer. The command @kbd{:e} will interpret the
630filename argument in @code{csh}. @xref{Customization}, if you
631want to change the default shell.
632The command @kbd{:next} takes counts from
633@kbd{:args}, so that @kbd{:rew} is obsolete. Also, @kbd{:args} will show only
634the invisible files (i.e., those that are not currently seen in Emacs
635windows).
636
637When applicable, Ex commands support file completion and history. This
638means that by typing a partial file name and then @key{TAB}, Emacs will try
639to complete the name or it will offer a menu of possible completions.
640This works similarly to Tcsh and extends the behavior of Csh. While Emacs
641is waiting for a file name, you can type @kbd{M-p} to get the previous file
642name you typed. Repeatedly typing @kbd{M-p} and @kbd{M-n} will let you
643browse through the file history.
644
645Like file names, partially typed Ex commands can be completed by typing
646@key{TAB}, and Viper keeps the history of Ex commands. After typing
647@kbd{:}, you can browse through the previously entered Ex commands by
648typing @kbd{M-p} and @kbd{M-n}. Viper tries to rationalize when it puts Ex
649commands on the history list. For instance, if you typed @kbd{:w!@: foo},
650only @kbd{:w!} will be placed on the history list. This is because the
651last history element is the default that can be invoked simply by typing
652@kbd{: @key{RET}}. If @kbd{:w!@: foo} were placed on the list, it would be all to
653easy to override valuable data in another file. Reconstructing the full
654command, @kbd{:w!@: foo}, from the history is still not that hard, since Viper
655has a separate history for file names. By typing @kbd{: M-p}, you will get
656@kbd{:w!} in the Minibuffer. Then, repeated @kbd{M-p} will get you through
657the file history, inserting one file name after another.
658
659In contrast to @kbd{:w!@: foo}, if the command were @kbd{:r foo}, the entire
660command will appear in the history list. This is because having @kbd{:r}
661alone as a default is meaningless, since this command requires a file
662argument.
663@refill
664@end table
665@noindent
666As Vi, Viper's destructive commands can be re-executed by typing `@kbd{.}'.
667However, in addition, Viper keeps track of the history of such commands. This
668history can be perused by typing @kbd{C-c M-p} and @kbd{C-c M-n}.
669Having found the appropriate command, it can be then executed by typing
670`@kbd{.}'.
671@xref{Improvements over Vi}, for more information.
672
673@node Insert State, Replace State, Vi State, States in Viper
674@subsection Insert State
675
676@cindex Insert state
677
678To avoid confusing the beginner (at Viper level 1 and 2), Viper makes only the
679standard Vi keys available in Insert state. The implication is that
680Emacs major modes cannot be used in Insert state.
681It is strongly recommended that as soon as you are comfortable, make the
682Emacs state bindings visible (by changing your user level to 3 or higher).
683@xref{Customization},
684to see how to do this.@refill
685
686Once this is done, it is possible to do quite a bit of editing in
687Insert state. For instance, Emacs has a @dfn{yank} command, @kbd{C-y},
688which is similar to Vi's @kbd{p}. However, unlike @kbd{p}, @kbd{C-y} can be
689used in Insert state of Viper. Emacs also has a kill ring where it keeps
690pieces of text you deleted while editing buffers. The command @kbd{M-y} is
691used to delete the text previously put back by Emacs' @kbd{C-y} or by Vi's
692@kbd{p} command and reinsert text that was placed on the kill-ring earlier.
693
694This works both in Vi and Insert states.
695In Vi state, @kbd{M-y} is a much better alternative to the usual Vi's way
696of recovering the 10 previously deleted chunks of text. In Insert state,
697you can
698use this as follows. Suppose you deleted a piece of text and now you need
699to re-insert it while editing in Insert mode. The key @kbd{C-y} will put
700back the most recently deleted chunk. If this is not what you want, type
701@kbd{M-y} repeatedly and, hopefully, you will find the chunk you want.
702
703Finally, in Insert and Replace states, Viper provides the history of
704pieces of text inserted in previous insert or replace commands. These
705strings of text can be recovered by repeatedly typing @kbd{C-c M-p} or
706@kbd{C-c M-n} while in Insert or Replace state. (This feature is disabled
707in the minibuffer: the above keys are usually bound to other histories,
708which are more appropriate in the minibuffer.)
709
710
711@cindex Meta key
712
713You can call Meta functions from Insert state. As in Vi state, the Meta key
714is @kbd{C-\}. Thus @kbd{M-x} is typed as @kbd{C-\ x}.
715
716Other Emacs commands that are useful in Insert state are @kbd{C-e}
717and @kbd{C-a}, which move the cursor to the end and the beginning of the
718current line, respectively. You can also use @kbd{M-f} and @kbd{M-b},
719which move the cursor forward (or backward) one word.
720If your display has a Meta key, these functions are invoked by holding the
721Meta key and then typing @kbd{f} and @kbd{b}, respectively. On displays
722without the Meta key, these functions are invoked by typing
723@kbd{C-\ f} and @kbd{C-\ b} (@kbd{C-\} simulates the Meta key in Insert
724state, as explained above).
725
726The key @kbd{C-z} is sometimes also useful in Insert state: it allows you
727to execute a single command in Vi state without leaving the Insert state!
728For instance, @kbd{C-z d2w} will delete the next two words without leaving
729the Insert state.
730
731When Viper is in Insert state, you will see <I> in the mode line.
732
733@node Replace State,, Insert State, States in Viper
734@subsection Replace State
735
736@cindex Replace state
737
738This state is entered through Vi replacement commands, such as @kbd{C},
739@kbd{cw}, etc., or by typing @kbd{R}. In Replace state, Viper puts <R> in
740the mode line to let you know which state is in effect. If Replace state is
741entered through @kbd{R}, Viper stays in that state until the user hits
742@key{ESC}. If this state is entered via the other replacement commands,
743then Replace state is in effect until you hit @key{ESC} or until you cross
744the rightmost boundary of the replacement region. In the latter case, Viper
745changes its state from Replace to Insert (which you will notice by the
746change in the mode line).
747
748Since Viper runs under Emacs, it is possible to switch between buffers
749while in Replace state. You can also move the cursor using the arrow keys
750(even on dumb terminals!)@: and the mouse. Because of this freedom (which is
751unattainable in regular Vi), it is possible to take the cursor outside the
752replacement region. (This may be necessary for several reasons, including
753the need to enable text selection and region-setting with the mouse.)
754
755The issue then arises as to what to do when the user
756hits the @key{ESC} key. In Vi, this would cause the text between cursor and
757the end of the replacement region to be deleted. But what if, as is
758possible in Viper, the cursor is not inside the replacement region?
759
760To solve the problem, Viper keeps track of the last cursor position while it
761was still inside the replacement region. So, in the above situation, Viper
762would delete text between this position and the end of the replacement
763region.
764
765@node The Minibuffer,Multiple Files in Viper, States in Viper, Overview
766@section The Minibuffer
767
768@cindex Minibuffer
769
770The Minibuffer is where commands are entered in. Editing can be done
771by commands from Insert state, namely:
772
773@table @kbd
774@item C-h
775Backspace
776@item C-w
777Delete Word
778@item C-u
779Erase line
780@item C-v
781Quote the following character
782@item @key{RET}
783Execute command
784@item C-g and C-]
785Emacs quit and abort keys. These may be necessary. @xref{Vi State}, for an
786explanation.
787@item M-p and M-n
788These keys are bound to functions that peruse minibuffer history. The
789precise history to be perused depends on the context. It may be the history
790of search strings, Ex commands, file names, etc.
791@end table
792
793Most of the Emacs keys are functional in the Minibuffer. While in the
794Minibuffer, Viper tries to make editing resemble Vi's behavior when the
795latter is waiting for the user to type an Ex command. In particular, you
796can use the regular Vi commands to edit the Minibuffer. You can switch
797between the Vi state and Insert state at will, and even use the replace mode.
798Initially, the Minibuffer comes up in Insert state.
799
800Some users prefer plain Emacs bindings in the Minibuffer. To this end, set
801@code{viper-vi-style-in-minibuffer} to @code{nil} in @file{.viper}.
802@xref{Customization}, to learn how to do this.
803
804When the Minibuffer changes Viper states, you will notice that the appearance
805of the text there changes as well. This is useful because the Minibuffer
806has no mode line to tell which Vi state it is in.
807The appearance of the text in the Minibuffer can be changed.
808@xref{Viper Specials}, for more details.
809
810@node Multiple Files in Viper,Unimplemented Features,The Minibuffer,Overview
811@section Multiple Files in Viper
812
813@cindex multiple files
814@cindex managing multiple files
815
816Viper can edit multiple files. This means, for example that you never need
817to suffer through @code{No write since last change} errors.
818Some Viper elements are common over all the files.
819
820@table @samp
821@item Textmarkers
822@cindex markers
823@cindex textmarkers
824Textmarkers remember @emph{files and positions}.
825If you set marker @samp{a} in
826file @file{foo}, start editing file @file{bar} and type @kbd{'a}, then
827@emph{YOU WILL SWITCH TO FILE @file{foo}}. You can see the contents of a
828textmarker using the Viper command @kbd{[<a-z>} where <a-z> are the
829textmarkers, e.g., @kbd{[a} to view marker @samp{a} .@refill
830@item Repeated Commands
831Command repetitions are common over files. Typing @kbd{!!} will repeat the
832last @kbd{!} command whichever file it was issued from.
833Typing @kbd{.} will repeat the last command from any file, and
834searches will repeat the last search. Ex commands can be repeated by typing
835@kbd{: @key{RET}}.@refill
836Note: in some rare cases, that @kbd{: @key{RET}} may do something dangerous.
837However, usually its effect can be undone by typing @kbd{u}.
838@item Registers
839@cindex registers
840Registers are common to files. Also, text yanked with @kbd{y} can be
841put back (@kbd{p}) into any file. The Viper command @kbd{]<a-z>}, where <a-z> are
842the registers, can be used to look at the contents of a register, e.g.,
843type @kbd{]a} to view register @samp{a}.
844
845There is one difference in text deletion that you should be
846aware of. This difference comes from Emacs and was adopted in Viper
847because we find it very useful. In Vi, if you delete a line, say, and then
848another line, these two deletions are separated and are put back
849separately if you use the @samp{p} command. In Emacs (and Viper), successive
850series of deletions that are @emph{not interrupted} by other commands are
851lumped together, so the deleted text gets accumulated and can be put back
852as one chunk. If you want to break a sequence of deletions so that the
853newly deleted text could be put back separately from the previously deleted
854text, you should perform a non-deleting action, e.g., move the cursor one
855character in any direction.
856@item Absolute Filenames
857@cindex absolute file names
858The current directory name for a file is automatically prepended to the
859file name in any
860@kbd{:e}, @kbd{:r}, @kbd{:w}, etc., command (in Emacs, each buffer has a
861current directory).
862This directory is inserted in the Minibuffer once you type space after
863@kbd{:e, r}, etc. Viper also supports completion of file names and Ex
864commands (@key{TAB}), and it keeps track of
865command and file history (@kbd{M-p}, @kbd{M-n}).
866Absolute filenames are required less
867often in Viper.
868
869You should be aware that Emacs interprets @kbd{/foo/bar//bla} as
870@kbd{/bla} and @kbd{/foo/~/bar} as @kbd{~/bar}. This is designed to
871minimize the need for erasing file names that Emacs suggests in its
872prompts, if a suggested file name is not what you wanted.
873
874The command @kbd{:cd} will change the default directory for the
875current Emacs buffer. The Ex command @kbd{:e} will interpret the
876filename argument in @samp{csh}, by default. @xref{Customization}, if you
877want to change this.
878@end table
879
880@noindent
881Currently undisplayed files can be listed using the @kbd{:ar} command. The
882command @kbd{:n} can be given counts from the @kbd{:ar} list to switch to
883other files. For example, use `:n3' to move to the third file in that list.
884
885@node Unimplemented Features,,Multiple Files in Viper,Overview
886@section Unimplemented Features
887
888Unimplemented features include:
889
890@itemize @bullet
891@item
892@kbd{:ab} and @kbd{:una} are not implemented, since
893@kbd{:ab} is considered obsolete, since Emacs has much
894more powerful facilities for defining abbreviations.
895@item
896@kbd{:set option?} is not implemented. The current
897@kbd{:set} can also be used to set Emacs variables.
898@item
899@kbd{:se list} requires modification of the display code for Emacs, so
900it is not implemented.
901A useful alternative is @code{cat -t -e file}. Unfortunately, it cannot
902be used directly inside Emacs, since Emacs will obdurately change @samp{^I}
903back to normal tabs.@refill
904@end itemize
905
906@comment node-name, next, previous, up
907@node Improvements over Vi, Customization, Overview, Top
908@chapter Improvements over Vi
909
910Some common problems with Vi and Ex have been solved in Viper. This
911includes better implementation of existing commands, new commands, and
912the facilities provided by Emacs.
913
914@menu
915* Basics:: Basic Viper differences, Multi-file effects.
916* Undo and Backups:: Multiple undo, auto-save, backups and changes
917* History:: History for Ex and Vi commands.
918* Macros and Registers:: Keyboard Macros (extended ".")@: @@reg execution.
919* Completion:: Filename and Command Completion for Ex.
920* Improved Search:: Incremental Search and Buffer Content Search.
921* Abbreviation Facilities:: Normal Abbrevs, Templates, and Dynamic Abbrevs.
922* Movement and Markers:: Screen Editor movements, viewing textmarkers.
923* New Commands:: Commands that do not exist in Vi.
924* Useful Packages:: A Sampling of some Emacs packages, and things
925 you should know about.
926@end menu
927
928@node Basics, Undo and Backups, Improvements over Vi, Improvements over Vi
929@section Basics
930
931The Vi command set is based on the idea of combining motion commands
932with other commands. The motion command is used as a text region
933specifier for other commands.
934We classify motion commands into @dfn{point commands} and
935@dfn{line commands}.@refill
936
937@cindex point commands
938
939The point commands are:
940
941@quotation
942@kbd{h}, @kbd{l}, @kbd{0}, @kbd{$}, @kbd{w}, @kbd{W}, @kbd{b}, @kbd{B},
943@kbd{e}, @kbd{E}, @kbd{(}, @kbd{)}, @kbd{/}, @kbd{?}, @kbd{`}, @kbd{f},
944@kbd{F}, @kbd{t}, @kbd{T}, @kbd{%}, @kbd{;}, @kbd{,}, @kbd{^}
945@end quotation
946
947@cindex line commands
948
949The line commands are:
950
951@quotation
952@kbd{j}, @kbd{k}, @kbd{+}, @kbd{-}, @kbd{H}, @kbd{M}, @kbd{L}, @kbd{@{},
953@kbd{@}}, @kbd{G}, @kbd{'}, @kbd{[[}, @kbd{]]}, @kbd{[]}
954@end quotation
955
956@cindex region
957@cindex region specification
958@cindex expanding (region)
959@cindex describing regions
960@cindex movement commands
961
962@noindent
963If a point command is given as an argument to a modifying command, the
964region determined by the point command will be affected by the modifying
965command. On the other hand, if a line command is given as an argument to a
966modifying command, the region determined by the line command will be
967enlarged so that it will become the smallest region properly containing the
968region and consisting of whole lines (we call this process @dfn{expanding
969the region}), and then the enlarged region will be affected by the modifying
970command.
971Text Deletion Commands (@pxref{Deleting Text}), Change commands
972(@pxref{Changing Text}), even Shell Commands (@pxref{Shell Commands})
973use these commands to describe a region of text to operate on.
974Thus, type @kbd{dw} to delete a word, @kbd{>@}} to shift a paragraph, or
975@kbd{!'afmt} to format a region from @samp{point} to textmarker
976@samp{a}.
977
978@cindex r and R region specifiers
979
980Viper adds the region specifiers @samp{r} and @samp{R}. Emacs has a
981special marker called @dfn{mark}. The text-area between the current cursor
982position @dfn{point} and the @dfn{mark} is called the @dfn{region}.
983@samp{r} specifies the raw region and @samp{R} is the expanded region
984(i.e., the minimal contiguous chunk of full lines that contains the raw
985region).
986@kbd{dr} will now delete the region, @kbd{>r} will shift it, etc.
987@kbd{r,R} are not motion commands, however. The special mark is set by
988@kbd{m.} and other commands. @xref{Marking}, for more info.
989
990Viper also adds counts to most commands for which it would make sense.
991
992In the Overview chapter, some Multiple File issues were discussed
993(@pxref{Multiple Files in Viper}). In addition to the files, Emacs has
994buffers. These can be seen in the @kbd{:args} list and switched using
995@kbd{:next} if you type @kbd{:set ex-cycle-through-non-files t}, or
996specify @code{(setq ex-cycle-through-non-files t)} in your @file{.viper}
997file. @xref{Customization}, for details.
998
999@node Undo and Backups, History, Basics, Improvements over Vi
1000@section Undo and Backups
1001
1002@cindex undo
1003
1004Viper provides multiple undo. The number of undo's and the size is limited
1005by the machine. The Viper command @kbd{u} does an undo. Undo can be
1006repeated by typing @kbd{.} (a period). Another @kbd{u} will undo the undo,
1007and further
1008@kbd{.} will repeat it. Typing @kbd{u} does the first undo, and changes the
1009direction.
1010
1011@cindex backup files
1012@cindex auto save
1013
1014Since the undo size is limited, Viper can create backup files and
1015auto-save files. It will normally do this automatically. It is possible
1016to have numbered backups, etc. For details, @pxref{Backup,,Backup and
1017Auto-Save,emacs,The GNU Emacs Manual} @refill
1018
1019@comment [ balance parens
1020@cindex viewing registers and markers
1021@cindex registers
1022@cindex markers
1023@cindex textmarkers
1024
1025The results of the 9 previous changes are available in the 9 numeric
1026registers, as in Vi. The extra goody is the ability to @emph{view} these
1027registers, in addition to being able to access them through @kbd{p} and
1028@kbd{M-y} (@xref{Insert State}, for details.)
1029The Viper command @kbd{] register} will display the contents of any
1030register, numeric or alphabetical. The related command @kbd{[ textmarker}
1031will show the text around the textmarker. @samp{register} and @samp{textmarker}
1032can be any letters from a through z.
1033@comment ] balance parens
1034
1035@node History, Macros and Registers, Undo and Backups,Improvements over Vi
1036@section History
1037
1038@cindex history
1039@cindex Minibuffer
1040
1041History is provided for Ex commands, Vi searches, file names, pieces of
1042text inserted in earlier commands that use Insert or Replace state, and for
1043destructive commands in Vi state. These are
1044useful for fixing those small typos that screw up searches and @kbd{:s},
1045and for eliminating routine associated with repeated typing of file names
1046or pieces of text that need to be inserted frequently.
1047At the @kbd{:} or @kbd{/} prompts in the Minibuffer, you can do the following:
1048
1049@table @kbd
1050@item M-p and M-n
1051To move to previous and next history items. This causes the history
1052items to appear on the command line, where you can edit them, or
1053simply type Return to execute.
1054@item M-r and M-s
1055To search backward and forward through the history.
1056@item @key{RET}
1057Type @key{RET} to accept a default (which is displayed in the prompt).
1058@end table
1059
1060The history of insertions can be perused by
1061typing @kbd{C-c M-p} and @kbd{C-c M-n} while in Insert or Replace state.
1062The history of destructive Vi commands can be perused via the same keys
1063when Viper is in Vi state. @xref{Viper Specials}, for details.
1064
1065All Ex commands have a file history. For instance, typing @kbd{:e}, space
1066and then @kbd{M-p} will bring up the name of the previously typed file
1067name. Repeatedly typing @kbd{M-p}, @kbd{M-n}, etc., will let you browse
1068through the file history.
1069
1070Similarly, commands that have to do with switching buffers
1071have a buffer history, and commands that expect strings or regular
1072expressions keep a history on those items.
1073
1074@node Macros and Registers,Completion,History,Improvements over Vi
1075@section Macros and Registers
1076
1077@cindex keyboard macros
1078@cindex macros
1079@cindex registers
1080@cindex register execution
1081
1082Viper facilitates the use of Emacs-style keyboard macros. @kbd{@@#} will
1083start a macro definition. As you type, the commands will be executed, and
1084remembered (This is called ``learn mode'' in some editors.)
1085@kbd{@@register} will complete the macro, putting it into @samp{register},
1086where @samp{register} is any character from @samp{a} through @samp{z}. Then
1087you can execute this macro using @kbd{@@register}. It is, of course,
1088possible to yank some text into a register and execute it using
1089@kbd{@@register}. Typing @kbd{@@@@}, @kbd{@@RET}, or @kbd{@@C-j} will
1090execute the last macro that was executed using @kbd{@@register}.@refill
1091
1092Viper will automatically lowercase the register, so that pressing the
1093@kbd{SHIFT} key for @kbd{@@} will not create problems. This is for
1094@kbd{@@} macros and @kbd{"p} @emph{only}. In the case of @kbd{y},
1095@kbd{"Ayy} will append to @emph{register a}. For @kbd{[,],',`}, it
1096is an error to use a Uppercase register name.
1097
1098@comment [ balance parens
1099@cindex viewing registers and markers
1100
1101The contents of a register can be seen by @kbd{]register}. (@kbd{[textmarker}
1102will show the contents of a textmarker).
1103@comment ] balance parens
1104
1105@cindex last keyboard macro
1106
1107The last keyboard macro can also be executed using
1108@kbd{*}, and it can be yanked into a register using @kbd{@@!register}.
1109This is useful for Emacs style keyboard macros defined using @kbd{C-x(}
1110and @kbd{C-x)}. Emacs keyboard macros have more capabilities.
1111@xref{Keyboard Macros,,Keyboard Macros,emacs, The GNU Emacs Manual}, for
1112details.@refill
1113
1114Keyboard Macros allow an interesting form of Query-Replace:
1115@kbd{/pattern} or @kbd{n} to go to the next pattern (the query), followed by a
1116Keyboard Macro execution @kbd{@@@@} (the replace).
1117
1118Viper also provides Vi-style macros. @xref{Vi Macros}, for details.
1119
1120
1121@node Completion, Improved Search, Macros and Registers, Improvements over Vi
1122@section Completion
1123
1124@cindex completion
1125
1126Completion is done when you type @key{TAB}. The Emacs completer does not
1127grok wildcards in file names. Once you type a wildcard, the completer will
1128no longer work for that file name. Remember that Emacs interprets a file name
1129of the form @kbd{/foo//bar} as @kbd{/bar} and @kbd{/foo/~/bar} as
1130@kbd{~/bar}.
1131
1132@node Improved Search, Abbreviation Facilities, Completion, Improvements over Vi
1133@section Improved Search
1134
1135@cindex buffer search
1136@cindex word search
1137
1138Viper provides buffer search, the ability to search the buffer for a region
1139under the cursor. You have to turn this on in @file{.viper} either by calling
1140
1141@example
1142(viper-buffer-search-enable)
1143@end example
1144
1145@noindent
1146or by setting @code{viper-buffer-search-char} to, say, @kbd{f3}:
1147@example
1148(setq viper-buffer-search-char ?g)
1149@end example
1150
1151@noindent
1152If the user calls @code{viper-buffer-search-enable} explicitly (the first
1153method), then @code{viper-buffer-search-char} will be set to @kbd{g}.
1154Regardless of how this feature is enabled, the key
1155@code{viper-buffer-search-char} will take movement commands, like
1156@kbd{w,/,e}, to find a region and then search for the contents of that
1157region. This command is very useful for searching for variable names, etc.,
1158in a program. The search can be repeated by @kbd{n} or reversed by @kbd{N}.
1159
1160@cindex incremental search
1161
1162Emacs provides incremental search. As you type the string in, the
1163cursor will move to the next match. You can snarf words from the buffer
1164as you go along. Incremental Search is normally bound to @kbd{C-s} and
1165@kbd{C-r}. @xref{Customization}, to find out how to change the bindings
1166of @kbd{C-r or C-s}.
1167For details, @pxref{Incremental Search,,Incremental
1168Search,emacs,The GNU Emacs Manual} @refill
1169
1170@cindex query replace
1171
1172Viper also provides a query replace function that prompts through the
1173Minibuffer. It is invoked by the @kbd{Q} key in Vi state.
1174
1175@cindex mouse search
1176
1177On a window display, Viper supports mouse search, i.e., you can search for a
1178word by clicking on it. @xref{Viper Specials}, for details.
1179
1180Finally, on a window display, Viper highlights search patterns as it finds
1181them. This is done through what is known as @emph{faces} in Emacs. The
1182variable that controls how search patterns are highlighted is
1183@code{viper-search-face}. If you don't want any highlighting at all, put
1184@example
1185(copy-face 'default 'viper-search-face)
1186@end example
1187@vindex @code{viper-search-face}
1188@noindent
1189in @file{~/.viper}. If you want to change how patterns are highlighted, you
1190will have to change @code{viper-search-face} to your liking. The easiest
1191way to do this is to use Emacs customization widget, which is accessible
1192from the menubar. Viper customization group is located under the
1193@emph{Emulations} customization group, which in turn is under the
1194@emph{Editing} group (or simply by typing @kbd{:customize}). All Viper
1195faces are grouped together under Viper's
1196@emph{Highlighting} group.
1197
1198Try it: it is really simple!
1199
1200@node Abbreviation Facilities,Movement and Markers,Improved Search,Improvements over Vi
1201@section Abbreviation Facilities
1202
1203@cindex abbrevs
1204
1205It is possible in Emacs to define abbrevs based on the contents of the
1206buffer.
1207Sophisticated templates can be defined using the Emacs abbreviation
1208facilities. @xref{Abbrevs,,Abbreviations,emacs,The GNU Emacs Manual}, for
1209details.
1210
1211@cindex dynamic abbrevs
1212
1213Emacs also provides Dynamic Abbreviations. Given a partial word, Emacs
1214will search the buffer to find an extension for this word. For instance,
1215one can type @samp{Abbreviations} by typing @samp{A}, followed by a keystroke
1216that completed the @samp{A} to @samp{Abbreviations}. Repeated typing
1217will search further back in the buffer, so that one could get
1218@samp{Abbrevs} by repeating the
1219keystroke, which appears earlier in the text. Emacs binds this to
1220@kbd{@key{ESC} /}, so you will have to find a key and bind the function
1221@code{dabbrev-expand} to that key.
1222Facilities like this make Vi's @kbd{:ab} command obsolete.
1223
1224@node Movement and Markers, New Commands, Abbreviation Facilities, Improvements over Vi
1225@section Movement and Markers
1226
1227@cindex Ex style motion
1228@cindex line editor motion
1229
1230Viper can be set free from the line--limited movements in Vi, such as @kbd{l}
1231refusing to move beyond the line, @key{ESC} moving one character back,
1232etc. These derive from Ex, which is a line editor. If your @file{.viper}
1233contains
1234
1235@example
1236@code{(setq viper-ex-style-motion nil)}
1237@end example
1238
1239@noindent
1240the motion will be a true screen editor motion. One thing you must then
1241watch out for is that it is possible to be on the end-of-line character.
1242The keys @kbd{x} and @kbd{%} will still work correctly, i.e., as if they
1243were on the last character.
1244
1245@vindex @code{viper-syntax-preference}
1246@cindex syntax table
1247
1248The word-movement commands @kbd{w}, @kbd{e}, etc., and the associated
1249deletion/yanking commands, @kbd{dw}, @kbd{yw}, etc., can be made to
1250understand Emacs syntax tables. If the variable
1251@code{viper-syntax-preference} is set to @code{strict-vi} then
1252the meaning of @emph{word} is the same as in
1253Vi. However, if the value is @code{reformed-vi} (the default) then the
1254alphanumeric symbols will be those specified by the current Emacs syntax
1255table (which may be different for different major modes) plus the
1256underscore symbol @kbd{_}, minus some non-word symbols, like '.;,|, etc.
1257Both @code{strict-vi} and @code{reformed-vi} work close to Vi in
1258traditional cases, but @code{reformed-vi} does a better job when editing
1259text in non-Latin alphabets.
1260
1261The user can also specify the value @code{emacs}, which would
1262make Viper use exactly the Emacs notion of word. In particular, the
1263underscore may not be part of a word. Finally, if
1264@code{viper-syntax-preference} is set to @code{extended}, Viper words would
1265consist of characters that are classified as alphanumeric @emph{or} as
1266parts of symbols. This is convenient for writing programs and in many other
1267situations.
1268
1269@code{viper-syntax-preference} is a local variable, so it can have different
1270values for different major modes. For instance, in programming modes it can
1271have the value @code{extended}. In text modes where words contain special
1272characters, such as European (non-English) letters, Cyrillic letters, etc.,
1273the value can be @code{reformed-vi} or @code{emacs}.
1274
1275Changes to @code{viper-syntax-preference} should be done in the hooks to
1276various major modes by executing @code{viper-set-syntax-preference} as in
1277the following example:
1278
1279@example
1280(viper-set-syntax-preference nil "emacs")
1281@end example
1282
1283@findex @code{viper-set-syntax-preference}
1284
1285The above discussion of the meaning of Viper's words concerns only Viper's
1286movement commands. In regular expressions, words remain the same as in
1287Emacs. That is, the expressions @code{\w}, @code{\>}, @code{\<}, etc., use
1288Emacs' idea of what is a word, and they don't look into the value of
1289variable @code{viper-syntax-preference}. This is because Viper doesn't change
1290syntax tables in fear of upsetting the various major modes that set these
1291tables.
1292
1293@cindex textmarkers
1294
1295Textmarkers in Viper remember the file and the position, so that you can
1296switch files by simply doing @kbd{'a}. If you set up a regimen for using
1297Textmarkers, this is very useful. Contents of textmarkers can be viewed
1298by @kbd{[marker}. (Contents of registers can be viewed by @kbd{]register}).
1299
1300@node New Commands, Useful Packages, Movement and Markers, Improvements over Vi
1301@section New Commands
1302
1303These commands have no Vi analogs.
1304
1305@table @kbd
1306@item C-x, C-c
1307@kindex @kbd{C-x}
1308@kindex @kbd{C-c}
1309These two keys invoke many important Emacs functions. For example, if you
1310hit @kbd{C-x} followed by @kbd{2}, then the current window will be split
1311into 2. Except for novice users, @kbd{C-c} is also set to execute an Emacs
1312command from the current major mode. @key{ESC} will do the same, if you
1313configure @key{ESC} as Meta by setting @code{viper-no-multiple-ESC} to @code{nil}
1314in @file{.viper}. @xref{Customization}. @kbd{C-\} in Insert, Replace, or Vi
1315states will make Emacs think @kbd{Meta} has been hit.@refill
1316@item \
1317@kindex @kbd{\}
1318Escape to Emacs to execute a single Emacs command. For instance,
1319@kbd{\ @key{ESC}} will act like a Meta key.
1320@item Q
1321@kindex @kbd{Q}
1322@cindex query replace
1323@kbd{Q} is for query replace. By default,
1324each string to be replaced is treated as a regular expression. You can use
1325@code{(setq viper-re-query-replace nil)} in your @file{.emacs} file to
1326turn this off. (For normal searches, @kbd{:se nomagic} will work. Note
1327that @kbd{:se nomagic} turns Regexps off completely, unlike Vi).
1328@item v
1329@itemx V
1330@itemx C-v
1331@kindex @kbd{v}
1332@kindex @kbd{V}
1333@kindex @kbd{C-v}
1334These keys are used to visit files. @kbd{v} will switch to a buffer
1335visiting file whose name can be entered in the Minibuffer. @kbd{V} is
1336similar, but will use a window different from the current window.
1337@kbd{C-v} is like @kbd{V}, except that a new frame (X window) will be used
1338instead of a new Emacs window.
1339@item #
1340@kindex @kbd{#}
1341If followed by a certain character @var{ch}, it becomes an operator whose
1342argument is the region determined by the motion command that follows
1343(indicated as <move>).
1344Currently, @var{ch} can be one of @kbd{c}, @kbd{C}, @kbd{g}, @kbd{q}, and
1345@kbd{s}. For instance, @kbd{#qr} will prompt you for a string and then
1346prepend this string to each line in the buffer.@refill
1347@item # c
1348@kindex @kbd{#c<move>}
1349@cindex changing case
1350Change upper-case characters in the region to lower-case
1351(@code{downcase-region}).
1352Emacs command @kbd{M-l} does the same for words.
1353@item # C
1354@kindex @kbd{#C<move>}
1355Change lower-case characters in the region to upper-case. For instance,
1356@kbd{# C 3 w} will capitalize 3 words from the current point
1357(@code{upcase-region}).
1358Emacs command @kbd{M-u} does the same for words.
1359@item # g
1360@kindex @kbd{#g<move>}
1361Execute last keyboard macro for each line in the region
1362(@code{viper-global-execute}).@refill
1363@item # q
1364@kindex @kbd{#q<move>}
1365Insert specified string at the beginning of each line in the region
1366(@code{viper-quote-region}). The default string is composed of the comment
1367character(s) appropriate for the current major mode.
1368@item # s
1369@kindex @kbd{#s<move>}
1370Check spelling of words in the region (@code{spell-region}).
1371The function used for spelling is determined from the variable
1372@code{viper-spell-function}.
1373@vindex @code{viper-spell-function}
1374@item *
1375@kindex @kbd{*}
1376Call last keyboard macro.
1377@item m .
1378Set mark at point and push old mark off the ring
1379@item m<
1380@item m>
1381Set mark at beginning and end of buffer, respectively.
1382@item m,
1383Jump to mark and pop mark off the ring. @xref{Mark,,Mark,emacs,The GNU
1384Emacs Manual}, for more info.
1385@item ] register
1386@kindex @kbd{]<a-z>}
1387View contents of register
1388@item [ textmarker
1389@kindex @kbd{[<a-z>}
1390View filename and position of textmarker
1391@item @@#
1392@item @@register
1393@item @@!
1394@kindex @kbd{@@#}
1395@kindex @kbd{@@<a-z>}
1396@kindex @kbd{@@!}
1397@cindex keyboard macros
1398@cindex register execution
1399
1400Begin/end keyboard macro. @@register has a different meaning when used after
1401a @kbd{@@#}. @xref{Macros and Registers}, for details
1402@item []
1403@kindex @kbd{[]}
1404Go to end of heading.
1405@item g <@emph{movement command}>
1406Search buffer for text delimited by movement command. The canonical
1407example is @kbd{gw} to search for the word under the cursor.
1408@xref{Improved Search}, for details.@refill
1409@item C-g and C-]
1410@kindex @kbd{C-g}
1411@kindex @kbd{C-]}
1412Quit and Abort Recursive edit. These may be necessary on occasion.
1413@xref{Vi State}, for a reason.
1414@item C-c C-g
1415@kindex @kbd{C-c C-g}
1416Hitting @kbd{C-c} followed by @kbd{C-g} will display the information on the
1417current buffer. This is the same as hitting @kbd{C-g} in Vi, but, as
1418explained above, @kbd{C-g} is needed for other purposes in Emacs.
1419@item C-c /
1420@kindex @kbd{C-c /}
1421Without a prefix argument, this command toggles
1422case-sensitive/case-insensitive search modes and plain vanilla/regular
1423expression search. With the prefix argument 1, i.e.,
1424@kbd{1 C-c /}, this toggles case-sensitivity; with the prefix argument 2,
1425toggles plain vanilla search and search using
1426regular expressions. @xref{Viper Specials}, for alternative ways to invoke
1427this function.
1428@cindex vanilla search
1429@cindex case-sensitive search
1430@cindex case-insensitive search
1431
1432@item M-p and M-n
1433@kindex @kbd{M-p}
1434@kindex @kbd{M-n}
1435In the Minibuffer, these commands navigate through the minibuffer
1436histories, such as the history of search strings, Ex commands, etc.
1437
1438@item C-c M-p and C-c M-n
1439@kindex @kbd{C-c M-p}
1440@kindex @kbd{C-c M-n}
1441@cindex Insertion history
1442@cindex Insertion ring
1443@cindex Command history
1444@cindex Command ring
1445
1446In Insert or Replace state, these commands let the user
1447peruse the history of insertion strings used in previous insert or replace
1448commands. Try to hit @kbd{C-c M-p} or @kbd{C-c M-n} repeatedly and see what
1449happens. @xref{Viper Specials}, for more.
1450
1451In Vi state, these commands let the user peruse the history of Vi-style
1452destructive commands, such as @kbd{dw}, @kbd{J}, @kbd{a}, etc.
1453By repeatedly typing @kbd{C-c M-p} or @kbd{C-c M-n} you will cycle Viper
1454through the recent history of Vi commands, displaying the commands one by
1455one. Once
1456an appropriate command is found, it can be executed by typing `@kbd{.}'.
1457
1458Since typing @kbd{C-c M-p} is tedious, it is more convenient to bind an
1459appropriate function to a function key on the keyboard and use that key.
1460@xref{Viper Specials}, for details.
1461
1462@item Ex commands
1463@findex @kbd{:args}
1464@findex @kbd{:n}
1465@findex @kbd{:pwd}
1466@findex @kbd{:pre}
1467The commands @kbd{:args}, @kbd{:next}, @kbd{:pre} behave
1468differently. @kbd{:pwd} exists to get current directory.
1469The commands @kbd{:b} and @kbd{:B} switch buffers around. @xref{File and
1470Buffer Handling}, for details.
1471There are also the new commands @kbd{:RelatedFile} and
1472@kbd{PreviousRelatedFile} (which abbreviate to @kbd{R} and @kbd{P},
1473respectively. @xref{Viper Specials}, for details.
1474@findex @kbd{:RelatedFile}
1475@findex @kbd{:PreviousRelatedFile}
1476@end table
1477
1478Apart from the new commands, many old commands have been enhanced. Most
1479notably, Vi style macros are much more powerful in Viper than in Vi. @xref{Vi
1480Macros}, for details.
1481
1482@node Useful Packages, ,New Commands, Improvements over Vi
1483@section Useful Packages
1484
1485Some Emacs packages are mentioned here as an aid to the new Viper user, to
1486indicate what Viper is capable of.
1487A vast number comes with the standard Emacs distribution, and many more exist
1488on the net and on the archives.
1489
1490This manual also mentions some Emacs features a new user
1491should know about. The details of these are found in the GNU Emacs
1492Manual.
1493
1494The features first. For details, look up the Emacs Manual.
1495
1496@table @samp
1497@item Make
1498@cindex make
1499@cindex compiling
1500
1501Makes and Compiles can be done from the editor. Error messages will be
1502parsed and you can move to the error lines.
1503@item Shell
1504@cindex shell
1505@cindex interactive shell
1506You can talk to Shells from inside the editor. Your entire shell session
1507can be treated as a file.
1508@item Mail
1509@cindex email
1510@cindex mail
1511Mail can be read from and sent within the editor. Several sophisticated
1512packages exist.
1513@item Language Sensitive Editing
1514Editing modes are written for most computer languages in existence. By
1515controlling indentation, they catch punctuation errors.
1516@end table
1517
1518The packages, below, represents a drop in the sea of special-purpose
1519packages that come with standard distribution of Emacs.
1520
1521@table @samp
1522@item Transparent FTP
1523@cindex transparent ftp
1524@pindex ange-ftp.el
1525@code{ange-ftp.el} can ftp from the editor to files on other machines
1526transparent to the user.
1527@item RCS Interfaces
1528@cindex version maintenance
1529@cindex RCS
1530@pindex vc.el
1531@code{vc.el} for doing RCS commands from inside the editor
1532@item Directory Editor
1533@cindex dired
1534@pindex dired.el
1535@code{dired.el} for editing contents of directories and for navigating in
1536the file system.
1537@item Syntactic Highlighting
1538@cindex font-lock
1539@pindex font-lock.el
1540@code{font-lock.el} for automatic highlighting various parts of a buffer
1541using different fonts and colors.
1542@item Saving Emacs Configuration
1543@cindex desktop
1544@pindex desktop.el
1545@code{desktop.el} for saving/restoring configuration on Emacs exit/startup.
1546@item Spell Checker
1547@cindex ispell
1548@pindex ispell.el
1549@code{ispell.el} for spell checking the buffer, words, regions, etc.
1550@item File and Buffer Comparison
1551@cindex ediff
1552@pindex ediff.el
1553@code{ediff.el} for finding differences between files and for applying
1554patches.
1555@end table
1556
1557@noindent
1558Emacs Lisp archives exist on
1559@samp{archive.cis.ohio-state.edu}
1560and @samp{wuarchive.wustl.edu}@refill
1561
1562
1563@node Customization,Commands,Improvements over Vi,Top
1564@chapter Customization
1565
1566@cindex customization
1567
1568Customization can be done in 2 ways.
1569
1570@itemize @bullet
1571@item
1572@cindex initialization
1573@cindex .viper
1574Elisp code in a @file{.viper} file in your home directory. Viper
1575loads @file{.viper} just before it does the binding for mode
1576hooks. This is recommended for experts only.
1577@item
1578@cindex .emacs
1579Elisp code in your @file{.emacs} file before and after the @code{(require
1580'viper)} line. This method is @emph{not} recommended, unless you know what
1581you are doing. Only two variables, @code{viper-mode} and
1582@code{viper-custom-file-name}, are supposed to be customized in @file{.emacs},
1583prior to loading Viper (i.e., prior to @code{(require 'viper)} command.@refill
1584@item
1585@cindex :customize
1586By executing the @kbd{:customize} Ex command. This takes you to the Emacs
1587customization widget, which lets you change the values of Viper
1588customizable variables easily. This method is good for novice and
1589experts alike. The customization code in the form of Lisp commands will be
1590placed in @file{~/.emacs} or some other customization file depending on the
1591version of Emacs that you use. Still, it is recommended to separate
1592Viper-related customization produced by the Emacs customization widget
1593and keep it in the @file{.viper} file.
1594
1595Some advanced customization cannot be accomplished this way, however, and
1596has to be done in Emacs Lisp in the @file{.viper} file. For the common
1597cases, examples are provided that you can use directly.
1598@end itemize
1599
1600
1601@menu
1602* Rudimentary Changes:: Simple constant definitions.
1603* Key Bindings:: Enabling Emacs Keys, Rebinding keys, etc.
1604* Packages that Change Keymaps:: How to deal with such beasts.
1605* Viper Specials:: Special Viper commands.
1606* Vi Macros:: How to do Vi style macros.
1607@end menu
1608
1609@node Rudimentary Changes,Key Bindings,Customization,Customization
1610@section Rudimentary Changes
1611
1612@cindex setting variables
1613@cindex variables for customization
1614@findex @kbd{:set}
1615
1616An easy way to customize Viper is to change the values of constants used in
1617Viper. Here is the list of the constants used in Viper and their default
1618values. The corresponding :se command is also indicated. (The symbols
1619@code{t} and @code{nil} represent ``true'' and ``false'' in Lisp).
1620
1621Viper supports both the abbreviated Vi variable names and their full
1622names. Variable completion is done on full names only. @key{TAB} and
1623@key{SPC} complete
1624variable names. Typing `=' will complete the name and then will prompt for
1625a value, if applicable. For instance, @kbd{:se au @key{SPC}} will complete the
1626command to @kbd{:set autoindent}; @kbd{:se ta @key{SPC}} will complete the command
1627and prompt further like this: @kbd{:set tabstop = }.
1628However, typing @kbd{:se ts @key{SPC}} will produce a ``No match'' message
1629because @kbd{ts} is an abbreviation for @kbd{tabstop} and Viper supports
1630completion on full names only. However, you can still hit @key{RET}
1631or @kbd{=}, which will complete the command like this: @kbd{:set ts = } and
1632Viper will be waiting for you to type a value for the tabstop variable.
1633To get the full list of Vi variables, type @kbd{:se @key{SPC} @key{TAB}}.
1634
1635@table @code
1636@item viper-auto-indent nil
1637@itemx :se ai (:se autoindent)
1638@itemx :se ai-g (:se autoindent-global)
1639If @code{t}, enable auto indentation.
1640by @key{RET}, @kbd{o} or @kbd{O} command.
1641
1642@code{viper-auto-indent} is a local variable. To change the value globally, use
1643@code{setq-default}. It may be useful for certain major modes to have their
1644own values of @code{viper-auto-indent}. This can be achieved by using
1645@code{setq} to change the local value of this variable in the hooks to the
1646appropriate major modes.
1647
1648@kbd{:se ai} changes the value of @code{viper-auto-indent} in the current
1649buffer only; @kbd{:se ai-g} does the same globally.
1650@item viper-electric-mode t
1651If not @code{nil}, auto-indentation becomes electric, which means that
1652@key{RET}, @kbd{O}, and @kbd{o} indent cursor according to the current
1653major mode. In the future, this variable may control additional electric
1654features.
1655
1656This is a local variable: @code{setq} changes the value of this variable
1657in the current buffer only. Use @code{setq-default} to change the value in
1658all buffers.
1659@item viper-case-fold-search nil
1660@itemx :se ic (:se ignorecase)
1661If not @code{nil}, search ignores cases.
1662This can also be toggled by quickly hitting @kbd{/} twice.
1663@item viper-re-search nil
1664@itemx :se magic
1665If not @code{nil}, search will use regular expressions; if @code{nil} then
1666use vanilla search.
1667This behavior can also be toggled by quickly hitting @kbd{/} trice.
1668@item buffer-read-only
1669@itemx :se ro (:se readonly)
1670Set current buffer to read only. To change globally put
1671@code{(setq-default buffer-read-only t)} in your @file{.emacs} file.
1672@item blink-matching-paren t
1673@itemx :se sm (:se showmatch)
1674Show matching parens by blinking cursor.
1675@item tab-width t (default setting via @code{setq-default})
1676@itemx :se ts=value (:se tabstop=value)
1677@itemx :se ts-g=value (:se tabstop-global=value)
1678@code{tab-width} is a local variable that controls the width of the tab stops.
1679To change the value globally, use @code{setq-default}; for local settings,
1680use @code{setq}.
1681
1682The command @kbd{:se ts}
1683sets the tab width in the current
1684buffer only; it has no effect on other buffers.
1685
1686The command @kbd{:se ts-g} sets tab width globally,
1687for all buffers where the tab is not yet set locally,
1688including the new buffers.
1689
1690Note that typing @key{TAB} normally
1691doesn't insert the tab, since this key is usually bound to
1692a text-formatting function, @code{indent-for-tab-command} (which facilitates
1693programming and document writing). Instead, the tab is inserted via the
1694command @code{viper-insert-tab}, which is bound to @kbd{S-tab} (shift + tab).
1695
1696On some non-windowing terminals, Shift doesn't modify the @key{TAB} key, so
1697@kbd{S-tab} behaves as if it were @key{TAB}. In such a case, you will have
1698to bind @code{viper-insert-tab} to some other convenient key.
1699
1700@item viper-shift-width 8
1701@itemx :se sw=value (:se shiftwidth=value)
1702The number of columns shifted by @kbd{>} and @kbd{<} commands.
1703@item viper-search-wrap-around t
1704@itemx :se ws (:se wrapscan)
1705If not @code{nil}, search wraps around the end/beginning of buffer.
1706@item viper-search-scroll-threshold 2
1707If search lands within this many lines of the window top or bottom, the
1708window will be scrolled up or down by about 1/7-th of its size, to reveal
1709the context. If the value is negative---don't scroll.
1710@item viper-tags-file-name "TAGS"
1711The name of the file used as the tag table.
1712@item viper-re-query-replace nil
1713If not @code{nil}, use reg-exp replace in query replace.
1714@item viper-want-ctl-h-help nil
1715If not @code{nil}, @kbd{C-h} is bound to @code{help-command};
1716otherwise, @kbd{C-h} is bound as usual in Vi.
1717@item viper-vi-style-in-minibuffer t
1718If not @code{nil}, Viper provides a high degree of compatibility with Vi
1719insert mode when you type text in the Minibuffer; if @code{nil}, typing in
1720the Minibuffer feels like plain Emacs.
1721@item viper-no-multiple-ESC t
1722If you set this to @code{nil}, you can use @key{ESC} as Meta in Vi state.
1723Normally, this is not necessary, since graphical displays have separate
1724Meta keys (usually on each side of the space bar). On a dumb terminal, Viper
1725sets this variable to @code{twice}, which is almost like @code{nil}, except
1726that double @key{ESC} beeps. This, too, lets @key{ESC} to be used as a Meta.
4009494e
GM
1727@item viper-fast-keyseq-timeout 200
1728Key sequences separated by this many milliseconds are treated as Vi-style
1729keyboard macros. If the key sequence is defined as such a macro, it will be
1730executed. Otherwise, it is processed as an ordinary sequence of typed keys.
1731
1732Setting this variable too high may slow down your typing. Setting it too
1733low may make it hard to type macros quickly enough.
4009494e
GM
1734@item viper-ex-style-motion t
1735Set this to @code{nil}, if you want @kbd{l,h} to cross
1736lines, etc. @xref{Movement and Markers}, for more info.
1737@item viper-ex-style-editing t
1738Set this to @code{nil}, if you want
1739@kbd{C-h} and @key{DEL} to not stop
1740at the beginning of a line in Insert state, @key{X} and @key{x} to delete
1741characters across lines in Vi command state, etc.
1742@item viper-ESC-moves-cursor-back t
1743It @code{t}, cursor moves back 1 character when switching from insert state to vi
1744state. If @code{nil}, the cursor stays where it was before the switch.
1745@item viper-always t
1746@code{t} means: leave it to Viper to decide when a buffer must be brought
1747up in Vi state,
1748Insert state, or Emacs state. This heuristics works well in virtually all
1749cases. @code{nil} means you either has to invoke @code{viper-mode} manually
1750for each buffer (or you can add @code{viper-mode} to the appropriate major mode
1751hooks using @code{viper-load-hook}).
1752
1753This option must be set in the file @file{~/.viper}.
1754@item viper-custom-file-name "~/.viper"
1755File used for Viper-specific customization.
1756Change this setting, if you want. Must be set in @file{.emacs} (not @file{.viper}!)
1757before Viper is loaded. Note that you
1758have to set it as a string inside double quotes.
1759@item viper-spell-function 'ispell-region
1760Function used by the command @kbd{#c<move>} to spell.
1761@item viper-glob-function
1762The value of this variable is the function symbol used to expand wildcard
1763symbols. This is platform-dependent. The default tries to set this variable
1764to work with most shells, MS Windows, OS/2, etc. However, if it
1765doesn't work the way you expect, you should write your own.
1766Use @code{viper-glob-unix-files} and @code{viper-glob-mswindows-files} in
1767@file{viper-util.el} as examples.
1768
1769This feature is used to expand wildcards in the Ex command @kbd{:e}.
1770Note that Viper doesn't support wildcards in the @kbd{:r} and @kbd{:w}
1771commands, because file completion is a better mechanism.
1772@findex @code{viper-glob-function}
1773
1774@item ex-cycle-other-window t
1775If not @code{nil}, @kbd{:n} and @kbd{:b} will cycle through files in another
1776window, if one exists.
1777@item ex-cycle-through-non-files nil
1778@kbd{:n} does not normally cycle through buffers. Set this to get
1779buffers also.
1780@item viper-want-emacs-keys-in-insert
1781This is set to @code{nil} for user levels 1 and 2 and to @code{t} for user
1782levels 3 and 4. Users who specify level 5 are allowed to set this variable
1783as they please (the default for this level is @code{t}). If set to
1784@code{nil}, complete Vi compatibility is provided in Insert state. This is
1785really not recommended, as this precludes you from using language-specific
1786features provided by the major modes.
1787@item viper-want-emacs-keys-in-vi
1788This is set to @code{nil} for user
1789level 1 and to @code{t} for user levels 2--4.
1790At level 5, users are allowed to set this variable as they please (the
1791default for this level is @code{t}).
1792If set to @code{nil}, complete Vi compatibility is provided
1793in Vi command state. Setting this to @code{nil} is really a bad idea,
1794unless you are a novice, as this precludes the use
1795of language-specific features provided by the major modes.
1796@item viper-keep-point-on-repeat t
1797If not @code{nil}, point is not moved when the user repeats the previous
1798command by typing `.' This is very useful for doing repeated changes with
1799the @kbd{.} key.
1800@item viper-repeat-from-history-key 'f12
1801Prefix key used to invoke the macros @kbd{f12 1} and @kbd{f12 2} that repeat
1802the second-last and the third-last destructive command.
1803Both these macros are bound (as Viper macros) to
1804@code{viper-repeat-from-history},
1805which checks the second key by which it is invoked to see which of the
1806previous commands to invoke. Viper binds @kbd{f12 1} and @kbd{f12 2} only,
1807but the user can bind more in @file{~/.viper}. @xref{Vi Macros}, for how to do
1808this.
1809@item viper-keep-point-on-undo nil
1810If not @code{nil}, Viper tries to not move point when undoing commands.
1811Instead, it will briefly move the cursor to the place where change has
1812taken place. However, if the undone piece of text is not seen in window,
1813then point will be moved to the place where the change took place.
1814Set it to @code{t} and see if you like it better.
1815@item viper-delete-backwards-in-replace nil
1816If not @code{nil}, @key{DEL} key will delete characters while moving the cursor
1817backwards. If @code{nil}, the cursor will move backwards without deleting
1818anything.
1819@item viper-replace-overlay-face 'viper-replace-overlay-face
1820On a graphical display, Viper highlights replacement regions instead of
1821putting a @samp{$} at the end. This variable controls the so called
1822@dfn{face} used to highlight the region.
1823
1824By default, @code{viper-replace-overlay-face} underlines the replacement on
1825monochrome displays and also lays a stipple over them. On color displays,
1826replacement regions are highlighted with color.
1827
1828If you know something about Emacs faces and don't like how Viper highlights
1829replacement regions, you can change @code{viper-replace-overlay-face} by
1830specifying a new face. (Emacs faces are described in the Emacs Lisp
1831reference.) On a color display, the following customization method is
1832usually most effective:
1833@example
1834(set-face-foreground viper-replace-overlay-face "DarkSlateBlue")
1835(set-face-background viper-replace-overlay-face "yellow")
1836@end example
1837For a complete list of colors available to you, evaluate the expression
1838@code{(x-defined-colors)}. (Type it in the buffer @code{*scratch*} and then
1839hit the @kbd{C-j} key.
1840
1841@item viper-replace-overlay-cursor-color "Red"
1842@vindex @code{viper-replace-overlay-cursor-color}
1843Cursor color when it is inside the replacement region.
1844This has effect only on color displays and only when Emacs runs as an X
1845application.
1846@item viper-insert-state-cursor-color nil
1847@vindex @code{viper-insert-state-cursor-color}
1848If set to a valid color, this will be the cursor color when Viper is in
1849insert state.
1850@item viper-emacs-state-cursor-color nil
1851@vindex @code{viper-emacs-state-cursor-color}
1852If set to a valid color, this will be the cursor color when Viper is in
1853emacs state.
1854@item viper-replace-region-end-delimiter "$"
1855A string used to mark the end of replacement regions. It is used only on
1856TTYs or if @code{viper-use-replace-region-delimiters} is non-@code{nil}.
1857@item viper-replace-region-start-delimiter ""
1858A string used to mark the beginning of replacement regions. It is used
1859only on TTYs or if @code{viper-use-replace-region-delimiters} is non-@code{nil}.
1860@item viper-use-replace-region-delimiters
1861If non-@code{nil}, Viper will always use @code{viper-replace-region-end-delimiter} and
1862@code{viper-replace-region-start-delimiter} to delimit replacement regions,
1863even on color displays (where this is unnecessary). By default, this
1864variable is non-@code{nil} only on TTYs or monochrome displays.
1865@item viper-allow-multiline-replace-regions t
1866If non-@code{nil}, multi-line text replacement regions, such as those produced by
1867commands @kbd{c55w}, @kbd{3C}, etc., will stay around until the user exits
1868the replacement mode. In this variable is set to @code{nil}, Viper will
1869emulate the standard Vi behavior, which supports only intra-line
1870replacement regions (and multi-line replacement regions are deleted).
1871@item viper-toggle-key "\C-z"
1872Specifies the key used to switch from Emacs to Vi and back.
1873Must be set in @file{.viper}. This variable can't be
1874changed interactively after Viper is loaded.
1875
1876In Insert state, this key acts as a temporary escape to Vi state, i.e., it
1877will set Viper up so that the very next command will be executed as if it
1878were typed in Vi state.
4009494e
GM
1879@item viper-buffer-search-char nil
1880Key used for buffer search. @xref{Viper Specials}, for details.
1881@item viper-surrounding-word-function 'viper-surrounding-word
1882The value of this variable is a function name that is used to determine
1883what constitutes a word clicked upon by the mouse. This is used by mouse
1884search and insert.
1885@item viper-search-face 'viper-search-face
1886Variable that controls how search patterns are highlighted when they are
1887found.
1888@item viper-vi-state-hook nil
1889List of parameterless functions to be run just after entering the Vi
1890command state.
1891@item viper-insert-state-hook nil
1892Same for Insert state. This hook is also run after entering Replace state.
1893@item viper-replace-state-hook nil
1894List of (parameterless) functions called just after entering Replace state
1895(and after all @code{viper-insert-state-hook}).
1896@item viper-emacs-state-hook nil
1897List of (parameterless) functions called just after switching from Vi state
1898to Emacs state.
1899@item viper-load-hook nil
1900List of (parameterless) functions called just after loading Viper. This is
1901the last chance to do customization before Viper is up and running.
1902@end table
1903@noindent
1904You can reset some of these constants in Viper with the Ex command @kbd{:set}
1905(when so indicated in the table). Or you
1906can include a line like this in your @file{.viper} file:
1907@example
1908(setq viper-case-fold-search t)
1909@end example
1910@vindex @code{viper-auto-indent}
1911@vindex @code{viper-electric-mode}
1912@vindex @code{viper-case-fold-search}
1913@vindex @code{viper-re-search}
1914@vindex @code{viper-shift-width}
1915@vindex @code{buffer-read-only}
1916@vindex @code{viper-search-wrap-around}
1917@vindex @code{viper-search-scroll-threshold}
1918@vindex @code{viper-search-face}
1919@vindex @code{viper-tags-file-name}
1920@vindex @code{viper-re-query-replace}
1921@vindex @code{viper-want-ctl-h-help}
1922@vindex @code{viper-vi-style-in-minibuffer}
1923@vindex @code{viper-no-multiple-ESC}
1924@vindex @code{viper-always}
4009494e
GM
1925@vindex @code{viper-fast-keyseq-timeout}
1926@vindex @code{viper-ex-style-motion}
1927@vindex @code{viper-ex-style-editing}
1928@vindex @code{viper-ESC-moves-cursor-back}
1929@vindex @code{viper-custom-file-name}
1930@vindex @code{viper-spell-function}
1931@vindex @code{ex-cycle-other-window}
1932@vindex @code{ex-cycle-through-non-files}
1933@vindex @code{viper-want-emacs-keys-in-insert}
1934@vindex @code{viper-want-emacs-keys-in-vi}
1935@vindex @code{viper-keep-point-on-repeat}
1936@vindex @code{viper-keep-point-on-undo}
1937@vindex @code{viper-delete-backwards-in-replace}
1938@vindex @code{viper-replace-overlay-face}
1939@vindex @code{viper-replace-region-end-symbol}
1940@vindex @code{viper-replace-region-start-symbol}
1941@vindex @code{viper-allow-multiline-replace-regions}
1942@vindex @code{viper-toggle-key}
4009494e
GM
1943@vindex @code{viper-buffer-search-char}
1944@vindex @code{viper-surrounding-word-function}
1945@vindex @code{viper-vi-state-hook}
1946@vindex @code{viper-insert-state-hook}
1947@vindex @code{viper-replace-state-hook}
1948@vindex @code{viper-emacs-state-hook}
1949
1950@node Key Bindings, Packages that Change Keymaps, Rudimentary Changes,Customization
1951@section Key Bindings
1952
1953@cindex key bindings
1954@cindex keymaps
1955
1956Viper lets you define hot keys, i.e., you can associate keyboard keys
1957such as F1, Help, PgDn, etc., with Emacs Lisp functions (that may already
1958exist or that you will write). Each key has a "preferred form" in
1959Emacs. For instance, the Up key's preferred form is [up], the Help key's
1960preferred form is [help], and the Undo key has the preferred form [f14].
1961You can find out the preferred form of a key by typing @kbd{M-x
1962describe-key-briefly} and then typing the key you want to know about.
1963
1964Under the X Window System, every keyboard key emits its preferred form,
1965so you can just type
1966
1967@lisp
1968(global-set-key [f11] 'calendar) ; L1, Stop
1969(global-set-key [f14] 'undo) ; L4, Undo
1970@end lisp
1971
1972@noindent
1973to bind L1 (a key that exists on some SUN workstations) so it will invoke
1974the Emacs Calendar and to bind L4 so it will undo changes.
1975However, on a dumb terminal or in an Xterm window, even the standard arrow
1976keys may
1977not emit the right signals for Emacs to understand. To let Emacs know about
1978those keys, you will have to find out which key sequences they emit
1979by typing @kbd{C-q} and then the key (you should switch to Emacs state
1980first). Then you can bind those sequences to their preferred forms using
4f4a84ec 1981@code{input-decode-map} as follows:
4009494e
GM
1982
1983@lisp
1984(cond ((string= (getenv "TERM") "xterm")
4f4a84ec
SM
1985(define-key input-decode-map "\e[192z" [f11]) ; L1
1986(define-key input-decode-map "\e[195z" [f14]) ; L4, Undo
4009494e
GM
1987@end lisp
1988
1989The above illustrates how to do this for Xterm. On VT100, you would have to
1990replace "xterm" with "vt100" and also change the key sequences (the same
1991key may emit different sequences on different types of terminals).
1992
1993The above keys are global, so they are overwritten by the local maps
1994defined by the major modes and by Viper itself. Therefore, if you wish to
1995change a binding set by a major mode or by Viper, read this.
1996
1997Viper users who wish to specify their own key bindings should be concerned
1998only with the following three keymaps:
1999@code{viper-vi-global-user-map} for Vi state commands,
2000@code{viper-insert-global-user-map} for Insert state commands,
2001and @code{viper-emacs-global-user-map} for Emacs state commands (note:
2002customized bindings for Emacs state made to @code{viper-emacs-global-user-map}
2003are @emph{not} inherited by Insert state).
2004
2005For more information on Viper keymaps, see the header of the file
2006@file{viper.el}.
2007If you wish to change a Viper binding, you can use the
2008@code{define-key} command, to modify @code{viper-vi-global-user-map},
2009@code{viper-insert-global-user-map}, and @code{viper-emacs-global-user-map}, as
2010explained below. Each of these key maps affects the corresponding Viper state.
2011The keymap @code{viper-insert-global-user-map} also affects Viper's Replace
2012state.
2013
2014@noindent
2015If you want to
2016bind a key, say @kbd{C-v}, to the function that scrolls
2017page down and to make @kbd{0} display information on the current buffer,
2018putting this in @file{.viper} will do the trick in Vi state:
2019@example
2020(define-key viper-vi-global-user-map "\C-v" 'scroll-down)
2021@end example
2022@noindent
2023To set a key globally,
2024@example
2025(define-key viper-emacs-global-user-map "\C-c m" 'smail)
2026(define-key viper-vi-global-user-map "0" 'viper-info-on-file)
2027@end example
2028@noindent
2029Note, however, that this binding may be overwritten by other keymaps, since
2030the global keymap has the lowest priority.
2031To make sure that nothing will override a binding in Emacs state, you
2032can write this:
2033@example
2034(define-key viper-emacs-global-user-map "\C-c m" 'smail)
2035@end example
2036@noindent
2037To customize the binding for @kbd{C-h} in Insert state:
2038@example
2039(define-key viper-insert-global-user-map "\C-h" 'my-del-backwards-function)
2040@end example
2041@noindent
2042
2043Each Emacs command key calls some Lisp function. If you have enabled the
2044Help, (@pxref{Rudimentary Changes}) @kbd{C-h k} will show you the function
2045for each specific key; @kbd{C-h b} will show all bindings, and @kbd{C-h m}
2046will provide information on the major mode in effect. If Help is not
2047enabled, you can still get help in Vi state by prefixing the above commands
2048with @kbd{\}, e.g., @kbd{\ C-h k} (or you can use the Help menu in the
2049menu bar, if Emacs runs under X).
2050
2051Viper users can also change bindings on a per major mode basis. As with
2052global bindings, this can be done separately for each of the three main Viper
2053states. To this end, Viper provides the function
2054@code{viper-modify-major-mode}.
2055@findex @code{viper-modify-major-mode}
2056
2057To modify keys in Emacs state for @code{my-favorite-major-mode}, the user
2058needs to create a sparse keymap, say, @code{my-fancy-map}, bind whatever
2059keys necessary in that keymap, and put
2060
2061@example
2062(viper-modify-major-mode 'dired-mode 'emacs-state my-fancy-map)
2063@end example
2064
2065@noindent
2066in @file{~/.viper}. To do the same in Vi and Insert states, you should use
2067@code{vi-state} and @code{insert-state}. Changes in Insert state are also
2068in effect in Replace state. For instance, suppose that the user wants to
2069use @kbd{dd} in Vi state under Dired mode to delete files, @kbd{u} to unmark
2070files, etc. The following code in @file{~/.viper} will then do the job:
2071
2072@example
2073(setq my-dired-modifier-map (make-sparse-keymap))
2074(define-key my-dired-modifier-map "dd" 'dired-flag-file-deletion)
2075(define-key my-dired-modifier-map "u" 'dired-unmark)
2076(viper-modify-major-mode 'dired-mode 'vi-state my-dired-modifier-map)
2077@end example
2078
2079A Vi purist may want to modify Emacs state under Dired mode so that
2080@kbd{k}, @kbd{l}, etc., will move around in directory buffers, as in
2081Vi. Although this is not recommended, as these keys are bound to useful
2082Dired functions, the trick can be accomplished via the following code:
2083
2084@example
2085(setq my-dired-vi-purist-map (make-sparse-keymap))
2086(define-key my-dired-vi-purist-map "k" 'viper-previous-line)
2087(define-key my-dired-vi-purist-map "l" 'viper-forward-char)
2088(viper-modify-major-mode 'dired-mode 'emacs-state my-dired-vi-purist-map)
2089@end example
2090
2091Yet another way to customize key bindings in a major mode is to edit the
2092list @code{viper-major-mode-modifier-list} using the customization widget.
2093@vindex @code{viper-major-mode-modifier-list}
2094(This variable is in the Viper-misc customization group.)
2095The elements of this list are triples of the form: (major-mode viper-state
2096keymap), where the keymap contains bindings that are supposed to be active
2097in the given major mode and the given viper-state.
2098
2099Effects similar to key binding changes can be achieved by defining Vi
2100keyboard macros using the Ex commands @kbd{:map} and @kbd{:map!}. The
2101difference is that multi-key Vi macros do not override the keys they are
2102bound to, unless these keys are typed in quick succession. So, with macros,
2103one can use the normal keys alongside with the macros. If per-mode
2104modifications are needed, the user can try both ways and see which one is
2105more convenient.
2106@findex @kbd{:map}
2107@xref{Vi Macros}, for details.
2108
2109Note: in major modes that come up in @emph{Emacs state} by default, the
2110aforesaid modifications may not take place immediately (but only after the
2111buffer switches to some other Viper state and then back to Emacs state). To
2112avoid this, one should add @code{viper-change-state-to-emacs} to an
2113appropriate hook of that major mode. (Check the function
2114@code{viper-set-hooks} in @file{viper.el} for examples.) However, if you
2115did not set @code{viper-always} to @code{nil}, chances are that you won't
2116need to perform the above procedure, because Viper will take care of most
2117useful defaults.
2118
2119
2120Finally, Viper has a facility that lets the user define per-buffer
2121bindings, i.e., bindings that are in effect in some specific buffers
2122only. Unlike per-mode bindings described above, per-buffer bindings can be
2123defined based on considerations other than the major mode. This is done
2124via the function @code{viper-add-local-keys}, which lets one specify bindings
2125that should be in effect in the current buffer only and for a specific Viper
2126state. For instance,
2127@lisp
2128(viper-add-local-keys 'vi-state '(("ZZ" .@: TeX-command-master)
2129 ("ZQ" .@: viper-save-kill-buffer)))
2130@end lisp
2131@noindent
2132redefines @kbd{ZZ} to invoke @code{TeX-command-master} in @code{vi-state}
2133and @kbd{ZQ} to save-then-kill the current buffer. These bindings take
2134effect only in the buffer where this command is executed. The typical use
2135of this function is to execute the above expression from within a function
2136that is included in a hook to some major mode. For instance, the above
2137expression
2138could be called from a function, @code{my-tex-init}, which may be added to
2139@code{tex-mode-hook} as follows:
2140@lisp
2141(add-hook 'tex-mode-hook 'my-tex-init)
2142@end lisp
2143@noindent
2144When TeX mode starts, the hook is executed and the above Lisp expression is
2145evaluated. Then, the bindings for @kbd{ZZ} and @kbd{ZQ} are changed in Vi
2146command mode for all buffers in TeX mode.
2147
2148Another useful application is to bind @kbd{ZZ} to @code{send-mail}
2149in the Mail mode buffers (the specifics of this depend on which mail
2150package you are using, @code{rmail}, @code{mh-e}, @code{vm}, etc.
2151For instance, here is how to do this for @code{mh-e}, the Emacs interface
2152to MH:
2153@lisp
2154(defun mh-add-vi-keys ()
2155 "Set up ZZ for MH-e and XMH."
2156 (viper-add-local-keys 'vi-state '(("ZZ" .@: mh-send-letter))))
2157(add-hook 'mh-letter-mode-hook 'mh-add-vi-keys)
2158@end lisp
2159
2160You can also use @code{viper-add-local-keys} to set per buffer
2161bindings in Insert state and Emacs state by passing as a parameter the
2162symbols @code{insert-state} and @code{emacs-state}, respectively.
2163As with global bindings, customized local bindings done to Emacs state
2164are not inherited by Insert state.
2165
2166On rare occasions, local keys may be added by mistake. Usually this is done
2167indirectly, by invoking a major mode that adds local keys (e.g.,
2168@code{shell-mode} redefines @key{RET}). In such a case, exiting the wrong
2169major mode won't rid you from unwanted local keys, since these keys are
2170local to Viper state and the current buffer, not to the major mode.
2171In such situations, the remedy is to type @kbd{M-x viper-zap-local-keys}.
2172
2173So much about Viper-specific bindings.
2174@xref{Customization,,Customization,emacs,The GNU Emacs
2175Manual}, and the Emacs quick reference card for the general info on key
2176bindings in Emacs.
2177
4f4a84ec 2178@vindex @code{input-decode-map}
4009494e
GM
2179@vindex @code{function-key-map}
2180@vindex @code{viper-vi-global-user-map}
2181@vindex @code{viper-insert-global-user-map}
2182@vindex @code{viper-emacs-global-user-map}
2183@findex @code{viper-add-local-keys}
2184@findex @code{viper-zap-local-keys}
2185
2186@node Packages that Change Keymaps,Viper Specials,Key Bindings,Customization
2187@subsection Packages that Change Keymaps
2188@cindex C-c and Viper
2189@cindex Viper and C-c
2190
2191Viper is designed to coexist with all major and minor modes of Emacs. This
2192means that bindings set by those modes are generally available with Viper
2193(unless you explicitly prohibit them by setting
2194@code{viper-want-emacs-keys-in-vi} and @code{viper-want-emacs-keys-in-insert} to
2195@code{nil}).
2196If @code{viper-always} is set to @code{t} (which is the default), Viper
2197will try to bring each buffer
2198in the Viper state that is most appropriate for that buffer.
2199Usually, this would be the Vi state, but sometimes it could be the Insert
2200state or the Emacs state.
2201
2202Some major mode bindings will necessarily be overwritten by Viper. Indeed, in
2203Vi state, most of the 1-character keys are used for Vi-style editing. This
2204usually causes no problems because most packages designed for editing files
2205typically do not bind such keys. Instead, they use key sequences that start
2206with @kbd{C-x} and @kbd{C-c}. This is why it was so important for us to
2207free up @kbd{C-x} and @kbd{C-c}.
2208It is common for language-specific major modes to bind @key{TAB} and
2209@kbd{C-j} (the line feed) keys to various formatting functions. This is
2210extremely useful, but may require some getting used to for a Vi user. If you
2211decide that this feature is not for you, you can re-bind these keys as
2212explained earlier (@pxref{Customization}).
2213
2214Binding for @key{TAB} is one of the most unusual aspects of Viper for many
2215novice users. In Emacs, @key{TAB} is used to format text and programs, and
2216is extremely useful. For instance, hitting @key{TAB} causes the current
2217line to be re-indented in accordance with the context. In programming,
2218this is very important, since improper automatic indentation would
2219immediately alert the programmer to a possible error. For instance, if a
2220@kbd{)} or a @kbd{"} is missing somewhere above the current
2221line, @key{TAB} is likely to mis-indent the line.
2222
2223For this reason, Viper doesn't change the standard Emacs binding of
2224@key{TAB}, thereby sacrificing Vi compatibility
2225(except for users at level 1). Instead, in Viper, the key
2226@kbd{S-tab} (shift+ tab) is chosen to emulate Vi's @key{TAB}.
2227
2228We should note that on some non-windowing terminals, Shift doesn't modify
2229the @key{TAB} key, so @kbd{S-tab} behaves as if it were @key{TAB}. In such
2230a case, you will have to bind @code{viper-insert-tab} to some other
2231convenient key.
2232
2233Some packages, notably Dired, Gnus, Info, etc., attach special meaning to
2234common keys like @key{SPC}, @kbd{x}, @kbd{d}, @kbd{v}, and others. This
2235means that Vi command state is inappropriate for working with these
2236packages. Fortunately, these modes operate on read-only buffers and are
2237designed not for editing files, but for special-purpose browsing, reading
2238news, mail, etc., and Vi commands are meaningless in these situations. For
2239this reason, Viper doesn't force Vi state on such major modes---it
2240brings them in Emacs state. You can switch to Vi state by typing @kbd{C-z}
2241if, for instance, you want to do Vi-style search in a buffer (although,
2242usually, incremental search, which is bound to @kbd{C-s}, is sufficient in
2243these situations). But you should then switch back to Emacs state if you
2244plan to continue using these major modes productively. You can also switch
2245to Vi temporarily, to execute just one command. This is done by typing
2246@kbd{C-c \}. (In some of these modes, @kbd{/} and @kbd{:} are bound
2247Vi-style, unless these keys perform essential duties.)
2248
2249If you would like certain major modes to come up in Emacs state rather than
2250Vi state (but Viper thinks otherwise), you should put these major modes
2251on the @code{viper-emacs-state-mode-list} list and delete them from
2252@code{viper-vi-state-mode-list}.
2253Likewise, you can force Viper's Insert state on a major mode by putting it
2254in @code{viper-insert-state-mode-list}.
2255@vindex @code{viper-emacs-state-mode-list}
2256@vindex @code{viper-insert-state-mode-list}
2257@vindex @code{viper-vi-state-mode-list}
2258
2259It is also possible to impose Vi on some major modes, even though they may
2260bind common keys to specialized commands. This might make sense for modes
2261that bind only a small number of common keys. For instance, Viper subverts
2262the Shell mode by changing the bindings for @kbd{C-m} and @kbd{C-d} using
2263@code{viper-add-local-keys} described in the section on customization
2264(@pxref{Customization}).
2265
2266In some cases, some @emph{minor} modes might override certain essential
2267bindings in Vi command state. This is not a big problem because this
2268can happen only in the beginning, when the minor mode kicks in. Typing
2269@code{M-x viper-mode} will correct the situation. Viper knows about
2270several such minor modes and takes care of them, so the above trick
2271is usually not necessary. If you find that some minor mode, e.g.,
2272@code{nasty-mode} interferes with Viper, putting the following in
2273@file{.viper} should fix the problem:
2274@lisp
2275(viper-harness-minor-mode "nasty-mode")
2276@end lisp
2277@noindent
2278The argument to @code{viper-harness-minor-mode} is the name of the file for the
2279offending minor mode with the suffixes @file{.el} and @file{.elc} removed.
2280
2281It may not be always obvious which minor mode is at fault. The only
2282guidance here is to look into the file that defines the minor mode you are
2283suspecting, say @file{nasty-mode.el}, and see if it has a variable called
2284@code{nasty-mode-map}. Then check if there is a statement of the form
2285@lisp
2286(define-key nasty-mode-map key function)
2287@end lisp
2288@noindent
2289that binds the misbehaving
2290keys. If so, use the above line to harness @code{nasty-mode}. If your
2291suspicion is wrong, no harm is done if you harness a minor mode that
2292doesn't need to be harnessed.
2293
2294It is recommended to harness even those minor modes that don't override
2295Viper keys, but still have their own keymaps. A general way to
2296make a minor mode, @code{my-mode},
2297compatible with Viper is to have the file @file{my-mode.el} include the following code:
2298
2299@lisp
2300(when (fboundp 'viper-harness-minor-mode)
2301 (let ((lib (file-name-sans-extension
2302 (file-name-nondirectory load-file-name))))
2303 (viper-harness-minor-mode lib)))
2304@end lisp
2305
2306@vindex @code{viper-want-emacs-keys-in-vi}
2307@vindex @code{viper-want-emacs-keys-in-insert}
2308@vindex @code{viper-always}
2309@findex @code{viper-set-hooks}
2310@findex @code{viper-mode}
2311@findex @code{viper-harness-minor-mode}
2312@findex @code{remove-hook}
2313@findex @code{add-hook}
2314
2315@node Viper Specials,Vi Macros,Packages that Change Keymaps,Customization
2316@section Viper Specials
2317
2318Viper extends Vi with a number of useful features. This includes various
2319search functions, histories of search strings, Ex commands, insertions, and
2320Vi's destructive commands. In addition, Viper supports file name completion
2321and history, completion of Ex commands and variables, and many other
2322features. Some of these features are explained in detail elsewhere in this
2323document. Other features are explained here.
2324
2325@table @code
2326@item (viper-buffer-search-enable)
2327@item viper-buffer-search-char nil
2328Enable buffer search. Explicit call to @code{viper-buffer-search-enable}
2329sets @code{viper-buffer-search-char} to @kbd{g}. Alternatively, the user can
2330set @code{viper-buffer-search-char} in @file{.viper} to a key sequence
2331to be used for buffer search. There is no need to call
2332@code{viper-buffer-search-enable} in that case.
2333@findex @code{viper-buffer-search-enable}
2334@vindex @code{viper-buffer-search-char}
2335@item viper-toggle-search-style
2336This function, bound to @kbd{C-c /}, lets one toggle case-sensitive and
2337case-insensitive search, and also switch between plain vanilla search and
2338search via regular expressions. Without the prefix argument, the user is
2339asked which mode to toggle. With prefix argument 1, this toggles
2340case-sensitivity. With prefix argument 2, regular expression/vanilla search
2341will be toggled.
2342
2343However, we found that the most convenient way to toggle
2344these options is to bind a Vi macro to
2345bind @kbd{//} to toggles case sensitivity and to @kbd{///} to toggles
2346vanilla search. Thus, quickly hitting @kbd{/} twice will switch Viper from
2347case sensitive search to case-insensitive. Repeating this once again will
2348restore the original state. Likewise, quickly hitting @kbd{/} three times
2349will switch you from vanilla-style search to search via regular expressions.
2350If you hit something other than @kbd{/} after the first @kbd{/} or if the
2351second @kbd{/} doesn't follow quickly enough, then Viper will issue the
2352usual prompt @kbd{/} and will wait for input, as usual in Vi.
2353If you don't like this behavior, you can ``unrecord'' these macros in your
2354@file{~/.viper} file. For instance, if you don't like the above feature, put
2355this in @file{~/.viper}:
2356@example
2357(viper-set-searchstyle-toggling-macros 'undefine)
2358@end example
2359@findex @code{viper-set-searchstyle-toggling-macros}
2360
2361If you don't like this feature as a default, but would still like to have
2362it in some major modes, you can do so by first unsetting it globally, as
2363shown above, and then setting it in the desired major modes as follows:
2364@example
2365(viper-set-searchstyle-toggling-macros nil 'c-mode)
2366(viper-set-searchstyle-toggling-macros nil 'lisp-mode)
2367@end example
2368
2369@item Vi-isms in Emacs state
2370Some people find it useful to use the Vi-style search key, `/', to invoke
2371search in modes which Viper leaves in emacs-state. These modes are:
2372@code{dired-mode}, @code{mh-folder-mode},
2373@code{Info-mode}, and @code{Buffer-menu-mode}
2374(more may be added in the future). So, in the above modes, Viper binds `/'
2375so that it will behave Vi-style. Furthermore, in those major modes, Viper
2376binds `:' to invoke ex-style commands, like in vi-state. And, as described
2377above, `//' and `///' get bound to Vi-style macros that toggle
2378case-insensitivity and regexp-search.
2379
2380If you don't like these features---which I don't really understand---you
2381can unbind `/' and `:' in @code{viper-dired-modifier-map} (for Dired) or in
2382@code{viper-slash-and-colon-map}, for other modes.
2383@vindex @code{viper-slash-and-colon-map}
2384@vindex @code{viper-dired-modifier-map}
2385
2386To unbind the macros `//' and `///' for a major mode where you feel they
2387are undesirable, execute @code{viper-set-emacs-state-searchstyle-macros} with a
2388non-@code{nil} argument. This can be done either interactively, by supplying a
2389prefix argument, or by placing
2390@example
2391(viper-set-emacs-state-searchstyle-macros 'undefine)
2392@end example
2393@findex @code{viper-set-emacs-state-searchstyle-macros}
2394in the hook to the major mode (e.g., @code{dired-mode-hook}).
2395@xref{Vi Macros}, for more information on Vi macros.
2396
2397@item viper-heading-start
2398@item viper-heading-end
2399@cindex headings
2400@cindex sections
2401@cindex paragraphs
2402@cindex sentences
2403Regular Expressions for @kbd{[[} and @kbd{]]}. Note that Emacs defines
2404Regexps for paragraphs and sentences. @xref{Paragraphs,,Paragraphs and
2405Sentences,emacs,The GNU Emacs Manual}, for details.
2406@item M-x viper-set-expert-level
2407@findex @code{viper-set-expert-level}
2408Change your user level interactively.
2409@item viper-smart-suffix-list '("" "tex" "c" "cc" "el" "p")
2410@vindex @code{viper-smart-suffix-list}
2411Viper supports Emacs-style file completion when it prompts the user for a
2412file name. However, in many cases, the same directory may contain files
2413with identical prefix but different suffixes, e.g., prog.c, prog.o,
2414paper.tex, paper.dvi. In such cases, completion will stop at the `.'.
2415If the above variable is a list of strings representing suffixes, Viper will
2416try these suffixes
2417in the order listed and will check if the corresponding file exists.
2418
2419For instance, if completion stopped at `paper.'@: and the user typed
2420@key{RET},
2421then Viper will check if the files `paper.', `paper.tex', `paper.c', etc., exist.
2422It will take the first such file. If no file exists, Viper will give a chance
2423to complete the file name by typing the appropriate suffix. If `paper.'@: was
2424the intended file name, hitting return will accept it.
2425
2426To turn this feature off, set the above variable to @code{nil}.
2427
2428@item viper-insertion-ring-size 14
2429@vindex @code{viper-insertion-ring-size}
2430@cindex Insertion ring
2431Viper remembers what was previously inserted in Insert and Replace states.
2432Several such recent insertions are kept in a special ring of strings of size
2433@code{viper-insertion-ring-size}.
2434If you enter Insert or Replace state you can reinsert strings from this
2435ring by typing @kbd{C-c M-p} or @kbd{C-c M-n}. The former will search the
2436ring in
2437the direction of older insertions, and the latter will search in
2438the direction of newer insertions. Hitting @kbd{C-c M-p} or @kbd{C-c M-n}
2439in succession
2440will undo the previous insertion from the ring and insert the next item on
2441the ring. If a larger ring size is needed, change the value of the above
2442variable in the @file{~/.viper} file.
2443
2444Since typing these sequences of keys may be tedious, it is suggested that the
2445user should bind a function key, such as @kbd{f31}, as follows:
2446@example
2447(define-key viper-insert-global-user-map [f31]
2448 'viper-insert-prev-from-insertion-ring)
2449@end example
2450This binds @kbd{f31} (which is usually @kbd{R11} on a Sun workstation)
2451to the function that inserts the previous string in the insertion history.
2452To rotate the history in the opposite
2453direction, you can either bind an unused key to
2454@code{viper-insert-next-from-insertion-ring} or hit any digit (1 to 9) then
2455@kbd{f31}.
2456
2457One should not bind the above functions to @kbd{M-p} or @kbd{M-n}, since
2458this will interfere with the Minibuffer histories and, possibly, other
2459major modes.
2460
2461@item viper-command-ring-size 14
2462@vindex @code{viper-command-ring-size}
2463@cindex Destructive command ring
2464@cindex Destructive command history
2465Viper keeps track of the recent history of destructive
2466commands, such as @kbd{dw}, @kbd{i}, etc.
2467In Vi state,
2468the most recent command can be re-executed by hitting `@kbd{.}', as in Vi.
2469However, repeated typing @kbd{C-c M-p} will cause Viper to show the
2470previous destructive commands in the minibuffer. Subsequent hitting `@kbd{.}'
2471will execute the command that was displayed last.
2472The key @kbd{C-c M-n} will cycle through the command history in the
2473opposite direction.
2474Since typing @kbd{C-c M-p} may be tedious, it is more convenient to bind an
2475appropriate function to an unused function key on the keyboard and use that
2476key. For instance, the following
2477@example
2478(define-key viper-vi-global-user-map [f31]
2479 'viper-prev-destructive-command)
2480@end example
2481binds the key @kbd{f31} (which is usually @kbd{R11} on a Sun workstation)
2482to the function that searches the command history in the direction of older
2483commands. To search in the opposite
2484direction, you can either bind an unused key to
2485@code{viper-next-destructive-command} or hit any digit (1 to 9) then @kbd{f31}.
2486
2487One should not bind the above functions to @kbd{M-p} or @kbd{M-n}, since
2488this will interfere with the Minibuffer histories and, possibly, other
2489major modes.
2490
2491@item viper-minibuffer-vi-face 'viper-minibuffer-vi-face
2492@item viper-minibuffer-insert-face 'viper-minibuffer-insert-face
2493@item viper-minibuffer-emacs-face 'viper-minibuffer-emacs-face
2494These faces control the appearance of the minibuffer text in the
2495corresponding Viper states. You can change the appearance of these faces
2496through Emacs' customization widget, which is accessible through the
2497menubar.
2498
2499Viper is located in this widget under the @emph{Emulations} customization
2500subgroup of the @emph{Editing} group. All Viper faces are grouped together
2501in Viper's @emph{Highlighting} customization subgroup.
2502
2503Note that only the text you type in is affected by the above faces.
2504Prompts and Minibuffer messages are not affected.
2505
2506Purists who do not like adornments in the minibuffer can always zap them by
2507putting
2508@example
2509(copy-face 'default 'viper-minibuffer-vi-face)
2510(copy-face 'default 'viper-minibuffer-insert-face)
2511(copy-face 'default 'viper-minibuffer-emacs-face)
2512@end example
2513in the @file{~/.viper} file or through the customization widget, as
2514described above. However, in that case, the user will not have any
2515indication of the current Viper state in the minibuffer. (This is important
2516if the user accidentally switches to another Viper state by typing @key{ESC} or
2517@kbd{C-z}).
2518@item M-x viper-go-away
2519@findex @code{viper-go-away}
2520Make Viper disappear from the face of your running Emacs instance. If your
2521fingers start aching again, @kbd{M-x viper-mode} might save your day.
2522@item M-x toggle-viper-mode
2523@findex @code{toggle-viper-mode}
2524Toggle Viperization of Emacs on and off.
2525@end table
2526
2527@cindex Multifile documents and programs
2528
2529Viper provides some support for multi-file documents and programs.
2530If a document consists of several files we can designate one of them as a
2531master and put the following at the end of that file:
2532@lisp
2533;; Local Variables:
2534;; eval: (viper-setup-master-buffer "file1" "file2" "file3" "file4")
2535;; End:
2536@end lisp
2537@noindent
2538where @code{file1} to @code{file4} are names of files related to the master
2539file. Next time, when the master file is visited, the command
2540@code{viper-setup-master-buffer} will be evaluated and the above files will
2541be associated with the master file. Then, the new Ex command
2542@kbd{:RelatedFile} (abbr.@: @kbd{:R}) will display files 1 to 4 one after
2543another, so you can edit them. If a file is not in any Emacs buffer, it
2544will be visited. The command @kbd{PreviousRelatedFile} (abbr., @kbd{:P})
2545goes through the file list in the opposite direction.
2546@findex @kbd{:RelatedFile}
2547@findex @kbd{:PreviousRelatedFile}
2548
2549These commands are akin to @kbd{:n} and @kbd{:N}, but they allow the user to
2550focus on relevant files only.
2551
2552Note that only the master file needs to have the aforementioned block of
2553commands. Also, ";;" above can be replaced by some other
2554markers. Semicolon is good for Lisp programs, since it is considered a
2555comment designator there. For LaTeX, this could be "%%%", and for C the
2556above block should be commented out.
2557
2558Even though these commands are sometimes useful, they are no substitute for
2559the powerful @emph{tag table} facility of Emacs. Viper's @kbd{:tag} command
2560in a primitive interface to Emacs tags. @xref{Tags,Tags,Tags,emacs,
2561The GNU Emacs Manual}, for more information on tags.
2562
2563The following two commands are normally bound to a mouse click and are part
2564of Viper. They work only if Emacs runs as an application under X
2565Windows (or under some other window system for which a port of GNU Emacs 20
2566is available). Clicking the mouse when Emacs is invoked in an Xterm window
2567(using @code{emacs -nw}) will do no good.
2568
2569@table @code
2570@cindex mouse
2571@cindex mouse-search
2572@item viper-mouse-search-key (meta shift 1)
2573@vindex @code{viper-mouse-insert-key}
2574This variable controls the @emph{mouse-search} feature of Viper. The
2575default value
2576states that holding Meta and Shift keys while clicking mouse button 1
2577should initiate search for a region under the mouse pointer (defined
2578below). This command can take a prefix argument, which indicates the
2579occurrence of the pattern to search for.
2580
2581Note: while loading initially, Viper binds this mouse action only if it is
2582not already bound to something else. If you want to use the mouse-search
2583feature, and the @kbd{Meta-Shift-Mouse-1} mouse action is already bound to
2584something else, you can rebind the mouse-search feature by setting
2585@code{viper-mouse-search-key} to something else in your @code{~/.viper}
2586file:
2587@lisp
2588(setq viper-mouse-search-key '(meta 1))
2589@end lisp
2590This would bind mouse search to the action invoked by pressing the
2591Meta key and clicking mouse button 1. The allowed values of
2592@code{viper-mouse-search-key} are lists that contain a mouse-button number
2593(1,2, or 3) and any combination of the words `control', `meta', and
2594`shift'.
2595
2596If the requested mouse action (e.g., (meta 1)) is already taken for other
2597purposes then you have to confirm your intention by placing the following
2598command in @code{~/.viper} after setting @code{viper-mouse-search-key}:
2599@lisp
2600(viper-bind-mouse-search-key 'force)
2601@end lisp
2602
2603You can also change this setting interactively, through the customization
2604widget of Emacs (type @kbd{:customize}).
2605
2606The region that is chosen as a pattern to search for is determined as
2607follows. If search is invoked via a single click, Viper chooses the region
2608that lies between the beginning of the ``word'' under the pointer (``word''
2609is understood in Vi sense) and the end of that word. The only difference
2610with Vi's words is that in Lisp major modes `-' is considered an
2611alphanumeric symbol. This is done for the convenience of working with Lisp
2612symbols, which often have an `-' in them. Also, if you click on a
2613non-alphanumeric character that is not a word separator (in Vi sense) then
2614this character will also be considered alphanumeric, provided that it is
2615adjacent (from either side) to an alphanumeric character. This useful
2616feature gives added control over the patterns selected by the mouse click.
2617
2618On a double-click, the region is determined by the beginning of the current
2619Vi's ``Word'' (i.e., the largest non-separator chunk of text) and the End
2620of that ``Word'' (as determined by the @kbd{E} command).
2621
2622On a triple-click, the region consists of the entire line where the click
2623occurred with all leading and trailing spaces and tabs removed.
2624
2625@cindex mouse-insert
2626@item viper-mouse-insert-key (meta shift 2)
2627@vindex @code{viper-mouse-insert-key}
2628This variable controls the @emph{mouse-insert} feature of Viper.
2629The above default value states that
2630holding Meta and Shift keys while clicking mouse button 2
2631should insert the region surrounding the
2632mouse pointer. The rules defining this region are the same as for
2633mouse-search. This command takes an optional prefix argument, which
2634indicates how many such regions to snarf from the buffer and insert. (In
2635case of a triple-click, the prefix argument is ignored.)
2636
2637Note: while loading initially, Viper binds this mouse action only if it not
2638already bound to something else. If you want to use this feature and the
2639default mouse action is already bound, you can rebind mouse-insert by
2640placing this command in @code{~/.viper}:
2641@lisp
2642(setq viper-mouse-insert-key '(meta 2))
2643@end lisp
2644If you want to bind mouse-insert to an action even if this action is
2645already taken for other purposes in Emacs, then you should add this command
2646to @code{~/.viper}, after setting @code{viper-mouse-insert-key}:
2647@lisp
2648(viper-bind-mouse-insert-key 'force)
2649@end lisp
2650
2651This value can also be changed via the Emacs customization widget at the
2652menubar.
2653
2654@item viper-multiclick-timeout
2655This variable controls the rate at which double-clicking must occur for the
2656purpose of mouse search and mouse insert. By default, this is set to
2657@code{double-click-time} in Emacs and to
2658@code{mouse-track-multi-click-time} milliseconds in XEmacs.
2659@end table
2660@kindex @kbd{S-Mouse-1}
2661@kindex @kbd{S-Mouse-2}
2662@kindex @kbd{meta shift button1up}
2663@kindex @kbd{meta shift button2up}
2664@vindex @code{viper-multiclick-timeout}
2665@findex @code{viper-mouse-click-insert-word}
2666@findex @code{viper-mouse-click-search-word}
2667
2668Note: The above functions search and insert in the selected window of
2669the latest active frame. This means that you can click in another window or
2670another frame and have search or insertion done in the frame and window you
2671just left. This lets one use these functions in a multi-frame
2672configuration. However, this may require some getting used to. For
2673instance, if you are typing in a frame, A, and then move the mouse to frame
2674B and click to invoke mouse search, search (or insertion) will be performed
2675in frame A. To perform search/insertion in frame B, you will first have to
2676shift focus there, which doesn't happen until you type a character or
2677perform some other action in frame B---mouse search doesn't shift focus.
2678
2679If you decide that you don't like the above feature and always want
2680search/insertion be performed in the frame where the click occurs, don't
2681bind (and unbind, if necessary) @code{viper-mouse-catch-frame-switch} from
2682the mouse event it is bound to.
2683
2684Mouse search is integrated with Vi-style search, so you can
2685repeat it with @kbd{n} and @kbd{N}. It should be also noted that, while
2686case-sensitivity of search in Viper is controlled by the variable
2687@code{viper-case-fold-search}, the case of mouse search is
2688controlled by the Emacs variable @code{case-fold-search}, which may be set
2689differently from @code{viper-case-fold-search}. Therefore, case-sensitivity
2690of mouse search may be different from that of the usual Vi-style search.
2691
2692Finally, if the way Viper determines the word to be searched for or to be
2693inserted is not what you want, there is a variable,
2694@code{viper-surrounding-word-function}, which can be changed to indicate
2695another function for snarfing words out of the buffer. The catch is that
2696you will then have to write such a function and make it known to your
2697Emacs. The function @code{viper-surrounding-word} in @file{viper.el} can be
2698used as a guiding example.
2699
2700@node Vi Macros, ,Viper Specials,Customization
2701@section Vi Macros
2702
2703@cindex Vi macros
2704
2705Viper supports much enhanced Vi-style macros and also facilitates the use
2706of Emacs-style macros. To define a temporary macro, it is generally more
2707convenient to use Emacs keyboard macro facility. Emacs keyboard macros are
2708usually defined anonymously, and the latest macro can be executed by typing
2709@kbd{C-x e} (or @kbd{*}, if Viper is in Vi state). If you need to use several
2710temporary macros, Viper lets you save them to a
2711register (a lowercase letter); such macros can then be executed by typing
2712@kbd{@@a} in Vi state (if a macro was previously saved in register
2713@kbd{a}).
2714@xref{Macros and Registers}, for details.
2715
2716If, however, you need to use a macro regularly, it must be given a
2717permanent name and saved. Emacs manual explains how to do this, but
2718invocation of named Emacs macros is quite different from Vi's. First,
2719invocation of permanent Emacs macros takes time because it requires typing
2720too many keys (to a Vi user's taste, anyway).
2721Second, binding such macros to function keys, for
2722fast access, hogs valuable real estate on the keyboard.
2723
2724Vi-style macros are better in that respect, since Vi lets the user overload
2725the meaning of key sequences: keys typed in fast succession are treated
2726specially, if this key sequence is bound to a macro.
2727
2728Viper provides Vi-style keyboard macros through the usual Ex commands,
2729@kbd{:map} and
2730@kbd{:map!}. These macros are much more powerful in Viper than
2731they are in the original Vi and in other emulators. This is because Viper
2732implements an enhanced vi-style
2733interface to the powerful Emacs keyboard macro facility.
2734
2735First, any Emacs
2736command can be executed while defining a macro, not just the Vi
2737commands. In particular, the user can invoke Emacs commands via @kbd{M-x
2738command-name} or by pressing various function keys on the keyboard. One
2739can even use the mouse, although this is usually not useful and is not
2740recommended (and macros defined with the use of the mouse cannot be saved in
2741command history and in the startup file, for future use).
2742
2743Macros defined by mixing Vi and Emacs commands are represented as
2744vectors. So, don't be confused when you see one (usually through the
2745history of Ex commands). For instance, if @kbd{gg} is defined by typing
2746@kbd{l}, the up-arrow key and @kbd{M-x next-line}, its definition will look
2747as follows in Emacs:
2748
2749@example
2750[l up (meta x) n e x t - l i n e return]
2751@end example
2752
2753Second, Viper macros are defined in a WYSIWYG style. This means that
2754commands are executed as you type them, so you can see precisely what is
2755being defined. Third, macros can be bound to arbitrary sequences of keys,
2756not just to printable keys. For instance, one can define a macro that will
2757be invoked by hitting @kbd{f3} then @kbd{f2} function keys. (The keys
2758@kbd{delete} and @kbd{backspace} are excluded; also, a macro invocation
2759sequence can't start with @key{ESC}. Some other keys, such as @kbd{f1} and
2760@kbd{help}, can't be bound to macros under Emacs, since they
2761are bound in @code{key-translation-map}, which overrides any other binding
2762the user gives to keys. In general, keys that have a binding in
2763@code{key-translation-map} can't be bound to a macro.)
2764
2765Fourth, in Viper, one can define macros that are specific to a given
2766buffer, a given major mode, or macros that are defined for all buffers. In
2767fact, the same macro name can have several different definitions: one
2768global, several definitions for various major modes, and
2769definitions for various specific buffers. Buffer-specific definitions
2770override mode-specific definitions, which, in turn, override global
2771definitions.
2772
2773As if all that is not enough, Viper (through its interface to Emacs
2774macros) lets the user define keyboard macros that ask for confirmation or
2775even prompt the user for input and then continue. To do this, one should
2776type @kbd{C-x q} (for confirmation) or @kbd{C-u C-x q} (for prompt).
2777For details, @pxref{Keyboard Macro Query,,Customization,emacs,The GNU Emacs
2778Manual} @refill
2779
2780When the user finishes defining a macro (which is done by typing @kbd{C-x)} ---
2781a departure from Vi), you will be asked whether you want this
2782macro to be global, mode-specific, or buffer-specific. You will also be
2783given a chance to save the macro in your @file{~/.viper} file.
2784This is the easiest way to save a macro and make
2785it permanently available. If you work your startup files with bare hands,
2786here is how Viper saves the above macro so that it will be
2787available in Viper's Insert state (and Replace state) in buffer @code{my-buf}
2788only:
2789
2790@example
2791(viper-record-kbd-macro "gg" 'insert-state
2792 [l up (meta x) n e x t - l i n e return]
2793 "my-buf")
2794@end example
2795
2796@noindent
2797To do the same for Vi state and all buffers with the major mode
2798@code{cc-mode}, use:
2799
2800@example
2801(viper-record-kbd-macro "gg" 'vi-state
2802 [l up (meta x) n e x t - l i n e return]
2803 'cc-mode)
2804@end example
2805
2806@noindent
2807Both macro names and macro definitions are vectors of symbols that denote
2808keys on the keyboard. Some keys, like @kbd{\}, @kbd{ }, or digit-keys must
2809be escaped with a backslash. Modified keys are represented as lists. For
2810instance, holding Meta and Control and pressing @kbd{f4} is represented as
2811@kbd{(control meta f4)}.
2812If all members of a vectors are printable characters (or sequences, such as
2813@kbd{\e}, @kbd{\t}, for @key{ESC} and @key{TAB}), then they can also be represented as
2814strings:
2815
2816@example
2817(viper-record-kbd-macro "aa" 'vi-state "aaa\e" "my-buffer")
2818@end example
2819
2820@noindent
2821Thus, typing @kbd{aa} fast in Vi state will switch Viper to Insert state
2822(due to the first @kbd{a}), insert @kbd{aa}, and then it will switch back to Vi
2823state. All this will take effect only in the buffer named @code{my-buffer}.
2824
2825Note that the last argument to @code{viper-record-kbd-macro} must be either a
2826string (a buffer name), a symbol representing a major mode, or @code{t};
2827the latter says that the macro is to be defined for all buffers
2828(which is how macros are defined in original Vi).
2829
2830For convenience, Viper also lets you define Vi-style macros in its Emacs
2831state. There is no Ex command, like @kbd{:map} and @kbd{:map!} for doing
2832this, but the user can include such a macro in the @file{~/.viper} file. The
2833only thing is that the @code{viper-record-kbd-macro} command should specify
2834@code{emacs-state} instead of @code{vi-state} or @code{insert-state}.
2835
2836The user can get rid of a macro either by using the Ex commands @kbd{:unmap}
2837and @kbd{:unmap!} or by issuing a call to @code{viper-unrecord-kbd-macro}.
2838The latter is more powerful, since it can delete macros even in
2839@code{emacs-state}. However, @code{viper-unrecord-kbd-macro} is usually
2840needed only when the user needs to get rid of the macros that are already
2841predefined in Viper.
2842The syntax is:
2843@findex @code{viper-unrecord-kbd-macro}
2844@example
2845(viper-unrecord-kbd-macro macro state)
2846@end example
2847@noindent
2848The second argument must be @code{vi-state}, @code{insert-state}, or
2849@code{emacs-state}. The first argument is a name of a macro. To avoid
2850mistakes in specifying names of existing macros, type @kbd{M-x
2851viper-describe-kbd-macros} and use a name from the list displayed by this
2852command.
2853
2854If an error occurs during macro definition, Emacs
2855aborts the process, and it must be repeated. This is analogous to Vi,
2856except that in Vi the user doesn't know there is an error until the macro is
2857actually run. All that means that in order for a definition to be
2858successful, the user must do some simple planning of the process in
2859advance, to avoid errors. For instance, if you want to map @kbd{gg} to
2860@kbd{llll} in Vi state, you must make sure that there is enough room on the
2861current line. Since @kbd{l} moves the cursor forward, it may signal an
2862error on reaching the end of line, which will abort the definition.
2863
2864These precautions are necessary only when defining macros; they will help
2865avoid the need to redo the job. When macros are actually run, an error
2866during the execution will simply terminate the current execution
2867(but the macro will remain mapped).
2868
2869A macro name can be a string of characters or a vector of keys.
2870The latter makes it possible to define macros bound to, say, double-hits
2871on a function key, such as @kbd{up} or @kbd{f13}.
2872This is very useful if you run out of function keys on your keyboard; it
2873makes Viper macro facility a @emph{keyboard doubler}, so to speak.
2874
2875Elsewhere (@xref{Key Bindings}, for details), we review
2876the standard Emacs mechanism for binding function keys to commands.
2877For instance,
2878
2879@example
2880(global-set-key [f13] 'repeat-complex-command)
2881@end example
2882
2883@noindent
2884binds the key f13 to the Emacs function that repeats the last minibuffer
2885command. Under Viper, however, you may still use this key for additional
2886purposes, if you bind, say, a double-hitting action for that key to some
2887other function. Emacs doesn't allow the user to do that, but Viper does
2888this through its keyboard macro facility. To do this, type @kbd{:map }
2889first. When you are asked to enter a macro name, hit f13 twice, followed by
2890@key{RET} or @key{SPC}.
2891
2892Emacs will now start the mapping process by actually executing
2893Vi and Emacs commands, so that you could see what will happen each time the
2894macro is executed. Suppose now we wanted to bind the key sequence
2895@kbd{f13 f13} to the command @code{eval-last-sexp}. To accomplish this, we
2896can type @kbd{M-x eval-last-sexp} followed by @kbd{C-x )}.
2897If you answer positively to Viper's offer to save this macro in @file{~/.viper}
2898for future uses, the following will be inserted in that file:
2899
2900@example
2901(viper-record-kbd-macro [f16 f16] 'vi-state
2902 [(meta x) e v a l - l a s t - s e x p]
2903 'lisp-interaction-mode)
2904@end example
2905
2906To illustrate the above point, Viper provides two canned macros, which, by
2907default, are bound to @kbd{[f12 \1]} and @kbd{[f12 \2]} (invoked by typing
2908@kbd{f12} then @kbd{1} and @kbd{2}, respectively). These macros are useful
2909shortcuts to Viper's command ring history. The first macro will execute the
2910second-last destructive command (the last one is executed by @kbd{.}, as
2911usual). The second macro executes the third-last command.
2912
2913If you need to go deeper into the command history, you will have to use
2914other commands, as described earlier in this section; or you can bind,
2915say, @kbd{f12 \3} like this:
2916
2917@example
2918(viper-record-kbd-macro [f12 \3] 'vi-state
2919 [(meta x) r e p e a t - f r o m - h i s t o r y]
2920 t)
2921@end example
2922
2923
2924Note that even though the macro uses the function key @kbd{f12}, the key is
2925actually free and can still be bound to some Emacs function via
2926@code{define-key} or @code{global-set-key}.
2927
2928
2929Viper allows the user to define macro names that are prefixes of other macros.
2930For instance, one can define @kbd{[[} and @kbd{[[[[} to be macros.
2931If you type the exact sequence of such keys and then pause, Viper will
2932execute the right macro. However, if you don't pause and, say, type
2933@kbd{[[[[text} then the conflict is resolved as follows. If only one of the
2934key sequences, @kbd{[[} or @kbd{[[[[} has a definition applicable to the
2935current buffer, then, in fact, there is no conflict and the right macro
2936will be chosen. If both have applicable definitions, then the first one
2937found will be executed. Usually this is the macro with a shorter name. So,
2938in our case, @kbd{[[[[text} will cause the macro @kbd{[[} to be executed
2939twice and then the remaining keys, @kbd{t e x t}, will be processed.
2940
2941When defining macros using @kbd{:map} or @kbd{:map!}, the user enters
2942the actually keys to be used to invoke the macro. For instance, you
2943should hit the actual key @kbd{f6} if it is to be part of a macro
2944name; you do @emph{not} write @kbd{f 6}. When entering keys, Viper
2945displays them as strings or vectors (e.g., @code{"abc"} or @code{[f6
2946f7 a]}). The same holds for unmapping. Hitting @key{TAB} while
2947typing a macro name in the @kbd{:unmap} or @kbd{:unmap!} command will
2948cause name completion. Completions are displayed as strings or
2949vectors. However, as before, you don't actually type @samp{"},
2950@samp{[}, or @samp{]} that appear in the completions. These are
2951meta-symbols that indicate whether the corresponding macro name is a
2952vector or a string.
2953
2954One last difference from Vi: Vi-style keyboard macros cannot be defined in
2955terms of other Vi-style keyboard macros (but named Emacs macros are OK).
2956More precisely, while defining or executing a macro, the special meaning
2957of key sequences (as Vi macros) is ignored.
2958This is because it is all too easy to create an infinite loop in this way.
2959Since Viper macros are much more powerful than Vi's it is impossible to
2960detect such loops. In practice, this is not really a limitation but,
2961rather, a feature.
2962
2963We should also note that Vi macros are disabled in the Minibuffer, which
2964helps keep some potential troubles away.
2965
2966The rate at which the user must type keys in order for them to be
2967recognized as a timeout macro is controlled by the variable
2968@code{viper-fast-keyseq-timeout}, which defaults to 200 milliseconds.
2969
2970For the most part, Viper macros defined in @file{~/.viper} can be shared
2971between X and TTY modes.
2972The problem with TTY may be that the function keys there generate sequences
2973of events instead of a single event (as under a window system).
2974Emacs maps some of these sequences back to the logical keys
2975(e.g., the sequences generated by the arrow keys are mapped to @kbd{up},
2976@kbd{left}, etc.). However, not all function keys are mapped in this way.
2977Macros that are bound to key sequences that contain such unmapped function
2978keys have to be redefined for TTY's (and possibly for every type of TTY you
2979may be using). To do this, start Emacs on an appropriate TTY device and
2980define the macro using @kbd{:map}, as usual.
2981
2982@findex @code{viper-describe-kbd-macros}
2983Finally, Viper provides a function that conveniently displays all macros
2984currently defined. To see all macros along with their definitions, type
2985@kbd{M-x viper-describe-kbd-macros}.
2986
2987@node Commands,,Customization,Top
2988@chapter Commands
2989
2990This section is a semi-automatically bowdlerized version of the Vi
2991reference created by @* @samp{maart@@cs.vu.nl} and others. It can be
2992found on the Vi archives. This reference has been adapted for Viper.@refill
2993
2994@menu
2995* Groundwork:: Textual Conventions and Viper basics
2996* Text Handling:: Moving, Editing, Undoing.
2997* Display:: Scrolling.
2998* File and Buffer Handling:: Editing, Writing and Quitting.
2999* Mapping:: Mapping Keys, Keyboard Macros
3000* Shell Commands:: Accessing Shell Commands, Processing Text
3001* Options:: Ex options, the @kbd{:set} commands
3002* Emacs Related Commands:: Meta Keys, Windows
3003* Mouse-bound Commands:: Search and insertion of text
3004@end menu
3005
3006@node Groundwork, Text Handling, Commands, Commands
3007@comment node-name, next, previous, up
3008@section Groundwork
3009
3010The VI command set is based on the idea of combining motion commands
3011with other commands. The motion command is used as a text region
3012specifier for other commands.
3013We classify motion commands into @dfn{point commands} and
3014@dfn{line commands}.@refill
3015
3016@cindex point commands
3017
3018The point commands are:
3019
3020@quotation
3021@kbd{h}, @kbd{l}, @kbd{0}, @kbd{$}, @kbd{w}, @kbd{W}, @kbd{b}, @kbd{B},
3022@kbd{e}, @kbd{E}, @kbd{(}, @kbd{)}, @kbd{/}, @kbd{?}, @kbd{`}, @kbd{f},
3023@kbd{F}, @kbd{t}, @kbd{T}, @kbd{%}, @kbd{;}, @kbd{,}, @kbd{^}
3024@end quotation
3025
3026@cindex line commands
3027
3028The line commands are:
3029
3030@quotation
3031@kbd{j}, @kbd{k}, @kbd{+}, @kbd{-}, @kbd{H}, @kbd{M}, @kbd{L}, @kbd{@{},
3032@kbd{@}}, @kbd{G}, @kbd{'}, @kbd{[[}, @kbd{]]}, @kbd{[]}
3033@end quotation
3034@noindent
3035
3036Text Deletion Commands (@pxref{Deleting Text}), Change commands
3037(@pxref{Changing Text}), even Shell Commands (@pxref{Shell Commands})
3038use these commands to describe a region of text to operate on.
3039
3040@cindex r and R region specifiers
3041
3042Viper adds two region descriptors, @kbd{r} and @kbd{R}. These describe
3043the Emacs regions (@pxref{Basics}), but they are not movement commands.
3044
3045The command description uses angle brackets @samp{<>} to indicate
3046metasyntactic variables, since the normal conventions of using simple
3047text can be confusing with Viper where the commands themselves are
3048characters. Watch out where @kbd{<} shift commands and @kbd{<count>} are
3049mentioned together!!!
3050
3051@kindex <move>
3052@kindex <a-z>
3053@kindex <address>
3054@cindex <move>
3055@cindex <a-z>
3056@cindex <address>
3057@cindex movements
3058
3059@samp{<move>} refers to the above movement commands, and @samp{<a-z>}
3060refers to registers or textmarkers from @samp{a} to @samp{z}. Note
3061that the @samp{<move>} is described by full move commands, that is to
3062say they will take counts, and otherwise behave like normal move commands.
3063@cindex Ex addresses
3064@samp{<address>} refers to Ex line addresses, which include
3065
3066@table @kbd
3067@item .@: <No address>
3068Current line
3069@item .+n .-n
3070Add or subtract for current line
3071@item number
3072Actual line number, use @kbd{.=} to get the line number
3073@item '<a-z>
3074Textmarker
3075@item $
3076Last line
3077@item x,y
3078Where x and y are one of the above
3079@item %
3080@cindex % (Ex address)
3081For the whole file, same as (1,$).
3082@item /<pat>/
3083@itemx ?<pat>?
3084Next or previous line with pattern <pat>.
3085
3086Note that the pattern is allowed to contain newline character (inserted as
3087@kbd{C-qC-j}). Therefore, one can search for patterns that span several
3088lines.
3089@end table
3090
3091@cindex % (Current file)
3092Note that @samp{%} is used in Ex commands @kbd{:e} and @kbd{:r <shell-cmd>}
3093to mean current file. If you want a @samp{%} in your command, it must be
3094escaped as @samp{\%}. Note that @kbd{:w} and the regular @kbd{:r <file>}
3095command doesn't support the meta symbols @samp{%} and @samp{#}, because
3096file history is a better mechanism.
3097@cindex # (Previous file)
3098Similarly, @samp{#} expands to the previous file. The previous file is
3099the first file in @kbd{:args} listing. This defaults to previous window
3100in the VI sense if you have one window only.
3101
3102@kindex <args>
3103@kindex <cmd>
3104@cindex <args>
3105@cindex <cmd>
3106@noindent
3107Others like @samp{<args> -- arguments}, @samp{<cmd> -- command} etc.
3108should be fairly obvious.
3109
3110@noindent
3111Common characters referred to include:
3112
3113@table @kbd
3114@item <sp>
3115Space
3116@item <ht>
3117Tab
3118@item <lf>
3119Linefeed
3120@item <esc>
3121Escape
3122@item <cr>
3123Return, Enter
3124@end table
3125@cindex <cr>
3126@cindex <esc>
3127@cindex <lf>
3128@cindex <ht>
3129@cindex <sp>
3130
3131@cindex words
3132@cindex WORDS
3133@cindex char
3134@cindex CHAR
3135
3136We also use @samp{word} for alphanumeric/non-alphanumeric words, and
3137@samp{WORD} for whitespace delimited words. @samp{char} refers to any
3138@acronym{ASCII} character, @samp{CHAR} to non-whitespace character.
3139Brackets @samp{[]} indicate optional parameters; @samp{<count>} also
3140optional, usually defaulting to 1. Brackets are elided for
3141@samp{<count>} to eschew obfuscation.
3142
3143Viper's idea of Vi's words is slightly different from Vi. First, Viper
3144words understand Emacs symbol tables. Therefore, all symbols declared to be
3145alphanumeric in a symbol table can automatically be made part of the Viper
3146word. This is useful when, for instance, editing text containing European,
3147Cyrillic, Japanese, etc., texts.
3148
3149Second, Viper lets you depart from Vi's idea of a word by changing the a
3150syntax preference via the customization widget (the variable
3151@code{viper-syntax-preference}) or by executing
3152@code{viper-set-syntax-preference} interactively.
3153
3154By default, Viper syntax preference is @code{reformed-vi}, which means that
3155Viper considers only those symbols to be part of a word that are specified
3156as word-symbols by the current Emacs syntax table (which may be different
3157for different major modes) plus the underscore symbol @kbd{_}, minus the
3158symbols that are not considered words in Vi (e.g., `,',;, etc.), but may be
3159considered as word-symbols by various Emacs major modes. Reformed-Vi works
3160very close to Vi, and it also recognizes words in other
3161alphabets. Therefore, this is the most appropriate mode for editing text
3162and is likely to fit all your needs.
3163
3164You can also set Viper syntax preference to @code{strict-vi}, which would
3165cause Viper to view all non-English letters as non-word-symbols.
3166
3167You can also specify @code{emacs} as your preference, which would
3168make Viper use exactly the same notion of a word as Emacs does. In
3169particular, the underscore may not be part of a word in some major modes.
3170
3171Finally, if @code{viper-syntax-preference} is set to @code{extended}, Viper
3172words would consist of characters that are classified as alphanumeric
3173@emph{or} as parts of symbols. This is convenient for editing programs.
3174
3175@code{viper-syntax-preference} is a local variable, so it can have different
3176values for different major modes. For instance, in programming modes it can
3177have the value @code{extended}. In text modes where words contain special
3178characters, such as European (non-English) letters, Cyrillic letters, etc.,
3179the value can be @code{reformed-vi} or @code{emacs}.
3180If you consider using different syntactic preferences for different major
3181modes, you should execute, for example,
3182
3183@example
3184(viper-set-syntax-preference nil "extended")
3185@end example
3186
3187in the appropriate major mode hooks.
3188
3189@vindex @code{viper-syntax-preference}
3190@findex @code{viper-set-syntax-preference}
3191@cindex syntax table
3192
3193
3194
3195The above discussion concerns only the movement commands. In regular
3196expressions, words remain the same as in Emacs. That is, the expressions
3197@code{\w}, @code{\>}, @code{\<}, etc., use Emacs' idea of what is a word,
3198and they don't look into the value of variable
3199@code{viper-syntax-preference}. This is because Viper avoids changing
3200syntax tables in order to not thwart the various major modes that set these
3201tables.
3202
3203The usual Emacs convention is used to indicate Control Characters, i.e
3204C-h for Control-h. @emph{Do not confuse this with a sequence of separate
3205characters
3206C, -, h!!!} The @kbd{^} is itself, never used to indicate a
3207Control character.
3208
3209Finally, we note that Viper's Ex-style commands can be made to work on the
3210current Emacs region. This is done by typing a digit argument before
3211@kbd{:}. For instance, typing @kbd{1:} will prompt you with something like
3212@emph{:123,135}, assuming that the current region starts at line 123 and
3213ends at line 135. There is no need to type the line numbers, since Viper
3214inserts them automatically in front of the Ex command.
3215@cindex Ex commands
3216
3217@node Text Handling, Display, Groundwork, Commands
3218@section Text Handling
3219
3220@menu
3221* Move Commands:: Moving, Searching
3222* Marking:: Textmarkers in Viper and the Emacs Mark.
3223* Appending Text:: Text insertion, Shifting, Putting
3224* Editing in Insert State:: Autoindent, Quoting etc.
3225* Deleting Text:: Deleting
3226* Changing Text:: Changing, Replacement, Joining
3227* Search and Replace:: Searches, Query Replace, Pattern Commands
3228* Yanking:: Yanking, Viewing Registers
3229* Undoing:: Multiple Undo, Backups
3230@end menu
3231
3232@node Move Commands,Marking,,Text Handling
3233@subsection Move Commands
3234
3235@cindex movement commands
3236@cindex searching
3237@cindex textmarkers
3238@cindex markers
3239@cindex column movement
3240@cindex paragraphs
3241@cindex headings
3242@cindex sections
3243@cindex sentences
3244@cindex matching parens
3245@cindex paren matching
3246
3247@table @kbd
3248@item <count> h C-h
3249<count> chars to the left.
3250@item <count> j <lf> C-n
3251<count> lines downward.
3252@item <count> l <sp>
3253<count> chars to the right.
3254@item <count> k C-p
3255<count> lines upward.
3256@item <count> $
3257To the end of line <count> from the cursor.
3258@item <count> ^
3259To the first CHAR <count> - 1 lines lower.
3260@item <count> -
3261To the first CHAR <count> lines higher.
3262@item <count> + <cr>
3263To the first CHAR <count> lines lower.
3264@item 0
3265To the first char of the line.
3266@item <count> |
3267To column <count>
3268@item <count> f<char>
3269<count> <char>s to the right (find).
3270@item <count> t<char>
3271Till before <count> <char>s to the right.
3272@item <count> F<char>
3273<count> <char>s to the left.
3274@item <count> T<char>
3275Till after <count> <char>s to the left.
3276@item <count> ;
3277Repeat latest @kbd{f t F T} <count> times.
3278@item <count> ,
3279Repeat latest @kbd{f t F T}
3280<count> times in opposite direction.
3281@item <count> w
3282<count> words forward.
3283@item <count> W
3284<count> WORDS forward.
3285@item <count> b
3286<count> words backward.
3287@item <count> B
3288<count> WORDS backward.
3289@item <count> e
3290To the end of word <count> forward.
3291@item <count> E
3292To the end of WORD <count> forward.
3293@item <count> G
3294Go to line <count> (default end-of-file).
3295@item <count> H
3296To line <count> from top of the screen (home).
3297@item <count> L
3298To line <count> from bottom of the screen (last).
3299@item M
3300To the middle line of the screen.
3301@item <count> )
3302<count> sentences forward.
3303@item <count> (
3304<count> sentences backward.
3305@item <count> @}
3306<count> paragraphs forward.
3307@item <count> @{
3308<count> paragraphs backward.
3309@item <count> ]]
3310To the <count>th heading.
3311@item <count> [[
3312To the <count>th previous heading.
3313@item <count> []
3314To the end of <count>th heading.
3315@item m<a-z>
3316Mark the cursor position with a letter.
3317@item `<a-z>
3318To the mark.
3319@item '<a-z>
3320To the first CHAR of the line with the mark.
3321@item [<a-z>
3322Show contents of textmarker.
3323@item ]<a-z>
3324Show contents of register.
3325@item ``
3326To the cursor position before the latest absolute
3327jump (of which are examples @kbd{/} and @kbd{G}).
3328@item ''
3329To the first CHAR of the line on which the cursor
3330was placed before the latest absolute jump.
3331@item <count> /<string>
3332To the <count>th occurrence of <string>.
3333@item <count> /<cr>
3334To the <count>th occurrence of <string> from previous @kbd{/ or ?}.
3335@item <count> ?<string>
3336To the <count>th previous occurrence of <string>.
3337@item <count> ?<cr>
3338To the <count>th previous occurrence of <string> from previous @kbd{?@: or /}.
3339@item n
3340Repeat latest @kbd{/} @kbd{?} (next).
3341@item N
3342Repeat latest search in opposite direction.
3343@item C-c /
3344Without a prefix argument, this command toggles
3345case-sensitive/case-insensitive search modes and plain vanilla/regular
3346expression search. With the prefix argument 1, i.e.,
3347@kbd{1 C-c /}, this toggles case-sensitivity; with the prefix argument 2,
3348toggles plain vanilla search and search using
3349regular expressions. @xref{Viper Specials}, for alternative ways to invoke
3350this function.
3351@cindex vanilla search
3352@cindex case-sensitive search
3353@cindex case-insensitive search
3354@item %
3355Find the next bracket/parenthesis/brace and go to its match.
3356By default, Viper ignores brackets/parentheses/braces that occur inside
3357parentheses. You can change this by setting
3358@code{viper-parse-sexp-ignore-comments} to @code{nil} in your @file{.viper} file.
3359This option can also be toggled interactively if you quickly hit @kbd{%%%}.
3360
3361This latter feature is implemented as a vi-style keyboard macro. If you
3362don't want this macro, put
3363
3364@example
3365(viper-set-parsing-style-toggling-macro 'undefine)
3366@end example
3367@findex @code{viper-set-parsing-style-toggling-macro}
3368
3369in your @file{~/.viper} file.
3370
3371@end table
3372@kindex @kbd{%}
3373@kindex @kbd{C-c /}
3374@kindex @kbd{N}
3375@kindex @kbd{n}
3376@kindex @kbd{?<cr>}
3377@kindex @kbd{/<cr>}
3378@kindex @kbd{?<string>}
3379@kindex @kbd{/<string>}
3380@kindex @kbd{''}
3381@kindex @kbd{``}
3382@kindex @kbd{]<a-z>}
3383@kindex @kbd{[<a-z>}
3384@kindex @kbd{'<a-z>}
3385@kindex @kbd{`<a-z>}
3386@kindex @kbd{m<a-z>}
3387@kindex @kbd{[]}
3388@kindex @kbd{[[}
3389@kindex @kbd{]]}
3390@kindex @kbd{@{}
3391@kindex @kbd{@}}
3392@kindex @kbd{(}
3393@kindex @kbd{)}
3394@kindex @kbd{M}
3395@kindex @kbd{L}
3396@kindex @kbd{H}
3397@kindex @kbd{G}
3398@kindex @kbd{E}
3399@kindex @kbd{e}
3400@kindex @kbd{B}
3401@kindex @kbd{b}
3402@kindex @kbd{W}
3403@kindex @kbd{w}
3404@kindex @kbd{,}
3405@kindex @kbd{;}
3406@kindex @kbd{T<char>}
3407@kindex @kbd{F<char>}
3408@kindex @kbd{t<char>}
3409@kindex @kbd{f<char>}
3410@kindex @kbd{|}
3411@kindex @kbd{0}
3412@kindex @kbd{<cr>}
3413@kindex @kbd{+}
3414@kindex @kbd{-}
3415@kindex @kbd{^}
3416@kindex @kbd{$}
3417@kindex @kbd{C-p}
3418@kindex @kbd{<lf>}
3419@kindex @kbd{<sp>}
3420@kindex @kbd{C-n}
3421@kindex @kbd{C-h}
3422@kindex @kbd{h}
3423@kindex @kbd{j}
3424@kindex @kbd{k}
3425@kindex @kbd{l}
3426@vindex @code{viper-parse-sexp-ignore-comments}
3427
3428@node Marking,Appending Text,Move Commands,Text Handling
3429@subsection Marking
3430
3431Emacs mark is referred to in the region specifiers @kbd{r} and @kbd{R}.
3432@xref{Emacs Preliminaries}, and @xref{Basics}, for explanation. Also
3433see @ref{Mark,,Mark,emacs,The GNU Emacs manual}, for an explanation of
3434the Emacs mark ring.
3435
3436@cindex marking
3437
3438@table @kbd
3439@item m<a-z>
3440Mark the current file and position with the specified letter.
3441@item m .
3442Set the Emacs mark (@pxref{Emacs Preliminaries}) at point.
3443@item m ^
3444Set the Emacs mark (@pxref{Emacs Preliminaries}) back to where it was last
3445set with the @kbd{m.} command. This is useful when you set the mark with
3446@kbd{m.}, but then some other command (such as @kbd{L} or @kbd{G}) changes
3447it in a way that you didn't like.
3448@item m <
3449Set the Emacs mark at beginning of buffer.
3450@item m >
3451Set the Emacs mark at end of buffer.
3452@item m ,
3453Jump to the Emacs mark.
3454@item :mark <char>
3455Mark position with text marker named <char>. This is an Ex command.
3456@item :k <char>
3457Same as @kbd{:mark}.
3458@item ``
3459Exchange point and mark.
3460@item ''
3461Exchange point and mark and go to the first CHAR on line.
3462@item '<a-z>
3463Go to specified Viper mark.
3464@item
3465Go to specified Viper mark and go to the first CHAR on line.
3466@end table
3467@kindex @kbd{m<a-z>}
3468@kindex @kbd{m.}
3469@kindex @kbd{m>}
3470@kindex @kbd{m<}
3471@kindex @kbd{m,}
3472@kindex @kbd{m^}
3473@findex @kbd{:mark}
3474@findex @kbd{:k}
3475@kindex @kbd{''}
3476@kindex @kbd{``}
3477@kindex @kbd{`<a-z>}
3478@kindex @kbd{'<a-z>}
3479
3480@node Appending Text, Editing in Insert State, Marking,Text Handling
3481@subsection Appending Text
3482
3483@xref{Options}, to see how to change tab and shiftwidth size. See the GNU
3484Emacs manual, or try @kbd{C-ha tabs} (If you have turned Emacs help on).
3485Check out the variable @code{indent-tabs-mode} to put in just spaces.
3486Also see options for word-wrap.
3487
3488@cindex inserting
3489@cindex appending
3490@cindex paste
3491@cindex put
3492
3493@table @kbd
3494@item <count> a
3495<count> times after the cursor.
3496@item <count> A
3497<count> times at the end of line.
3498@item <count> i
3499<count> times before the cursor (insert).
3500@item <count> I
3501<count> times before the first CHAR of the line
3502@item <count> o
3503On a new line below the current (open).
3504The count is only useful on a slow terminal.
3505@item <count> O
3506On a new line above the current.
3507The count is only useful on a slow terminal.
3508@item <count> ><move>
3509Shift the lines described by <count><move> one
3510shiftwidth to the right (layout!).
3511@item <count> >>
3512Shift <count> lines one shiftwidth to the right.
3513@item <count> ["<a-z1-9>]p
3514Put the contents of the (default undo) buffer
3515<count> times after the cursor. The register will
3516be automatically down-cased.
3517@item <count> ["<a-z1-9>]P
3518Put the contents of the (default undo) buffer
3519<count> times before the cursor. The register will
3520@item [<a-z>
3521Show contents of textmarker.
3522@item ]<a-z>
3523Show contents of register.
3524@item <count> .
3525Repeat previous command <count> times. For destructive
3526commands as well as undo.
3527@item f1 1 and f1 2
3528While @kbd{.} repeats the last destructive command,
3529these two macros repeat the second-last and the third-last destructive
3530commands. @xref{Vi Macros}, for more information on Vi macros.
3531@item C-c M-p and C-c M-n
3532In Vi state,
3533these commands help peruse the history of Vi's destructive commands.
3534Successive typing of @kbd{C-c M-p} causes Viper to search the history in
3535the direction
3536of older commands, while hitting @kbd{C-c M-n} does so in reverse
3537order. Each command in the history is displayed in the Minibuffer. The
3538displayed command can
3539then be executed by typing `@kbd{.}'.
3540
3541Since typing the above sequences of keys may be tedious, the
3542functions doing the perusing can be bound to unused keyboard keys in the
3543@file{~/.viper} file. @xref{Viper Specials}, for details.
3544@end table
3545@kindex @kbd{C-c M-p}
3546@kindex @kbd{C-c M-n}
3547@kindex @kbd{.}
3548@kindex @kbd{]<a-z>}
3549@kindex @kbd{[<a-z>}
3550@kindex @kbd{P}
3551@kindex @kbd{p}
3552@kindex @kbd{"<a-z1-9>p}
3553@kindex @kbd{"<a-z1-9>P}
3554@kindex @kbd{>>}
3555@kindex @kbd{><move>}
3556@kindex @kbd{O}
3557@kindex @kbd{o}
3558@kindex @kbd{i}
3559@kindex @kbd{A}
3560@kindex @kbd{a}
3561
3562@node Editing in Insert State, Deleting Text, Appending Text,Text Handling
3563@subsection Editing in Insert State
3564
3565Minibuffer can be edited similarly to Insert state, and you can switch
3566between Insert/Replace/Vi states at will.
3567Some users prefer plain Emacs feel in the Minibuffer. To this end, set
3568@var{viper-vi-style-in-minibuffer} to @code{nil}.
3569
3570@cindex Insert state
3571
3572@table @kbd
3573@item C-v
3574Deprive the next char of its special meaning (quoting).
3575@item C-h
3576One char back.
3577@item C-w
3578One word back.
3579@item C-u
3580Back to the begin of the change on the
3581current line.
3582
3583@end table
3584@kindex @kbd{C-u}
3585@kindex @kbd{C-w}
3586@kindex @kbd{C-v}
3587
3588@node Deleting Text, Changing Text, Editing in Insert State, Text Handling
3589@subsection Deleting Text
3590
3591
3592There is one difference in text deletion that you should be
3593aware of. This difference comes from Emacs and was adopted in Viper
3594because we find it very useful. In Vi, if you delete a line, say, and then
3595another line, these two deletions are separated and are put back
3596separately if you use the @samp{p} command. In Emacs (and Viper), successive
3597series of deletions that are @emph{not interrupted} by other commands are
3598lumped together, so the deleted text gets accumulated and can be put back
3599as one chunk. If you want to break a sequence of deletions so that the
3600newly deleted text could be put back separately from the previously deleted
3601text, you should perform a non-deleting action, e.g., move the cursor one
3602character in any direction.
3603
3604@cindex shifting text
3605
3606@table @kbd
3607@item <count> x
3608Delete <count> chars under and after the cursor.
3609@item <count> X
3610Delete <count> chars before the cursor.
3611@item <count> d<move>
3612Delete from point to endpoint of <count><move>.
3613@item <count> dd
3614Delete <count> lines.
3615@item D
3616The rest of the line.
3617@item <count> <<move>
3618Shift the lines described by <count><move> one
3619shiftwidth to the left (layout!).
3620@item <count> <<
3621Shift <count> lines one shiftwidth to the left.
3622@end table
3623@kindex @kbd{<<}
3624@kindex @kbd{<<move>}
3625@kindex @kbd{D}
3626@kindex @kbd{dd}
3627@kindex @kbd{d<move>}
3628@kindex @kbd{X}
3629@kindex @kbd{x}
3630
3631@node Changing Text, Search and Replace, Deleting Text,Text Handling
3632@subsection Changing Text
3633
3634@cindex joining lines
3635@cindex changing case
3636@cindex quoting regions
3637@cindex substitution
3638
3639@table @kbd
3640@item <count> r<char>
3641Replace <count> chars by <char> - no <esc>.
3642@item <count> R
3643Overwrite the rest of the line,
3644appending change @var{count - 1} times.
3645@item <count> s
3646Substitute <count> chars.
3647@item <count> S
3648Change <count> lines.
3649@item <count> c<move>
3650Change from begin to endpoint of <count><move>.
3651@item <count> cc
3652Change <count> lines.
3653@item <count> C
3654The rest of the line and <count> - 1 next lines.
3655@item <count> =<move>
3656Reindent the region described by move.
3657@item <count> ~
3658Switch lower and upper cases.
3659@item <count> J
3660Join <count> lines (default 2).
3661@item :[x,y]s/<pat>/<repl>/<f>
3662Substitute (on lines x through y) the pattern
3663<pat> (default the last pattern) with <repl>. Useful
3664flags <f> are @samp{g} for @samp{global} (i.e.@: change every
3665non-overlapping occurrence of <pat>) and @samp{c} for
3666@samp{confirm} (type @samp{y} to confirm a particular
3667substitution, else @samp{n} ). Instead of @kbd{/} any
3668punctuation CHAR unequal to <space> <tab> and <lf> can be used as
3669delimiter.
3670
3671In Emacs, @samp{\&} stands for the last matched expression, so
3672@kbd{s/[ab]+/\&\&/} will double the string matched by @kbd{[ab]}.
3673Viper doesn't treat @samp{&} specially, unlike Vi: use @samp{\&} instead.
3674
3675Viper does not parse search patterns and does not expand special symbols
3676found there (e.g., @samp{~} is not expanded to the result of the previous
3677substitution).
3678
3679Note: @emph{The newline character (inserted as @kbd{C-qC-j})
3680can be used in <repl>}.
3681@item :[x,y]copy [z]
3682Copy text between @kbd{x} and @kbd{y} to the position after @kbd{z}.
3683@item :[x,y]t [z]
3684Same as @kbd{:copy}.
3685@item :[x,y]move [z]
3686Move text between @kbd{x} and @kbd{y} to the position after @kbd{z}.
3687@item &
3688Repeat latest Ex substitute command, e.g.
3689@kbd{:s/wrong/right}.
3690@item :x,yp
3691@itemx :g/Pat/p
3692@itemx :v/Pat/p
3693The above commands display certain buffer lines in a
3694temporary buffer. The first form above displays the buffer lines between
3695@kbd{x} and @kbd{y}. The second displays the lines of the buffer, which
3696match a given pattern. The third form displays the lines that do @emph{not}
3697match the given pattern.
3698@item #c<move>
3699Change upper-case characters in the region to lower-case.
3700@item #C<move>
3701Change lower-case characters in the region to upper-case.
3702@item #q<move>
3703Insert specified string at the beginning of each line in the region
3704@item C-c M-p and C-c M-n
3705In Insert and Replace states, these keys are bound to commands that peruse
3706the history of the text
3707previously inserted in other insert or replace commands. By repeatedly typing
3708@kbd{C-c M-p} or @kbd{C-c M-n}, you will cause Viper to
3709insert these previously used strings one by one.
3710When a new string is inserted, the previous one is deleted.
3711
3712In Vi state, these keys are bound to functions that peruse the history of
3713destructive Vi commands.
3714@xref{Viper Specials}, for details.
3715@end table
3716@kindex @kbd{C-c M-p}
3717@kindex @kbd{C-c M-n}
3718@kindex @kbd{#q<move> }
3719@kindex @kbd{#C<move>}
3720@kindex @kbd{#c<move>}
3721@kindex @kbd{&}
3722@kindex @kbd{\&}
3723@findex @kbd{:substitute/<pat>/<repl>/<f>}
3724@findex @kbd{:s/<pat>/<repl>/<f>}
3725@findex @kbd{:copy [z]}
3726@findex @kbd{:t [z]}
3727@findex @kbd{:move [z]}
3728@kindex @kbd{J}
3729@kindex @kbd{~}
3730@kindex @kbd{=<move>}
3731@kindex @kbd{C}
3732@kindex @kbd{cc}
3733@kindex @kbd{c<move>}
3734@kindex @kbd{S}
3735@kindex @kbd{s}
3736@kindex @kbd{R}
3737@kindex @kbd{r<char>}
3738
3739@node Search and Replace, Yanking, Changing Text,Text Handling
3740@subsection Search and Replace
3741
3742@xref{Groundwork}, for Ex address syntax. @xref{Options}, to see how to
3743get literal (non-regular-expression) search and how to stop search from
3744wrapping around.
3745
3746@table @kbd
3747@item C-c /
3748Toggle case-sensitive search. With prefix argument, toggle vanilla/regular
3749expression search.
3750@item <count> /<string>
3751To the <count>th occurrence of <string>.
3752
3753Viper does not parse search patterns and does not expand special symbols
3754found there (e.g., @samp{~} is not expanded to the result of the previous
3755substitution).
3756
3757@item <count> ?<string>
3758To the <count>th previous occurrence of <string>.
3759@item <count> g<move>
3760Search for the text described by move. (off by default)
3761@item n
3762Repeat latest @kbd{/} @kbd{?} (next).
3763@item N
3764Idem in opposite direction.
3765@item %
3766Find the next bracket and go to its match
3767@item :[x,y]g/<string>/<cmd>
3768@cindex text processing
3769Search globally [from line x to y] for <string>
3770and execute the Ex <cmd> on each occurrence.
3771@item :[x,y]v/<string>/<cmd>
3772Execute <cmd> on the lines that don't match.
3773@item #g<move>
3774Execute the last keyboard macro for each line in the region.
3775@xref{Macros and Registers}, for more info.
3776@item Q
3777Query Replace.
3778@item :ta <name>
3779Search in the tags file where <name> is defined (file, line), and go to it.
3780@item :[x,y]s/<pat>/<repl>/<f>
3781Substitute (on lines x through y) the pattern <pat> (default the last
3782pattern) with <repl>. Useful
3783flags <f> are @samp{g} for @samp{global} (i.e.@: change every
3784non-overlapping occurrence of <pat>) and @samp{c} for
3785@samp{confirm} (type @samp{y} to confirm a particular
3786substitution, else @samp{n}). Instead of @kbd{/} any
3787punctuation character other than <space> <tab> and <lf> can be used as
3788delimiter.
3789
3790Note: @emph{The newline character (inserted as @kbd{C-qC-j})
3791can be used in <repl>}.
3792@item &
3793Repeat latest Ex substitute command, e.g.@: @kbd{:s/wrong/right}.
3794@item :global /<pattern>/<ex-command>
3795@itemx :g /<pattern>/<ex-command>
3796Execute <ex-command> on all lines that match <pattern>.
3797@item :vglobal /<pattern>/<ex-command>
3798@itemx :v /<pattern>/<ex-command>
3799Execute <ex-command> on all lines that do not match <pattern>.
3800@end table
3801@kindex @kbd{&}
3802@findex @kbd{:substitute/<pat>/<repl>/<f>}
3803@kindex @kbd{Q}
3804@kindex @kbd{#g<move>}
3805@findex @kbd{:v}
3806@findex @kbd{:g}
3807@findex @kbd{:global}
3808@findex @kbd{:vglobal}
3809@findex @kbd{:tag <name>}
3810@kindex @kbd{%}
3811@kindex @kbd{N}
3812@kindex @kbd{n}
3813@kindex @kbd{g<move>}
3814@kindex @kbd{?<string>}
3815@kindex @kbd{/<string>}
3816
3817@node Yanking,Undoing,Search and Replace,Text Handling
3818@subsection Yanking
3819
3820@cindex cut and paste
3821@cindex paste
3822
3823@table @kbd
3824@item <count> y<move>
3825Yank from begin to endpoint of <count><move>.
3826@item <count> "<a-z>y<move>
3827Yank from begin to endpoint of <count><move> to register.
3828@item <count> "<A-Z>y<move>
3829Yank from begin to endpoint of <count><move> and append
3830to register.
3831@item <count> yy
3832<count> lines.
3833@item <count> Y
3834Idem (should be equivalent to @kbd{y$} though).
3835@item m<a-z>
3836Mark the cursor position with a letter.
3837@item [<a-z>
3838Show contents of textmarker.
3839@item ]<a-z>
3840Show contents of register.
3841@item <count> ["<a-z1-9>]p
3842Put the contents of the (default undo) buffer
3843<count> times after the cursor. The register will
3844be automatically down-cased.
3845@item <count> ["<a-z1-9>]P
3846Put the contents of the (default undo) buffer
3847<count> times before the cursor. The register will
3848@end table
3849@kindex @kbd{P}
3850@kindex @kbd{p}
3851@kindex @kbd{"<a-z1-9>p}
3852@kindex @kbd{"<a-z1-9>P}
3853@kindex @kbd{]<a-z>}
3854@kindex @kbd{[<a-z>}
3855@kindex @kbd{m<a-z>}
3856@kindex @kbd{Y}
3857@kindex @kbd{yy}
3858@kindex @kbd{"<A-Z>y<move>}
3859@kindex @kbd{"<a-z>y<move>}
3860@kindex @kbd{y<move>}
3861@kindex @kbd{yank}
3862@findex @kbd{:yank}
3863
3864@node Undoing,, Yanking,Text Handling
3865@subsection Undoing
3866
3867@cindex undo
3868@cindex backup files
3869
3870@table @kbd
3871@item u U
3872Undo the latest change.
3873@item .
3874Repeat undo.
3875@item :q!
3876Quit Vi without writing.
3877@item :e!
3878Re-edit a messed-up file.
3879@item :rec
3880Recover file from autosave. Viper also creates backup files
3881that have a @samp{~} appended to them.
3882@end table
3883@findex @kbd{:rec}
3884@findex @kbd{:e!}
3885@findex @kbd{:q!}
3886@kindex @kbd{.}
3887@kindex @kbd{U}
3888@kindex @kbd{u}
3889
3890@node Display, File and Buffer Handling, Text Handling, Commands
3891@section Display
3892
3893@cindex scrolling
3894
3895@table @kbd
3896@item C-g
3897At user level 1,
3898give file name, status, current line number
3899and relative position.@*
3900At user levels 2 and higher, abort the current command.
3901@item C-c g
3902Give file name, status, current line number and relative position -- all
3903user levels.
3904@item C-l
3905Refresh the screen.
3906@item <count> C-e
3907Expose <count> more lines at bottom, cursor stays put (if possible).
3908@item <count> C-y
3909Expose <count> more lines at top, cursor stays put (if possible).
3910@item <count> C-d
3911Scroll <count> lines downward (default the number of the previous scroll;
3912initialization: half a page).
3913@item <count> C-u
3914Scroll <count> lines upward (default the number of the previous scroll;
3915initialization: half a page).
3916@item <count> C-f
3917<count> pages forward.
3918@item <count> C-b
3919<count> pages backward (in older versions @kbd{C-b} only works without count).
3920@item <count> z<cr>
3921@item zH
3922Put line <count> at the top of the window (default the current line).
3923@item <count> z-
3924@item zL
3925Put line <count> at the bottom of the window
3926(default the current line).
3927@item <count> z.
3928@item zM
3929Put line <count> in the center of the window
3930(default the current line).
3931@end table
3932@kindex @kbd{zM}
3933@kindex @kbd{zL}
3934@kindex @kbd{zH}
3935@kindex @kbd{z<cr>}
3936@kindex @kbd{z.}
3937@kindex @kbd{z-}
3938@kindex @kbd{z<cr>}
3939@kindex @kbd{C-b}
3940@kindex @kbd{C-f}
3941@kindex @kbd{C-u}
3942@kindex @kbd{C-d}
3943@kindex @kbd{C-y}
3944@kindex @kbd{C-e}
3945@kindex @kbd{C-l}
3946@kindex @kbd{C-g}
3947
3948
3949@node File and Buffer Handling, Mapping, Display,Commands
3950@section File and Buffer Handling
3951
3952@cindex multiple files
3953
3954In all file handling commands, space should be typed before entering the file
3955name. If you need to type a modifier, such as @kbd{>>} or @kbd{!}, don't
3956put any space between the command and the modifier.
3957
3958Note that many Ex commands, e.g., @kbd{:w}, accept command arguments. The
3959effect is that the command would start acting on the current region. For
3960instance, if the current region spans the lines 11 through 22, then if you
3961type @kbd{1:w} you would see @samp{:11,22w} in the minibuffer.
3962
3963@table @kbd
3964@item :q
3965Quit buffer except if modified.
3966@item :q!
3967Quit buffer without checking. In Viper, these two commands
3968are identical. Confirmation is required if exiting modified buffers that
3969visit files.
3970@item :suspend
3971@item :stop
3972Suspend Viper
3973@item :[x,y] w
3974Write the file. Viper makes sure that a final newline is always added to
3975any file where this newline is missing. This is done by setting Emacs
3976variable @code{require-final-newline} to @code{t}. If you don't like this
3977feature, use @code{setq-default} to set @code{require-final-newline} to
3978@code{nil}. This must be done in @file{.viper} file.
3979@item :[x,y] w <name>
3980Write to the file <name>.
3981@item :[x,y] w>> <name>
3982Append the buffer to the file <name>. There should be no space between
3983@kbd{w} and @kbd{>>}. Type space after the @kbd{>>} and see what happens.
3984@item :w!@: <name>
3985Overwrite the file <name>. In Viper, @kbd{:w} and @kbd{:w!} are identical.
3986Confirmation is required for writing to an existing file (if this is not
3987the file the buffer is visiting) or to a read-only file.
3988@item :x,y w <name>
3989Write lines x through y to the file <name>.
3990@item :wq
3991Write the file and kill buffer.
3992@item :r <file> [<file> ...]
3993Read file into a buffer, inserting its contents after the current line.
3994@item :xit
3995Same as @kbd{:wq}.
3996@item :Write
3997@itemx :W
3998Save all unsaved buffers, asking for confirmation.
3999@item :WWrite
4000@itemx :WW
4001Like @kbd{W}, but without asking for confirmation.
4002@item ZZ
4003Save current buffer and kill it. If user level is 1, then save all files
4004and kill Emacs. Killing Emacs is the wrong way to use it, so you should
4005switch to higher user levels as soon as possible.
4006@item :x [<file>]
4007Save and kill buffer.
4008@item :x!@: [<file>]
4009@kbd{:w![<file>]} and @kbd{:q}.
4010@item :pre
4011Preserve the file -- autosave buffers.
4012@item :rec
4013Recover file from autosave.
4014@item :f [<file>]
4015without the argument, prints file name and character/line information afout
4016the currently visited file. With an argument, sets the currently visited
4017filename to @file{file}.
4018@item :cd [<dir>]
4019Set the working directory to <dir> (default home directory).
4020@item :pwd
4021Print present working directory.
4022@item :e [+<cmd>] <files>
4023Edit files. If no filename is given, edit the file visited by the current
4024buffer. If buffer was modified or the file changed on disk, ask for
4025confirmation. Unlike Vi, Viper allows @kbd{:e} to take multiple arguments.
4026The first file is edited the same way as in Vi. The rest are visited
4027in the usual Emacs way.
4028@item :e!@: [+<cmd>] <files>
4029Re-edit file. If no filename, re-edit current file.
4030In Viper, unlike Vi, @kbd{e!} is identical to @kbd{:e}. In both cases, the
4031user is asked to confirm if there is a danger of discarding changes to a
4032buffer.
4033@item :q!
4034Quit Vi without writing.
4035@item C-^
4036Edit the alternate (normally the previous) file.
4037@item :rew
4038Obsolete
4039@item :args
4040List files not shown anywhere with counts for next
4041@item :n [count] [+<cmd>] [<files>]
4042Edit <count> file, or edit files. The count comes from @kbd{:args}.
4043@item :N [count] [+<cmd>] [<files>]
4044Like @kbd{:n}, but the meaning of the variable
4045@var{ex-cycle-other-window} is reversed.
4046@item :b
4047Switch to another buffer. If @var{ex-cycle-other-window} is @code{t},
4048switch in another window. Buffer completion is supported.
4049The variable @var{viper-read-buffer-function} controls which function is
4050actually used to read the buffer name. The default is @code{read-buffer},
4051but better alternatives are also available in Emacs (e.g.,
4052@code{iswitchb-read-buffer}).
4053@vindex @var{viper-read-buffer-function}
4054@item :B
4055Like @kbd{:b}, but the meaning of @var{ex-cycle-other-window} is reversed.
4056@item :<address>r <name>
4057Read the file <name> into the buffer after the line <address>.
4058@item v, V, C-v
4059Edit a file in current or another window, or in another frame. File name
4060is typed in Minibuffer. File completion and history are supported.
4061@end table
4062@kindex @kbd{v}
4063@kindex @kbd{V}
4064@findex @kbd{:args}
4065@findex @kbd{:rew}
4066@kindex @kbd{C-^}
4067@findex @kbd{:e!@: [<files>]}
4068@findex @kbd{:e [<files>]}
4069@findex @kbd{:edit [<files>]}
4070@findex @kbd{:edit!@: [<files>]}
4071@findex @kbd{:q!}
4072@findex @kbd{:q}
4073@findex @kbd{:quit}
4074@findex @kbd{:quit!}
4075@findex @kbd{:f}
4076@findex @kbd{:rec}
4077@findex @kbd{:r}
4078@findex @kbd{:read}
4079@findex @kbd{:pre}
4080@kindex @kbd{ZZ}
4081@findex @kbd{:wq}
4082@findex @kbd{:w <file>}
4083@findex @kbd{:w!@: <file>}
4084@findex @kbd{:w >> <file>}
4085@findex @kbd{:write <file>}
4086@findex @kbd{:write!@: <file>}
4087@findex @kbd{:write >> <file>}
4088@findex @kbd{:W}
4089@findex @kbd{:WW}
4090@findex @kbd{:Write}
4091@findex @kbd{:WWrite}
4092@findex @kbd{:WWrite}
4093@findex @kbd{:x}
4094@findex @kbd{:x!}
4095@findex @kbd{:suspend}
4096@findex @kbd{:stop}
4097@findex @kbd{:n [<count> | <file>]}
4098@findex @kbd{:cd [<dir>]}
4099@findex @kbd{:pwd}
4100
4101@node Mapping, Shell Commands, File and Buffer Handling, Commands
4102@section Mapping
4103
4104@cindex key bindings
4105@cindex key mapping
4106
4107@table @kbd
4108@item :map <string>
4109Start defining a Vi-style keyboard macro.
4110For instance, typing
4111@kbd{:map www} followed by @kbd{:!wc %} and then typing @kbd{C-x )}
4112will cause @kbd{www} to run wc on
4113current file (Vi replaces @samp{%} with the current file name).
4114@item C-x )
4115Finish defining a keyboard macro.
4116In Viper, this command completes the process of defining all keyboard
4117macros, whether they are Emacs-style or Vi-style.
4118This is a departure from Vi, needed to allow WYSIWYG mapping of
4119keyboard macros and to permit the use of function keys and arbitrary Emacs
4120functions in the macros.
4121@item :unmap <string>
4122Deprive <string> of its mappings in Vi state.
4123@item :map!@: <string>
4124Map a macro for Insert state.
4125@item :unmap!@: <string>
4126Deprive <string> of its mapping in Insert state (see @kbd{:unmap}).
4127@item @@<a-z>
4128In Vi state,
4129execute the contents of register as a command.
4130@item @@@@
4131In Vi state,
4132repeat last register command.
4133@item @@#
4134In Vi state,
4135begin keyboard macro. End with @@<a-z>. This will
4136put the macro in the proper register. Register will
4137be automatically down-cased.
4138@xref{Macros and Registers}, for more info.
4139@item @@!<a-z>
4140In Vi state,
4141yank anonymous macro to register
4142@item *
4143In Vi state,
4144execute anonymous macro (defined by C-x( and C-x )).
4145@item C-x e
4146Like @kbd{*}, but works in all Viper states.
4147@item #g<move>
4148Execute the last keyboard macro for each line in the region.
4149@xref{Macros and Registers}, for more info.
4150@item [<a-z>
4151Show contents of textmarker.
4152@item ]<a-z>
4153Show contents of register.
4154@end table
4155@kindex @kbd{]<a-z>}
4156@kindex @kbd{[<a-z>}
4157@kindex @kbd{#g<move>}
4158@kindex @kbd{*}
4159@kindex @kbd{@@!<a-z>}
4160@kindex @kbd{@@#}
4161@kindex @kbd{@@@@}
4162@kindex @kbd{@@<a-z>}
4163@findex @kbd{:unmap <char>}
4164@findex @kbd{:map <char> <seq>}
4165@findex @kbd{:unmap!@: <char>}
4166@findex @kbd{:map!@: <char> <seq>}
4167
4168@node Shell Commands, Options, Mapping, Commands
4169@section Shell Commands
4170
4171@cindex % (Current file)
4172
4173The symbol @samp{%} is used in Ex shell commands to mean current file. If
4174you want a @samp{%} in your command, it must be escaped as @samp{\%}.
4175@cindex @samp{%} (Ex address)
4176However if @samp{%} is the first character, it stands as the address for
4177the whole file.
4178@cindex @samp{#} (Previous file)
4179Similarly, @samp{#} expands to the previous file. The previous file is the
4180first file in @kbd{:args} listing. This defaults to the previous file in
4181the VI sense if you have one window.@refill
4182
4183Symbols @samp{%} and @samp{#} are also used in the Ex commands @kbd{:e} and
4184@kbd{:r <shell-cmd>}. The commands @kbd{:w} and the regular @kbd{:r
4185<file>} command don't support these meta symbols, because file history is a
4186better mechanism.
4187
4188@cindex shell commands
4189
4190@table @kbd
4191@item :sh
4192Execute a subshell in another window
4193@item :[x,y]!<cmd>
4194Execute a shell <cmd> [on lines x through y;
4195% is replace by current file, \% is changed to %
4196@item :[x,y]!!@: [<args>]
4197Repeat last shell command [and append <args>].
4198@item :!<cmd>
4199Just execute command and display result in a buffer.
4200@item :!!@: <args>
4201Repeat last shell command and append <args>
4202@item <count> !<move><cmd>
4203The shell executes <cmd>, with standard
4204input the lines described by <count><move>,
4205next the standard output replaces those lines
4206(think of @samp{cb}, @samp{sort}, @samp{nroff}, etc.).
4207@item <count> !!<cmd>
4208Give <count> lines as standard input to the
4209shell <cmd>, next let the standard output
4210replace those lines.
4211@item :[x,y] w !<cmd>
4212Let lines x to y be standard input for <cmd>
4213(notice the <sp> between @kbd{w} and @kbd{!}).
4214@item :<address>r !<cmd>
4215Put the output of <cmd> after the line <address> (default current).
4216@item :<address>r <name>
4217Read the file <name> into the buffer after the line <address> (default
4218current).
4219@item :make
4220Run the make command in the current directory.
4221@end table
4222@findex @kbd{:<address>r <name>}
4223@findex @kbd{:<address>r !<cmd>}
4224@findex @kbd{!<cmd>}
4225@findex @kbd{!!<cmd>}
4226@findex @kbd{!<move><cmd>}
4227@findex @kbd{:w !<cmd>}
4228@findex @kbd{:x,y w !<cmd>}
4229@findex @kbd{:!!@: <args>}
4230@findex @kbd{:!<cmd>}
4231@findex @kbd{:sh}
4232@findex @kbd{:make}
4233
4234@node Options,Emacs Related Commands,Shell Commands,Commands
4235@section Options
4236
4237@cindex Vi options
4238
4239@table @kbd
4240@item autoindent
4241@itemx ai
4242@cindex autoindent
4243autoindent -- In append mode after a <cr> the
4244cursor will move directly below the first
4245character on the previous line.
4246This setting affects the current buffer only.
4247@item autoindent-global
4248@itemx ai-global
4249Same as `autoindent', but affects all buffers.
4250@item noautoindent
4251@itemx noai
4252Cancel autoindent.
4253@item noautoindent-global
4254@itemx noai-g
4255Cancel autoindent-global.
4256@item ignorecase
4257@itemx ic
4258@cindex case and searching
4259ignorecase -- No distinction between upper and lower cases when searching.
4260@item noignorecase
4261@itemx noic
4262Cancel ignorecase.
4263@item magic
4264@itemx ma
4265@cindex literal searching
4266Regular expressions used in searches; nomagic means no regexps.
4267@item nomagic
4268@item noma
4269Cancel magic.
4270@item readonly
4271@itemx ro
4272@cindex readonly files
4273readonly -- The file is not to be changed.
4274If the user attempts to write to this file, confirmation will be requested.
4275@item noreadonly
4276@itemx noro
4277Cancel readonly.
4278@item shell=<string>
4279@itemx sh=<string>
4280@cindex shell
4281shell -- The program to be used for shell escapes
4282(default @samp{$SHELL} (default @file{/bin/sh})).
4283@item shiftwidth=<count>
4284@itemx sw=<count>
4285@cindex layout
4286@cindex shifting text
4287shiftwidth -- Gives the shiftwidth (default 8 positions).
4288@item showmatch
4289@itemx sm
4290@cindex paren matching
4291@cindex matching parens
4292showmatch -- Whenever you append a @kbd{)}, Vi shows
4293its match if it's on the same page; also with
4294@kbd{@{} and @kbd{@}}. If there's no match, Vi will beep.
4295@item noshowmatch
4296@itemx nosm
4297Cancel showmatch.
4298@item tabstop=<count>
4299@itemx ts=<count>
4300@cindex changing tab width
4301@cindex tabbing
4302tabstop -- The length of a <ht>; warning: this is
4303only IN the editor, outside of it <ht>s have
4304their normal length (default 8 positions).
4305This setting affects the current buffer only.
4306@item tabstop-global
4307@itemx ts-g
4308Same as `tabstop', but affects all buffers.
4309@item wrapmargin=<count>
4310@itemx wm=<count>
4311@cindex auto fill
4312@cindex word wrap
4313wrapmargin -- In append mode Vi automatically
4314puts a <lf> whenever there is a <sp> or <ht>
4315within <wm> columns from the right margin.
4316@item wrapscan
4317@itemx ws
4318@cindex searching
4319wrapscan -- When searching, the end is
4320considered @samp{stuck} to the begin of the file.
4321@item nowrapscan
4322@itemx nows
4323Cancel wrapscan.
4324@item :set <option>
4325Turn <option> on.
4326@item :set no<option>
4327Turn <option> off.
4328@item :set <option>=<value>
4329Set <option> to <value>.
4330@end table
4331@findex @kbd{:set <option>=<value>}
4332@findex @kbd{:set no<option>}
4333@findex @kbd{:set <option>}
4334@findex @kbd{:set ws}
4335@findex @kbd{:set wrapscan}
4336@findex @kbd{:set wm=<count>}
4337@findex @kbd{:set wrapmargin=<count>}
4338@findex @kbd{:set ts=<count>}
4339@findex @kbd{:set tabstop=<count>}
4340@findex @kbd{:set tab-stop-local=<count>}
4341@findex @kbd{:set sm}
4342@findex @kbd{:set showmatch}
4343@findex @kbd{:set sw=<count>}
4344@findex @kbd{:set shiftwidth=<count>}
4345@findex @kbd{:set sh=<string>}
4346@findex @kbd{:set shell=<string>}
4347@findex @kbd{:set ro}
4348@findex @kbd{:set readonly}
4349@findex @kbd{:set magic}
4350@findex @kbd{:set ic}
4351@findex @kbd{:set ignorecase}
4352@findex @kbd{:set ai}
4353@findex @kbd{:set autoindent}
4354
4355@node Emacs Related Commands,,Options,Commands
4356@section Emacs Related Commands
4357
4358@table @kbd
4359@item C-\
4360Begin Meta command in Vi or Insert states. Most often used as C-\ x (M-x).
4361
4362Note: Emacs binds @kbd{C-\} to a function that offers to change the
4363keyboard input method in the multilingual environment. Viper overrides this
4364binding. However, it is still possible to switch the input method by typing
4365@kbd{\ C-\} in the Vi command state and @kbd{C-z \ C-\} in the Insert state.
4366Or you can use the MULE menu on the menubar.
4367@item C-z
4368In Insert and Replace states, prepare Viper to accept the next command and
4369execute it as if Viper was in Vi state. Then return to Insert state.
4370
4371In Vi state, switch to Emacs state; in Emacs state, switch to Vi state.
4372@item C-c \
4373Switches to Vi state for the duration of a single command. Then goes back
4374to the original Viper state. Works from Vi, Insert, Replace, and Emacs states.
4375@item C-x0
4376Close Window
4377@item C-x1
4378Close Other Windows
4379@item C-x2
4380Split Window
4381@item C-xo
4382Move among windows
4383@item C-xC-f
4384Emacs find-file, useful in Insert state
4385@item C-y
4386Put back the last killed text. Similar to Vi's @kbd{p}, but also works in
4387Insert and Replace state. This command doesn't work in Vi command state,
4388since this binding is taken for something else.
4389@item M-y
4390Undoes the last @kbd{C-y} and puts another kill from the kill ring.
4391Using this command, you can try may different kills until you find the one
4392you need.
4393@end table
4394@kindex @kbd{M-y}
4395@kindex @kbd{C-y}
4396@kindex @kbd{C-xC-f}
4397@kindex @kbd{C-xo}
4398@kindex @kbd{C-x2}
4399@kindex @kbd{C-x1}
4400@kindex @kbd{C-x0}
4401@kindex @kbd{C-z}
4402@kindex @kbd{C-\}
4403@kindex @kbd{C-c\}
4404
4405@node Mouse-bound Commands,,,Commands
4406@section Mouse-bound Commands
4407
4408The following two mouse actions are normally bound to special search and
4409insert commands in of Viper:
4410
4411@table @kbd
4412@item S-Mouse-1
4413Holding Shift and clicking mouse button 1 will
4414initiate search for
4415a region under the mouse pointer.
4416This command can take a prefix argument. Note: Viper sets this
4417binding only if this mouse action is not
4418already bound to something else.
4419@xref{Viper Specials}, for more information.@refill
4420
4421@item S-Mouse-2
4422Holding Shift and clicking button 2 of the mouse will
4423insert a region surrounding the mouse pointer.
4424This command can also take a prefix argument.
4425Note: Viper sets this binding only if this mouse action is not
4426already bound to something else.
4427@xref{Viper Specials}, for more details.@refill
4428@end table
4429@kindex @kbd{S-Mouse-1}
4430@kindex @kbd{S-Mouse-2}
4431@kindex @kbd{meta button1up}
4432@kindex @kbd{meta button2up}
4433
4434@node Acknowledgments,,,Top
4435@comment node-name, next, previous, up
4436@unnumbered Acknowledgments
4437
4438Viper, formerly known as VIP-19, was written by Michael Kifer. Viper is
4439based on the original VIP package by Masahiko Sato and on its enhancement,
4440VIP 4.4, by Aamod Sane. This manual is an adaptation of the manual for VIP
44414.4, which, in turn, was based on Sato's manual for VIP 3.5.
4442
4443Many contributors on the Net pointed out bugs and suggested a number of
4444useful features. Scott Bronson and Samuel Padgett contributed patches that
4445were incorporated in this code. Here is a hopefully complete list of
4446contributors:
4447
4448@example
4449aaronl@@vitelus.com (Aaron Lehmann),
4450ahg@@panix.com (Al Gelders),
4451amade@@diagram.fr (Paul-Bernard Amade),
4452ascott@@fws214.intel.com (Andy Scott),
4453bronson@@trestle.com (Scott Bronson),
4454cook@@biostat.wisc.edu (Tom Cook),
4455csdayton@@midway.uchicago.edu (Soren Dayton),
4456dave@@hellgate.utah.edu,
4457dm@@scs.cs.nyu.edu (David Mazieres),
4458dominik@@strw.LeidenUniv.nl (Carsten Dominik),
4459dwallach@@cs.princeton.edu (Dan Wallach),
4460dwight@@toolucky.llnl.gov (Dwight Shih),
4461dxc@@xprt.net (David X Callaway),
4462edmonds@@edmonds.home.cs.ubc.ca (Brian Edmonds),
4463gin@@mo.msk.ru (Golubev I.N.),
4464gviswana@@cs.wisc.edu (Guhan Viswanathan),
4465gvr@@halcyon.com (George V.@: Reilly),
4466hatazaki@@bach.convex.com (Takao Hatazaki),
4467hpz@@ibmhpz.aug.ipp-garching.mpg.de (Hans-Peter Zehrfeld),
4468irie@@t.email.ne.jp (Irie Tetsuya),
4469jackr@@dblues.engr.sgi.com (Jack Repenning),
4470jamesm@@bga.com (D.J.@: Miller II),
4471jjm@@hplb.hpl.hp.com (Jean-Jacques Moreau),
4472jl@@cse.ogi.edu (John Launchbury),
4473jobrien@@hchp.org (John O'Brien),
4474johnw@@borland.com (John Wiegley),
4475kanze@@gabi-soft.fr (James Kanze),
4476kin@@isi.com (Kin Cho),
4477kwzh@@gnu.org (Karl Heuer),
4478lindstro@@biostat.wisc.edu (Mary Lindstrom),
4479lektu@@terra.es (Juanma Barranquero),
4480lennart.borgman.073@@student.lu.se (Lennart Borgman),
4481minakaji@@osaka.email.ne.jp (Mikio Nakajima),
4482Mark.Bordas@@East.Sun.COM (Mark Bordas),
4483meyering@@comco.com (Jim Meyering),
4484martin@@xemacs.org (Martin Buchholz),
4485mbutler@@redfernnetworks.com (Malcolm Butler),
4486mveiga@@dit.upm.es (Marcelino Veiga Tuimil),
4487paulk@@summit.esg.apertus.com (Paul Keusemann),
4488pfister@@cs.stonybrook.edu (Hanspeter Pfister),
4489phil_brooks@@MENTORG.COM (Phil Brooks),
4490pogrell@@informatik.hu-berlin.de (Lutz Pogrell),
4491pradyut@@cs.uchicago.edu (Pradyut Shah),
4492roderick@@argon.org (Roderick Schertler),
4493rxga@@ulysses.att.com,
4494sawdey@@lcse.umn.edu (Aaron Sawdey),
4495simonb@@prl.philips.co.uk (Simon Blanchard),
4496spadgett1@@nc.rr.com (Samuel Padgett),
4497stephen@@farrell.org (Stephen Farrell),
4498storm@@cua.dk (Kim F. Storm),
4499sudish@@MindSpring.COM (Sudish Joseph),
4500schwab@@issan.informatik.uni-dortmund.de (Andreas Schwab)
4501terra@@diku.dk (Morten Welinder),
4502thanh@@informatics.muni.cz (Han The Thanh),
4503toma@@convex.convex.com,
4504vrenjak@@sun1.racal.com (Milan Vrenjak),
4505whicken@@dragon.parasoft.com (Wendell Hicken),
4506zapman@@cc.gatech.edu (Jason Zapman II),
4507@end example
4508
4509@node GNU Free Documentation License,,, Top
4510@appendix GNU Free Documentation License
4511@include doclicense.texi
4512
4513@node Key Index,Function Index,,Top
4514@comment node-name, next, previous, up
4515@unnumbered Key Index
4516
4517@printindex ky
4518
4519@node Function Index,Variable Index,Key Index,Top
4520@comment node-name, next, previous, up
4521@unnumbered Function Index
4522
4523@printindex fn
4524
4525@node Variable Index,Package Index,Function Index,Top
4526@comment node-name, next, previous, up
4527@unnumbered Variable Index
4528
4529@printindex vr
4530
4531@node Package Index,Concept Index,Variable Index,Top
4532@comment node-name, next, previous, up
4533@unnumbered Package Index
4534
4535@printindex pg
4536
4537@node Concept Index,,Package Index,Top
4538@comment node-name, next, previous, up
4539@unnumbered Concept Index
4540
4541@printindex cp
4542
4009494e
GM
4543@bye
4544
4545@ignore
4546 arch-tag: f53e866a-15cf-4b1e-aead-77da9da1e864
4547@end ignore