% -*-texinfo-*-\input texinfo@comment Using viper.info instead of viper in setfilename breaks DOS.@comment @setfilename viper@comment @setfilename viper.info@setfilename ../info/viper@copyingCopyright @copyright{} 1995, 1996, 1997, 2001, 2002, 2003, 2004,2005, 2006 Free Software Foundation, Inc.@quotationPermission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.2 orany later version published by the Free Software Foundation; with noInvariant Sections, with the Front-Cover texts being ``A GNUManual'', and with the Back-Cover Texts as in (a) below. A copy of thelicense is included in the section entitled ``GNU Free DocumentationLicense'' in the Emacs manual.(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modifythis GNU Manual, like GNU software. Copies published by the FreeSoftware Foundation raise funds for GNU development.''This document is part of a collection distributed under the GNU FreeDocumentation License. If you want to distribute this documentseparately from the collection, you can do so by adding a copy of thelicense to the document, as described in section 6 of the license.@end quotation@end copying@dircategory Emacs@direntry* VIPER: (viper). The newest Emacs VI-emulation mode. (also, A VI Plan for Emacs Rescue or the VI PERil.)@end direntry@finalout@titlepage@title Viper Is a Package for Emacs Rebels@subtitle a Vi emulator for Emacs@subtitle January 2002, Viper Version 3.11.2@author Michael Kifer (Viper)@author Aamod Sane (VIP 4.4)@author Masahiko Sato (VIP 3.5)@page@vskip 0pt plus 1filll@insertcopying@end titlepage@ifnottex@node Top, Overview,, (DIR)@unnumbered ViperWe believe that one or more of the following statements are adequatedescriptions of Viper:@exampleViper Is a Package for Emacs Rebels;it is a VI Plan for Emacs Rescueand/or a venomous VI PERil.@end exampleTechnically speaking, Viper is a Vi emulation package for Emacs. Itimplements all Vi and Ex commands, occasionally improving on them andadding many new features. It gives the user the best of both worlds: Vikeystrokes for editing combined with the power of the Emacs environment.Viper emulates Vi at several levels, from the one that closely follows Viconventions to the one that departs from many of them. It has manycustomizable options, which can be used to tailor Viper to the work habitsof various users.This manual describes Viper, concentrating on the differences from Vi andnew features of Viper.Viper, formerly known as VIP-19, was written by Michael Kifer. It is basedon VIP version 3.5 by Masahiko Sato and VIP version 4.4 by Aamod Sane.About 15% of the code still comes from those older packages.Viper is intended to be usable without reading this manual --- the defaultsare set to make Viper as close to Vi as possible. At startup, Viper willtry to set the most appropriate default environment for you, based onyour familiarity with Emacs. It will also tell you the basic GNU Emacs windowmanagement commands to help you start immediately.Although this manual explains how to customize Viper, some basicfamiliarity with Emacs Lisp is a plus.It is recommended that you read the Overview node. The other nodes maybe visited as needed.Comments and bug reports are welcome.@code{kifer@@cs.stonybrook.edu} is the current address for Viper bug reports.Please use the Ex command @kbd{:submitReport} for this purpose.@refill@end ifnottex@menu* Overview:: Read for a smoother start* Improvements over Vi:: New features, Improvements* Customization:: How to customize Viper* Commands:: Vi and Ex Commands* Key Index:: Index of Vi and Ex Commands* Function Index:: Index of Viper Functions* Variable Index:: Index of Viper Variables* Package Index:: Index of Packages Mentioned in this Document* Concept Index:: Vi, Ex and Emacs concepts* Acknowledgments::@end menu@iftex@unnumbered IntroductionWe believe that one or more of the following statements are adequatedescriptions of Viper:@exampleViper Is a Package for Emacs Rebels;it is a VI Plan for Emacs Rescueand/or a venomous VI PERil.@end exampleViper is a Vi emulation package for Emacs. Viper contains virtually allof Vi and Ex functionality and much more. It gives you the best of bothworlds: Vi keystrokes for editing combined with the GNU Emacsenvironment. Viper also fixes some common complaints with Vi commands.This manual describes Viper, concentrating on the differences from Viand on the new features of Viper.Viper was written by Michael Kifer. It is based on VIP version 3.5 byMasahiko Sato and VIP version 4.4 by Aamod Sane. About 15% of the codestill comes from those older packages.Viper is intended to be usable out of the box, without reading this manual--- the defaults are set to make Viper as close to Vi as possible. Atstartup, Viper will attempt to set the most appropriate default environmentfor you, based on your familiarity with Emacs. It will also tell you thebasic GNU Emacs window management commands to help you start immediately.Although this manual explains how to customize Viper, some basicfamiliarity with Emacs Lisp is a plus.It is recommended that you read the chapter Overview. The other chapterswill be useful for customization and advanced usage.You should also learn to use the Info on-line hypertext manual system thatcomes with Emacs. This manual can be read as an Info file. Try the command@kbd{@key{ESC} x info} with vanilla Emacs sometime.Comments and bug reports are welcome.@code{kifer@@cs.stonybrook.edu} is the current address for Viper bug reports.Please use the Ex command @kbd{:submitReport} for this purpose.@refill@end iftex@node Overview,Improvements over Vi,Top,Top@chapter Overview of ViperViper is a Vi emulation on top of Emacs. At the same time, Viper provides avirtually unrestricted access to Emacs facilities. Perfect compatibilitywith Vi is possible but not desirable. This chapter tells you about theEmacs ideas that you should know about, how to use Viper within Emacs andsome incompatibilities.This manual is written with the assumption that you are an experienced Viuser who wants to switch to Emacs while retaining the ability to edit filesVi style. Incredible as it might seem, there are experienced Emacs userswho use Viper as a backdoor into the superior (as every Vi user already knows)world of Vi! These users are well familiar with Emacs bindings and prefer themin some cases, especially in the Vi Insert state. John Hawkins<jshawkin@@eecs.umich.edu> has provided a set of customizations, whichenables additional Emacs bindings under Viper. These customizations can beincluded in your @file{~/.viper} file and are found at the following URL:@file{http://traeki.freeshell.org/files/viper-sample}.@menu* Emacs Preliminaries:: Basic concepts in Emacs.* Loading Viper:: Loading and Preliminary Configuration.* States in Viper:: Viper has four states orthogonal to Emacs modes.* The Minibuffer:: Command line in Emacs.* Multiple Files in Viper:: True multiple file handling.* Unimplemented Features:: That are unlikely to be implemented.@end menu@node Emacs Preliminaries, Loading Viper, Overview, Overview@section Emacs Preliminaries@cindex buffer@cindex point@cindex mark@cindex text@cindex looking at@cindex end (of buffer)@cindex end (of line)@cindex regionEmacs can edit several files at once. A file in Emacs is placed in a@dfn{buffer} that usually has the same name as the file. Buffers are also usedfor other purposes, such as shell interfaces, directory editing, etc.@xref{Dired,,Directory Editor,emacs,TheGNU Emacs Manual}, for an example.@refillA buffer has a distinguished position called the @dfn{point}.A @dfn{point} is always between 2 characters, and is @dfn{looking at}the right hand character. The cursor is positioned on the right handcharacter. Thus, when the @dfn{point} is looking at the end-of-line,the cursor is on the end-of-line character, i.e.@: beyond the lastcharacter on the line. This is the default Emacs behavior.@refillThe default settings of Viper try to mimic the behavior of Vi, preventingthe cursor from going beyond the last character on the line. By usingEmacs commands directly (such as those bound to arrow keys), it is possibleto get the cursor beyond the end-of-line. However, this won't (orshouldn't) happen if you restrict yourself to standard Vi keys, unless youmodify the default editing style. @xref{Customization}.@refillIn addition to the @dfn{point}, there is another distinguished bufferposition called the @dfn{mark}. @xref{Mark,,Mark,emacs,The GNU Emacsmanual}, for more info on the mark. The text between the @dfn{point} andthe @dfn{mark} is called the @dfn{region} of the buffer. For the Viperuser, this simply means that in addition to the Vi textmarkers a--z, thereis another marker called @dfn{mark}. This is similar to the unnamed Vimarker used by the jump commands @kbd{``} and @kbd{''}, which move thecursor to the position of the last absolute jump. Viper provides access tothe region in most text manipulation commands as @kbd{r} and @kbd{R} suffixto commands that operate on text regions, e.g., @kbd{dr} to delete region,etc.Furthermore, Viper lets Ex-style commands to work on the current region.This is done by typing a digit argument before @kbd{:}. For instance,typing @kbd{1:} will prompt you with something like @emph{:123,135},assuming that the current region starts at line 123 and ends at line135. There is no need to type the line numbers, since Viper inserts themautomatically in front of the Ex command.@xref{Basics}, for more info.@refill@cindex window@cindex mode line@cindex buffer information@cindex Minibuffer@cindex command line@cindex buffer (modified)Emacs divides the screen into tiled @dfn{windows}. You can see thecontents of a buffer through the window associated with the buffer. Thecursor of the screen is positioned on the character after @dfn{point}.Every window has a @dfn{mode line} that displays information about the buffer.You can change the format of the modeline, but normally if you see @samp{**} at the beginning of a mode line itmeans that the buffer is @dfn{modified}. If you write out the contents ofa buffer to a file, then the buffer will become not modified. Also ifyou see @samp{%%} at the beginning of the mode line, it means that the fileassociated with the buffer is write protected. The mode line will alsoshow the buffer name and current major and minor modes (see below).A special buffer called @dfn{Minibuffer} is displayed as the last linein a Minibuffer window. The Minibuffer window is used for command inputoutput. Viper uses Minibuffer window for @kbd{/} and @kbd{:}commands.@refill@cindex mode@cindex keymap@cindex local keymap@cindex global keymap@cindex major mode@cindex minor modeAn Emacs buffer can have a @dfn{major mode} that customizes Emacs forediting text of a particular sort by changing the functionality of the keys.Keys are defined using a @dfn{keymap} that records the bindings betweenkeystrokes andfunctions. The @dfn{global keymap} is common to all thebuffers. Additionally, each buffer has its @dfn{local keymap} that determines the@dfn{mode} of the buffer. If a function is bound to some key in the localkeymap then that function will be executed when you type the key.If no function is bound to a key in thelocal map, however, the function bound to the key in the global mapwill be executed. @xref{Major Modes,Major Modes,Major Modes,emacs,TheGNU Emacs Manual}, for more information.@refillA buffer can also have a @dfn{minor mode}. Minor modes are options thatyou can use or not. A buffer in @code{text-mode} can have@code{auto-fill-mode} as minor mode, which can be turned off or on atany time. In Emacs, a minor mode may have it own keymap,which overrides the local keymap when the minor mode is turned on. Formore information, @pxref{Minor Modes,Minor Modes,Minor Modes,emacs,TheGNU Emacs Manual} @refill@cindex Viper as minor mode@cindex Control keys@cindex Meta keyViper is implemented as a collection of minor modes. Different minor modesare involved when Viper emulates Vi command mode, Vi insert mode, etc.You can also turn Viper on and off at any time while in Vi command mode.@xref{States in Viper}, formore information.@refillEmacs uses Control and Meta modifiers. These are denoted as C and M,e.g.@: @kbd{^Z} as @kbd{C-z} and @kbd{Meta-x} as @kbd{M-x}. The Meta key isusually located on each side of the Space bar; it is used in a mannersimilar to the Control key, e.g., @kbd{M-x} means typing @kbd{x} whileholding the Meta key down. For keyboards that do not have a Meta key,@key{ESC} is used as Meta. Thus @kbd{M-x} is typed as @kbd{@key{ESC}x}. Viper uses @key{ESC} to switch from Insert state to Vi state. ThereforeViper defines @kbd{C-\} as its Meta key in Vi state. @xref{Vi State}, formore info.@refillEmacs is structured as a Lisp interpreter around a C core. Emacs keyscause Lisp functions to be called. It is possible to call thesefunctions directly, by typing @kbd{M-x function-name}.@node Loading Viper, States in Viper, Emacs Preliminaries, Overview@section Loading ViperThe most common way to load it automatically is to include the followinglines (in the given order!):@lisp(setq viper-mode t)(require 'viper)@end lisp@noindentin your @file{~/.emacs} file. The @file{.emacs} file is placed in yourhome directory and it is be executed every time you invoke Emacs. This isthe place where all general Emacs customization takes place. Beginning withversion 20.0, Emacsen have an interactive interface, which simplifies thejob of customization significantly.Viper also uses the file @file{~/.viper} for Viper-specific customization.The location of Viper customization file can be changed by setting thevariable @code{viper-custom-file-name} in @file{.emacs} @emph{prior} to loadingViper.The latest versions of Emacs have an interactive customization facility,which allows you to (mostly) bypass the use of the @file{.emacs} and@file{.viper} files. You can reach this customizationfacility from within Viper's VI state by executing the Ex command@kbd{:customize}.Once invoked, Viper will arrange to bring up Emacs buffers in Vi statewhenever this makes sense.@xref{Packages that Change Keymaps}, to find out when forcing Vi command stateon a buffer may be counter-productive.Even if your @file{.emacs} file does not invoke Viper automatically,you can still load Viper and enter the Vi command state by typing thefollowing from within Emacs:@lispM-x viper-mode@end lispWhen Emacs first comes up, if you have not specified a file on thecommand line, it will show the @samp{*scratch*} buffer, in the@samp{Lisp Interaction} mode. After you invoke Viper, you can startediting files by using @kbd{:e}, @kbd{:vi}, or @kbd{v} commands.(@xref{File and Buffer Handling}, for more information on @kbd{v} and othernew commands that, in many cases, are more convenient than @kbd{:e},@kbd{:vi}, and similar old-style Vi commands.)@refillFinally, if at some point you would want to de-Viperize your runningcopy of Emacs after Viper has been loaded, the command @kbd{M-xviper-go-away} will do it for you. The function @code{toggle-viper-mode}toggles Viperization of Emacs on and off.@node States in Viper, The Minibuffer, Loading Viper,Overview@section States in Viper@kindex @kbd{C-z}@kindex @key{ESC}@kindex @kbd{i}@cindex Emacs state@cindex Vi state@cindex Insert state@cindex Replace state@cindex Ex commands@findex @code{viper-go-away}@findex @code{toggle-viper-mode}Viper has four states, Emacs, Vi, Insert, and Replace.@table @samp@item Emacs stateThis is the state plain vanilla Emacs is normally in. After you have loadedViper, @kbd{C-z} will normally take you to Vi command state. Another@kbd{C-z} will take you back to Emacs state. This toggle key can bechanged, @pxref{Customization} You can also type @kbd{M-x viper-mode} tochange to Vi state.@refillFor users who chose to set their user level to 1 at Viper setup time,switching to Emacs state is deliberately made harder in order to notconfuse the novice user. In this case, @kbd{C-z} will either iconify Emacs(if Emacs runs as an application under X) or it will stop Emacs (ifEmacs runs on a dumb terminal or in an Xterm window).@item Vi stateThis is the Vi command mode. Any of the Vi commands, such as @kbd{i, o, a},@dots{}, will take you to Insert state. All Vi commands maybe used in this mode. Most Ex commands can also be used.For a full list of Ex commands supported by Viper, type@kbd{:} and then @key{TAB}. To get help on any issue, including the Excommands, type @kbd{:help}. This will invoke Viper Info(if it is installed). Then typing @kbd{i} will prompt you for a topic tosearch in the index. Note: to search for Ex commands in the index, youshould start them with a @kbd{:}, e.g., @kbd{:WW}.In Viper, Ex commands can be made to work on the current Emacs region.This is done by typing a digit argument before @kbd{:}.For instance, typing @kbd{1:} will prompt you with something like@emph{:123,135}, assuming that the current region starts at line 123 andends at line 135. There is no need to type the line numbers, since Viperinserts them automatically in front of the Ex command.@item Insert stateInsert state is the Vi insertion mode. @key{ESC} will take you back toVi state. Insert state editing can be done, including auto-indentation. Bydefault, Viper disables Emacs key bindings in Insert state.@item Replace stateCommands like @kbd{cw} invoke the Replace state. When you cross theboundary of a replacement region (usually designated via a @samp{$} sign),it will automatically change to Insert state. You do not have to worryabout it. The key bindings remain practically the same as in Insertstate. If you type @key{ESC}, Viper will switch to Vi command mode, terminating thereplacement state.@refill@end table@cindex mode lineThe modes are indicated on the @dfn{mode line} as <E>, <I>, <V>, and <R>,so that the multiple modes do not confuse you. Most of your editing can bedone in Vi and Insert states. Viper will try to make all new buffers be in Vistate, but sometimes they may come up in Emacs state. @kbd{C-z}will take you to Vi state in such a case. In some major modes, like Dired,Info, Gnus, etc., you should not switch to Vi state (and Viper will notattempt to do so) because these modes are not intended for text editing andmany of the Vi keys have special meaning there. If you plan to read news,browse directories, read mail, etc., from Emacs (which you should startdoing soon!), you should learn about the meaning of the various keys inthose special modes (typing @kbd{C-h m} in a buffer provideshelp with key bindings for the major mode of that buffer).If you switch to Vi in Dired or similar modes---no harm is done. It is justthat the special key bindings provided by those modes will be temporarilyovershadowed by Viper's bindings. Switching back to Viper's Emacs statewill revive the environment provided by the current major mode.States in Viper are orthogonal to Emacs major modes, such as C mode or Diredmode. You can turn Viper on and off for any Emacs state. When Viper is turnedon, Vi state can be used to move around. In Insert state, the bindings forthese modes can be accessed. For beginners (users at Viper levels 1 and 2),these bindings are suppressed in Insert state, so that new users are notconfused by the Emacs states. Note that unless you allow Emacs bindings inInsert state, you cannot do many interesting things, like languagesensitive editing. For the novice user (at Viper level 1), all major modebindings are turned off in Vi state as well. This includes the bindings forkey sequences that start with @kbd{C-c}, which practically means that allmajor mode bindings are unsupported. @xref{Customization}, to find out howto allow Emacs keys in Insert state.@menu* Emacs State:: This is the state you should learn more about when you get up to speed with Viper.* Vi State:: Vi commands are executed in this state.* Insert State:: You can enter text, and also can do sophisticated editing if you know enough Emacs commands.* Replace State:: Like Insert mode, but it is invoked via the replacement commands, such as cw, C, R, etc.@end menu@node Emacs State, Vi State, States in Viper, States in Viper@subsection Emacs State@kindex @kbd{C-z}@cindex Emacs stateYou will be in this mode only by accident (hopefully). This is the stateEmacs is normally in (imagine!!). Now leave it as soon as possible bytyping @kbd{C-z}. Then you will be in Vi state (sigh of relief) :-).Emacs state is actually a Viperism to denote all the major and minor modes(@pxref{Emacs Preliminaries}) other than Viper that Emacs can be in. Emacscan have several modes, such as C mode for editing C programs, LaTeX modefor editing LaTeX documents, Dired for directory editing, etc. These aremajor modes, each with a different set of key-bindings. Viper states areorthogonal to these Emacs major modes. The presence of these languagesensitive and other modes is a major win over Vi. @xref{Improvements overVi}, for more.@refillThe bindings for these modes can be made available in the Viper Insert stateas well as in Emacs state. Unless you specify your user level as 1 (anovice), all major mode key sequences that start with @kbd{C-x} and@kbd{C-c} are also available in Vi state. This is important because majormodes designed for editing files, such as cc-mode or latex-mode, use keysequences that begin with @kbd{C-x} and @kbd{C-c}.There is also a key that lets you temporarily escape to Vi command statefrom the Insert state: typing @kbd{C-z} will let you execute asingle Vi command while staying in Viper's Insert state.@node Vi State, Insert State, Emacs State, States in Viper@subsection Vi State@cindex Vi stateThis is the Vi command mode. When Viper is in Vi state, you will see the sign<V> in the mode line. Most keys will work as in Vi. The notableexceptions are:@table @kbd@item C-x@kindex @kbd{C-x}@kbd{C-x} is used to invoke Emacs commands, mainly those that do windowmanagement. @kbd{C-x 2} will split a window, @kbd{C-x 0} will close awindow. @kbd{C-x 1} will close all other windows. @kbd{C-xb} is used toswitch buffers in a window, and @kbd{C-xo} to move through windows.These are about the only necessary keystrokes.For the rest, see the GNU Emacs Manual.@item C-c@kindex @kbd{C-c}For user levels 2 and higher, this key serves as a prefix key for the keysequences used by various major modes. For users at Viper level 1, @kbd{C-c}simply beeps.@item C-g and C-]@kindex @kbd{C-g}@kindex @kbd{C-]}These are the Emacs @samp{quit} keys.There will be cases where you will have touse @kbd{C-g} to quit. Similarly, @kbd{C-]} is used to exit@samp{Recursive Edits} in Emacs for which there is no comparable Vifunctionality and no key-binding. Recursive edits are indicated by@samp{[]} brackets framing the modes on the mode line.@xref{Recursive Edit,RecursiveEdit,Recursive Edit,emacs,The GNU Emacs Manual}.At user level 1, @kbd{C-g} is bound to @code{viper-info-on-file}function instead.@refill@item C-\@kindex @kbd{C-\}@cindex Meta keyViper uses @key{ESC} as a switch between Insert and Vi states. Emacs uses@key{ESC} for Meta. The Meta key is very important in Emacs since manyfunctions are accessible only via that key as @kbd{M-x function-name}.Therefore, we need to simulate it somehow. In Viper's Vi, Insert, andReplace states, the meta key is set to be @kbd{C-\}. Thus, to get@kbd{M-x}, you should type @kbd{C-\ x} (if the keyboard has no Meta key,which is rare these days).This works both in the Vi command state and in the Insert and Replacestates. In Vi command state, you can also use @kbd{\ @key{ESC}} as themeta key.Note: Emacs binds @kbd{C-\} to a function that offers to change thekeyboard input method in the multilingual environment. Viper overrides thisbinding. However, it is still possible to switch the input method by typing@kbd{\ C-\} in the Vi command state and @kbd{C-z \ C-\} in the Insert state.Or you can use the MULE menu in the menubar.@end table@noindentOther differences are mostly improvements. The ones you should knowabout are:@table @samp@item Undo@kindex @kbd{u}@kbd{u} will undo. Undo can be repeated by the @kbd{.} key. Undo itselfcan be undone. Another @kbd{u} will change the direction. The presenceof repeatable undo means that @kbd{U}, undoing lines, is not veryimportant. Therefore, @kbd{U} also calls @code{viper-undo}.@cindex multiple undo@cindex undo@item CountsMost commands, @kbd{~}, @kbd{[[}, @kbd{p}, @kbd{/}, @dots{}, etc., take counts.@comment ]] Just to balance parens@item RegexpsViper uses Emacs Regular Expressions for searches. These are a superset ofVi regularexpressions, excepting the change-of-case escapes @samp{\u}, @samp{\L},@dots{}, etc. @xref{Regexps,,Syntax of Regular Expressions,emacs,TheGNU Emacs Manual}, for details.Files specified to @kbd{:e} use @code{csh} regular expressions(globbing, wildcards, what have you).However, the function @code{viper-toggle-search-style}, bound to @kbd{C-c /},lets the user switch from search with regular expressions to plain vanillasearch and vice versa. It also lets one switch from case-sensitive searchto case-insensitive and back.@xref{Viper Specials}, for more details.@cindex regular expressions@cindex vanilla search@cindex case-sensitive search@cindex case-insensitive search@kindex @kbd{C-c /}@item Ex commands@cindex Ex commandsThe current working directory of a buffer is automatically inserted in theminibuffer if you type @kbd{:e} then space. Absolute filenames arerequired less often in Viper. For file names, Emacs uses a convention thatis slightly different from other programs. It is designed to minimize theneed for deleting file names that Emacs provides in its prompts. (This isusually convenient, but occasionally the prompt may suggest a wrong filename for you.) If you see a prompt @kbd{/usr/foo/} and you wish to edit thefile @kbd{~/.viper}, you don't have to erase the prompt. Instead, simplycontinue typing what you need. Emacs will interpret @kbd{/usr/foo/~/.viper}correctly. Similarly, if the prompt is @kbd{~/foo/} and you need to get to@kbd{/bar/file}, keep typing. Emacs interprets @kbd{~/foo//bar/} as@kbd{/bar/file}, since when it sees @samp{//}, it understands that@kbd{~/foo/} is to be discarded.The command @kbd{:cd} will change the default directory for thecurrent buffer. The command @kbd{:e} will interpret thefilename argument in @code{csh}. @xref{Customization}, if youwant to change the default shell.The command @kbd{:next} takes counts from@kbd{:args}, so that @kbd{:rew} is obsolete. Also, @kbd{:args} will show onlythe invisible files (i.e., those that are not currently seen in Emacswindows).When applicable, Ex commands support file completion and history. Thismeans that by typing a partial file name and then @key{TAB}, Emacs will tryto complete the name or it will offer a menu of possible completions.This works similarly to Tcsh and extends the behavior of Csh. While Emacsis waiting for a file name, you can type @kbd{M-p} to get the previous filename you typed. Repeatedly typing @kbd{M-p} and @kbd{M-n} will let youbrowse through the file history.Like file names, partially typed Ex commands can be completed by typing@key{TAB}, and Viper keeps the history of Ex commands. After typing@kbd{:}, you can browse through the previously entered Ex commands bytyping @kbd{M-p} and @kbd{M-n}. Viper tries to rationalize when it puts Excommands on the history list. For instance, if you typed @kbd{:w!@: foo},only @kbd{:w!} will be placed on the history list. This is because thelast history element is the default that can be invoked simply by typing@kbd{: @key{RET}}. If @kbd{:w!@: foo} were placed on the list, it would be all toeasy to override valuable data in another file. Reconstructing the fullcommand, @kbd{:w!@: foo}, from the history is still not that hard, since Viperhas a separate history for file names. By typing @kbd{: M-p}, you will get@kbd{:w!} in the Minibuffer. Then, repeated @kbd{M-p} will get you throughthe file history, inserting one file name after another.In contrast to @kbd{:w!@: foo}, if the command were @kbd{:r foo}, the entirecommand will appear in the history list. This is because having @kbd{:r}alone as a default is meaningless, since this command requires a fileargument.@refill@end table@noindentAs Vi, Viper's destructive commands can be re-executed by typing `@kbd{.}'.However, in addition, Viper keeps track of the history of such commands. Thishistory can be perused by typing @kbd{C-c M-p} and @kbd{C-c M-n}.Having found the appropriate command, it can be then executed by typing`@kbd{.}'.@xref{Improvements over Vi}, for more information.@node Insert State, Replace State, Vi State, States in Viper@subsection Insert State@cindex Insert stateTo avoid confusing the beginner (at Viper level 1 and 2), Viper makes only thestandard Vi keys available in Insert state. The implication is thatEmacs major modes cannot be used in Insert state.It is strongly recommended that as soon as you are comfortable, make theEmacs state bindings visible (by changing your user level to 3 or higher).@xref{Customization},to see how to do this.@refillOnce this is done, it is possible to do quite a bit of editing inInsert state. For instance, Emacs has a @dfn{yank} command, @kbd{C-y},which is similar to Vi's @kbd{p}. However, unlike @kbd{p}, @kbd{C-y} can beused in Insert state of Viper. Emacs also has a kill ring where it keepspieces of text you deleted while editing buffers. The command @kbd{M-y} isused to delete the text previously put back by Emacs' @kbd{C-y} or by Vi's@kbd{p} command and reinsert text that was placed on the kill-ring earlier.This works both in Vi and Insert states.In Vi state, @kbd{M-y} is a much better alternative to the usual Vi's wayof recovering the 10 previously deleted chunks of text. In Insert state,you canuse this as follows. Suppose you deleted a piece of text and now you needto re-insert it while editing in Insert mode. The key @kbd{C-y} will putback the most recently deleted chunk. If this is not what you want, type@kbd{M-y} repeatedly and, hopefully, you will find the chunk you want.Finally, in Insert and Replace states, Viper provides the history ofpieces of text inserted in previous insert or replace commands. Thesestrings of text can be recovered by repeatedly typing @kbd{C-c M-p} or@kbd{C-c M-n} while in Insert or Replace state. (This feature is disabledin the minibuffer: the above keys are usually bound to other histories,which are more appropriate in the minibuffer.)@cindex Meta keyYou can call Meta functions from Insert state. As in Vi state, the Meta keyis @kbd{C-\}. Thus @kbd{M-x} is typed as @kbd{C-\ x}.Other Emacs commands that are useful in Insert state are @kbd{C-e}and @kbd{C-a}, which move the cursor to the end and the beginning of thecurrent line, respectively. You can also use @kbd{M-f} and @kbd{M-b},which move the cursor forward (or backward) one word.If your display has a Meta key, these functions are invoked by holding theMeta key and then typing @kbd{f} and @kbd{b}, respectively. On displayswithout the Meta key, these functions are invoked by typing@kbd{C-\ f} and @kbd{C-\ b} (@kbd{C-\} simulates the Meta key in Insertstate, as explained above).The key @kbd{C-z} is sometimes also useful in Insert state: it allows youto execute a single command in Vi state without leaving the Insert state!For instance, @kbd{C-z d2w} will delete the next two words without leavingthe Insert state.When Viper is in Insert state, you will see <I> in the mode line.@node Replace State,, Insert State, States in Viper@subsection Replace State@cindex Replace stateThis state is entered through Vi replacement commands, such as @kbd{C},@kbd{cw}, etc., or by typing @kbd{R}. In Replace state, Viper puts <R> inthe mode line to let you know which state is in effect. If Replace state isentered through @kbd{R}, Viper stays in that state until the user hits@key{ESC}. If this state is entered via the other replacement commands,then Replace state is in effect until you hit @key{ESC} or until you crossthe rightmost boundary of the replacement region. In the latter case, Viperchanges its state from Replace to Insert (which you will notice by thechange in the mode line).Since Viper runs under Emacs, it is possible to switch between bufferswhile in Replace state. You can also move the cursor using the arrow keys(even on dumb terminals!)@: and the mouse. Because of this freedom (which isunattainable in regular Vi), it is possible to take the cursor outside thereplacement region. (This may be necessary for several reasons, includingthe need to enable text selection and region-setting with the mouse.)The issue then arises as to what to do when the userhits the @key{ESC} key. In Vi, this would cause the text between cursor andthe end of the replacement region to be deleted. But what if, as ispossible in Viper, the cursor is not inside the replacement region?To solve the problem, Viper keeps track of the last cursor position while itwas still inside the replacement region. So, in the above situation, Viperwould delete text between this position and the end of the replacementregion.@node The Minibuffer,Multiple Files in Viper, States in Viper, Overview@section The Minibuffer@cindex MinibufferThe Minibuffer is where commands are entered in. Editing can be doneby commands from Insert state, namely:@table @kbd@item C-hBackspace@item C-wDelete Word@item C-uErase line@item C-vQuote the following character@item @key{RET}Execute command@item C-g and C-]Emacs quit and abort keys. These may be necessary. @xref{Vi State}, for anexplanation.@item M-p and M-nThese keys are bound to functions that peruse minibuffer history. Theprecise history to be perused depends on the context. It may be the historyof search strings, Ex commands, file names, etc.@end tableMost of the Emacs keys are functional in the Minibuffer. While in theMinibuffer, Viper tries to make editing resemble Vi's behavior when thelatter is waiting for the user to type an Ex command. In particular, youcan use the regular Vi commands to edit the Minibuffer. You can switchbetween the Vi state and Insert state at will, and even use the replace mode.Initially, the Minibuffer comes up in Insert state.Some users prefer plain Emacs bindings in the Minibuffer. To this end, set@code{viper-vi-style-in-minibuffer} to @code{nil} in @file{.viper}.@xref{Customization}, to learn how to do this.When the Minibuffer changes Viper states, you will notice that the appearanceof the text there changes as well. This is useful because the Minibufferhas no mode line to tell which Vi state it is in.The appearance of the text in the Minibuffer can be changed.@xref{Viper Specials}, for more details.@node Multiple Files in Viper,Unimplemented Features,The Minibuffer,Overview@section Multiple Files in Viper@cindex multiple files@cindex managing multiple filesViper can edit multiple files. This means, for example that you never needto suffer through @code{No write since last change} errors.Some Viper elements are common over all the files.@table @samp@item Textmarkers@cindex markers@cindex textmarkersTextmarkers remember @emph{files and positions}.If you set marker @samp{a} infile @file{foo}, start editing file @file{bar} and type @kbd{'a}, then@emph{YOU WILL SWITCH TO FILE @file{foo}}. You can see the contents of atextmarker using the Viper command @kbd{[<a-z>} where <a-z> are thetextmarkers, e.g., @kbd{[a} to view marker @samp{a} .@refill@item Repeated CommandsCommand repetitions are common over files. Typing @kbd{!!} will repeat thelast @kbd{!} command whichever file it was issued from.Typing @kbd{.} will repeat the last command from any file, andsearches will repeat the last search. Ex commands can be repeated by typing@kbd{: @key{RET}}.@refillNote: in some rare cases, that @kbd{: @key{RET}} may do something dangerous.However, usually its effect can be undone by typing @kbd{u}.@item Registers@cindex registersRegisters are common to files. Also, text yanked with @kbd{y} can beput back (@kbd{p}) into any file. The Viper command @kbd{]<a-z>}, where <a-z> arethe registers, can be used to look at the contents of a register, e.g.,type @kbd{]a} to view register @samp{a}.There is one difference in text deletion that you should beaware of. This difference comes from Emacs and was adopted in Viperbecause we find it very useful. In Vi, if you delete a line, say, and thenanother line, these two deletions are separated and are put backseparately if you use the @samp{p} command. In Emacs (and Viper), successiveseries of deletions that are @emph{not interrupted} by other commands arelumped together, so the deleted text gets accumulated and can be put backas one chunk. If you want to break a sequence of deletions so that thenewly deleted text could be put back separately from the previously deletedtext, you should perform a non-deleting action, e.g., move the cursor onecharacter in any direction.@item Absolute Filenames@cindex absolute file namesThe current directory name for a file is automatically prepended to thefile name in any@kbd{:e}, @kbd{:r}, @kbd{:w}, etc., command (in Emacs, each buffer has acurrent directory).This directory is inserted in the Minibuffer once you type space after@kbd{:e, r}, etc. Viper also supports completion of file names and Excommands (@key{TAB}), and it keeps track ofcommand and file history (@kbd{M-p}, @kbd{M-n}).Absolute filenames are required lessoften in Viper.You should be aware that Emacs interprets @kbd{/foo/bar//bla} as@kbd{/bla} and @kbd{/foo/~/bar} as @kbd{~/bar}. This is designed tominimize the need for erasing file names that Emacs suggests in itsprompts, if a suggested file name is not what you wanted.The command @kbd{:cd} will change the default directory for thecurrent Emacs buffer. The Ex command @kbd{:e} will interpret thefilename argument in @samp{csh}, by default. @xref{Customization}, if youwant to change this.@end table@noindentCurrently undisplayed files can be listed using the @kbd{:ar} command. Thecommand @kbd{:n} can be given counts from the @kbd{:ar} list to switch toother files. For example, use `:n3' to move to the third file in that list.@node Unimplemented Features,,Multiple Files in Viper,Overview@section Unimplemented FeaturesUnimplemented features include:@itemize @bullet@item@kbd{:ab} and @kbd{:una} are not implemented, since@kbd{:ab} is considered obsolete, since Emacs has muchmore powerful facilities for defining abbreviations.@item@kbd{:set option?} is not implemented. The current@kbd{:set} can also be used to set Emacs variables.@item@kbd{:se list} requires modification of the display code for Emacs, soit is not implemented.A useful alternative is @code{cat -t -e file}. Unfortunately, it cannotbe used directly inside Emacs, since Emacs will obdurately change @samp{^I}back to normal tabs.@refill@end itemize@comment node-name, next, previous, up@node Improvements over Vi, Customization, Overview, Top@chapter Improvements over ViSome common problems with Vi and Ex have been solved in Viper. Thisincludes better implementation of existing commands, new commands, andthe facilities provided by Emacs.@menu* Basics:: Basic Viper differences, Multi-file effects.* Undo and Backups:: Multiple undo, auto-save, backups and changes* History:: History for Ex and Vi commands.* Macros and Registers:: Keyboard Macros (extended ".")@: @@reg execution.* Completion:: Filename and Command Completion for Ex.* Improved Search:: Incremental Search and Buffer Content Search.* Abbreviation Facilities:: Normal Abbrevs, Templates, and Dynamic Abbrevs.* Movement and Markers:: Screen Editor movements, viewing textmarkers.* New Commands:: Commands that do not exist in Vi.* Useful Packages:: A Sampling of some Emacs packages, and things you should know about.@end menu@node Basics, Undo and Backups, Improvements over Vi, Improvements over Vi@section BasicsThe Vi command set is based on the idea of combining motion commandswith other commands. The motion command is used as a text regionspecifier for other commands.We classify motion commands into @dfn{point commands} and@dfn{line commands}.@refill@cindex point commandsThe point commands are:@quotation@kbd{h}, @kbd{l}, @kbd{0}, @kbd{$}, @kbd{w}, @kbd{W}, @kbd{b}, @kbd{B},@kbd{e}, @kbd{E}, @kbd{(}, @kbd{)}, @kbd{/}, @kbd{?}, @kbd{`}, @kbd{f},@kbd{F}, @kbd{t}, @kbd{T}, @kbd{%}, @kbd{;}, @kbd{,}, @kbd{^}@end quotation@cindex line commandsThe line commands are:@quotation@kbd{j}, @kbd{k}, @kbd{+}, @kbd{-}, @kbd{H}, @kbd{M}, @kbd{L}, @kbd{@{},@kbd{@}}, @kbd{G}, @kbd{'}, @kbd{[[}, @kbd{]]}, @kbd{[]}@end quotation@cindex region@cindex region specification@cindex expanding (region)@cindex describing regions@cindex movement commands@noindentIf a point command is given as an argument to a modifying command, theregion determined by the point command will be affected by the modifyingcommand. On the other hand, if a line command is given as an argument to amodifying command, the region determined by the line command will beenlarged so that it will become the smallest region properly containing theregion and consisting of whole lines (we call this process @dfn{expandingthe region}), and then the enlarged region will be affected by the modifyingcommand.Text Deletion Commands (@pxref{Deleting Text}), Change commands(@pxref{Changing Text}), even Shell Commands (@pxref{Shell Commands})use these commands to describe a region of text to operate on.Thus, type @kbd{dw} to delete a word, @kbd{>@}} to shift a paragraph, or@kbd{!'afmt} to format a region from @samp{point} to textmarker@samp{a}.@cindex r and R region specifiersViper adds the region specifiers @samp{r} and @samp{R}. Emacs has aspecial marker called @dfn{mark}. The text-area between the current cursorposition @dfn{point} and the @dfn{mark} is called the @dfn{region}.@samp{r} specifies the raw region and @samp{R} is the expanded region(i.e., the minimal contiguous chunk of full lines that contains the rawregion).@kbd{dr} will now delete the region, @kbd{>r} will shift it, etc.@kbd{r,R} are not motion commands, however. The special mark is set by@kbd{m.} and other commands. @xref{Marking}, for more info.Viper also adds counts to most commands for which it would make sense.In the Overview chapter, some Multiple File issues were discussed(@pxref{Multiple Files in Viper}). In addition to the files, Emacs hasbuffers. These can be seen in the @kbd{:args} list and switched using@kbd{:next} if you type @kbd{:set ex-cycle-through-non-files t}, orspecify @code{(setq ex-cycle-through-non-files t)} in your @file{.viper}file. @xref{Customization}, for details.@node Undo and Backups, History, Basics, Improvements over Vi@section Undo and Backups@cindex undoViper provides multiple undo. The number of undo's and the size is limitedby the machine. The Viper command @kbd{u} does an undo. Undo can berepeated by typing @kbd{.} (a period). Another @kbd{u} will undo the undo,and further@kbd{.} will repeat it. Typing @kbd{u} does the first undo, and changes thedirection.@cindex backup files@cindex auto saveSince the undo size is limited, Viper can create backup files andauto-save files. It will normally do this automatically. It is possibleto have numbered backups, etc. For details, @pxref{Backup,,Backup andAuto-Save,emacs,The GNU Emacs Manual} @refill@comment [ balance parens@cindex viewing registers and markers@cindex registers@cindex markers@cindex textmarkersThe results of the 9 previous changes are available in the 9 numericregisters, as in Vi. The extra goody is the ability to @emph{view} theseregisters, in addition to being able to access them through @kbd{p} and@kbd{M-y} (@xref{Insert State}, for details.)The Viper command @kbd{] register} will display the contents of anyregister, numeric or alphabetical. The related command @kbd{[ textmarker}will show the text around the textmarker. @samp{register} and @samp{textmarker}can be any letters from a through z.@comment ] balance parens@node History, Macros and Registers, Undo and Backups,Improvements over Vi@section History@cindex history@cindex MinibufferHistory is provided for Ex commands, Vi searches, file names, pieces oftext inserted in earlier commands that use Insert or Replace state, and fordestructive commands in Vi state. These areuseful for fixing those small typos that screw up searches and @kbd{:s},and for eliminating routine associated with repeated typing of file namesor pieces of text that need to be inserted frequently.At the @kbd{:} or @kbd{/} prompts in the Minibuffer, you can do the following:@table @kbd@item M-p and M-nTo move to previous and next history items. This causes the historyitems to appear on the command line, where you can edit them, orsimply type Return to execute.@item M-r and M-sTo search backward and forward through the history.@item @key{RET}Type @key{RET} to accept a default (which is displayed in the prompt).@end tableThe history of insertions can be perused bytyping @kbd{C-c M-p} and @kbd{C-c M-n} while in Insert or Replace state.The history of destructive Vi commands can be perused via the same keyswhen Viper is in Vi state. @xref{Viper Specials}, for details.All Ex commands have a file history. For instance, typing @kbd{:e}, spaceand then @kbd{M-p} will bring up the name of the previously typed filename. Repeatedly typing @kbd{M-p}, @kbd{M-n}, etc., will let you browsethrough the file history.Similarly, commands that have to do with switching buffershave a buffer history, and commands that expect strings or regularexpressions keep a history on those items.@node Macros and Registers,Completion,History,Improvements over Vi@section Macros and Registers@cindex keyboard macros@cindex macros@cindex registers@cindex register executionViper facilitates the use of Emacs-style keyboard macros. @kbd{@@#} willstart a macro definition. As you type, the commands will be executed, andremembered (This is called ``learn mode'' in some editors.)@kbd{@@register} will complete the macro, putting it into @samp{register},where @samp{register} is any character from @samp{a} through @samp{z}. Thenyou can execute this macro using @kbd{@@register}. It is, of course,possible to yank some text into a register and execute it using@kbd{@@register}. Typing @kbd{@@@@}, @kbd{@@RET}, or @kbd{@@C-j} willexecute the last macro that was executed using @kbd{@@register}.@refillViper will automatically lowercase the register, so that pressing the@kbd{SHIFT} key for @kbd{@@} will not create problems. This is for@kbd{@@} macros and @kbd{"p} @emph{only}. In the case of @kbd{y},@kbd{"Ayy} will append to @emph{register a}. For @kbd{[,],',`}, itis an error to use a Uppercase register name.@comment [ balance parens@cindex viewing registers and markersThe contents of a register can be seen by @kbd{]register}. (@kbd{[textmarker}will show the contents of a textmarker).@comment ] balance parens@cindex last keyboard macroThe last keyboard macro can also be executed using@kbd{*}, and it can be yanked into a register using @kbd{@@!register}.This is useful for Emacs style keyboard macros defined using @kbd{C-x(}and @kbd{C-x)}. Emacs keyboard macros have more capabilities.@xref{Keyboard Macros,,Keyboard Macros,emacs, The GNU Emacs Manual}, fordetails.@refillKeyboard Macros allow an interesting form of Query-Replace:@kbd{/pattern} or @kbd{n} to go to the next pattern (the query), followed by aKeyboard Macro execution @kbd{@@@@} (the replace).Viper also provides Vi-style macros. @xref{Vi Macros}, for details.@node Completion, Improved Search, Macros and Registers, Improvements over Vi@section Completion@cindex completionCompletion is done when you type @key{TAB}. The Emacs completer does notgrok wildcards in file names. Once you type a wildcard, the completer willno longer work for that file name. Remember that Emacs interprets a file nameof the form @kbd{/foo//bar} as @kbd{/bar} and @kbd{/foo/~/bar} as@kbd{~/bar}.@node Improved Search, Abbreviation Facilities, Completion, Improvements over Vi@section Improved Search@cindex buffer search@cindex word searchViper provides buffer search, the ability to search the buffer for a regionunder the cursor. You have to turn this on in @file{.viper} either by calling@example(viper-buffer-search-enable)@end example@noindentor by setting @code{viper-buffer-search-char} to, say, @kbd{f3}:@example(setq viper-buffer-search-char ?g)@end example@noindentIf the user calls @code{viper-buffer-search-enable} explicitly (the firstmethod), then @code{viper-buffer-search-char} will be set to @kbd{g}.Regardless of how this feature is enabled, the key@code{viper-buffer-search-char} will take movement commands, like@kbd{w,/,e}, to find a region and then search for the contents of thatregion. This command is very useful for searching for variable names, etc.,in a program. The search can be repeated by @kbd{n} or reversed by @kbd{N}.@cindex incremental searchEmacs provides incremental search. As you type the string in, thecursor will move to the next match. You can snarf words from the bufferas you go along. Incremental Search is normally bound to @kbd{C-s} and@kbd{C-r}. @xref{Customization}, to find out how to change the bindingsof @kbd{C-r or C-s}.For details, @pxref{Incremental Search,,IncrementalSearch,emacs,The GNU Emacs Manual} @refill@cindex query replaceViper also provides a query replace function that prompts through theMinibuffer. It is invoked by the @kbd{Q} key in Vi state.@cindex mouse searchOn a window display, Viper supports mouse search, i.e., you can search for aword by clicking on it. @xref{Viper Specials}, for details.Finally, on a window display, Viper highlights search patterns as it findsthem. This is done through what is known as @emph{faces} in Emacs. Thevariable that controls how search patterns are highlighted is@code{viper-search-face}. If you don't want any highlighting at all, put@example(copy-face 'default 'viper-search-face)@end example@vindex @code{viper-search-face}@noindentin @file{~/.viper}. If you want to change how patterns are highlighted, youwill have to change @code{viper-search-face} to your liking. The easiestway to do this is to use Emacs customization widget, which is accessiblefrom the menubar. Viper customization group is located under the@emph{Emulations} customization group, which in turn is under the@emph{Editing} group (or simply by typing @kbd{:customize}). All Viperfaces are grouped together under Viper's@emph{Highlighting} group.Try it: it is really simple!@node Abbreviation Facilities,Movement and Markers,Improved Search,Improvements over Vi@section Abbreviation Facilities@cindex abbrevsIt is possible in Emacs to define abbrevs based on the contents of thebuffer.Sophisticated templates can be defined using the Emacs abbreviationfacilities. @xref{Abbrevs,,Abbreviations,emacs,The GNU Emacs Manual}, fordetails.@cindex dynamic abbrevsEmacs also provides Dynamic Abbreviations. Given a partial word, Emacswill search the buffer to find an extension for this word. For instance,one can type @samp{Abbreviations} by typing @samp{A}, followed by a keystrokethat completed the @samp{A} to @samp{Abbreviations}. Repeated typingwill search further back in the buffer, so that one could get@samp{Abbrevs} by repeating thekeystroke, which appears earlier in the text. Emacs binds this to@kbd{@key{ESC} /}, so you will have to find a key and bind the function@code{dabbrev-expand} to that key.Facilities like this make Vi's @kbd{:ab} command obsolete.@node Movement and Markers, New Commands, Abbreviation Facilities, Improvements over Vi@section Movement and Markers@cindex Ex style motion@cindex line editor motionViper can be set free from the line--limited movements in Vi, such as @kbd{l}refusing to move beyond the line, @key{ESC} moving one character back,etc. These derive from Ex, which is a line editor. If your @file{.viper}contains@example@code{(setq viper-ex-style-motion nil)}@end example@noindentthe motion will be a true screen editor motion. One thing you must thenwatch out for is that it is possible to be on the end-of-line character.The keys @kbd{x} and @kbd{%} will still work correctly, i.e., as if theywere on the last character.@vindex @code{viper-syntax-preference}@cindex syntax tableThe word-movement commands @kbd{w}, @kbd{e}, etc., and the associateddeletion/yanking commands, @kbd{dw}, @kbd{yw}, etc., can be made tounderstand Emacs syntax tables. If the variable@code{viper-syntax-preference} is set to @code{strict-vi} thenthe meaning of @emph{word} is the same as inVi. However, if the value is @code{reformed-vi} (the default) then thealphanumeric symbols will be those specified by the current Emacs syntaxtable (which may be different for different major modes) plus theunderscore symbol @kbd{_}, minus some non-word symbols, like '.;,|, etc.Both @code{strict-vi} and @code{reformed-vi} work close to Vi intraditional cases, but @code{reformed-vi} does a better job when editingtext in non-Latin alphabets.The user can also specify the value @code{emacs}, which wouldmake Viper use exactly the Emacs notion of word. In particular, theunderscore may not be part of a word. Finally, if@code{viper-syntax-preference} is set to @code{extended}, Viper words wouldconsist of characters that are classified as alphanumeric @emph{or} asparts of symbols. This is convenient for writing programs and in many othersituations.@code{viper-syntax-preference} is a local variable, so it can have differentvalues for different major modes. For instance, in programming modes it canhave the value @code{extended}. In text modes where words contain specialcharacters, such as European (non-English) letters, Cyrillic letters, etc.,the value can be @code{reformed-vi} or @code{emacs}.Changes to @code{viper-syntax-preference} should be done in the hooks tovarious major modes by executing @code{viper-set-syntax-preference} as inthe following example:@example(viper-set-syntax-preference nil "emacs")@end example@findex @code{viper-set-syntax-preference}The above discussion of the meaning of Viper's words concerns only Viper'smovement commands. In regular expressions, words remain the same as inEmacs. That is, the expressions @code{\w}, @code{\>}, @code{\<}, etc., useEmacs' idea of what is a word, and they don't look into the value ofvariable @code{viper-syntax-preference}. This is because Viper doesn't changesyntax tables in fear of upsetting the various major modes that set thesetables.@cindex textmarkersTextmarkers in Viper remember the file and the position, so that you canswitch files by simply doing @kbd{'a}. If you set up a regimen for usingTextmarkers, this is very useful. Contents of textmarkers can be viewedby @kbd{[marker}. (Contents of registers can be viewed by @kbd{]register}).@node New Commands, Useful Packages, Movement and Markers, Improvements over Vi@section New CommandsThese commands have no Vi analogs.@table @kbd@item C-x, C-c@kindex @kbd{C-x}@kindex @kbd{C-c}These two keys invoke many important Emacs functions. For example, if youhit @kbd{C-x} followed by @kbd{2}, then the current window will be splitinto 2. Except for novice users, @kbd{C-c} is also set to execute an Emacscommand from the current major mode. @key{ESC} will do the same, if youconfigure @key{ESC} as Meta by setting @code{viper-no-multiple-ESC} to @code{nil}in @file{.viper}. @xref{Customization}. @kbd{C-\} in Insert, Replace, or Vistates will make Emacs think @kbd{Meta} has been hit.@refill@item \@kindex @kbd{\}Escape to Emacs to execute a single Emacs command. For instance,@kbd{\ @key{ESC}} will act like a Meta key.@item Q@kindex @kbd{Q}@cindex query replace@kbd{Q} is for query replace. By default,each string to be replaced is treated as a regular expression. You can use@code{(setq viper-re-query-replace nil)} in your @file{.emacs} file toturn this off. (For normal searches, @kbd{:se nomagic} will work. Notethat @kbd{:se nomagic} turns Regexps off completely, unlike Vi).@item v@itemx V@itemx C-v@kindex @kbd{v}@kindex @kbd{V}@kindex @kbd{C-v}These keys are used to visit files. @kbd{v} will switch to a buffervisiting file whose name can be entered in the Minibuffer. @kbd{V} issimilar, but will use a window different from the current window.@kbd{C-v} is like @kbd{V}, except that a new frame (X window) will be usedinstead of a new Emacs window.@item #@kindex @kbd{#}If followed by a certain character @var{ch}, it becomes an operator whoseargument is the region determined by the motion command that follows(indicated as <move>).Currently, @var{ch} can be one of @kbd{c}, @kbd{C}, @kbd{g}, @kbd{q}, and@kbd{s}. For instance, @kbd{#qr} will prompt you for a string and thenprepend this string to each line in the buffer.@refill@item # c@kindex @kbd{#c<move>}@cindex changing caseChange upper-case characters in the region to lower-case(@code{downcase-region}).Emacs command @kbd{M-l} does the same for words.@item # C@kindex @kbd{#C<move>}Change lower-case characters in the region to upper-case. For instance,@kbd{# C 3 w} will capitalize 3 words from the current point(@code{upcase-region}).Emacs command @kbd{M-u} does the same for words.@item # g@kindex @kbd{#g<move>}Execute last keyboard macro for each line in the region(@code{viper-global-execute}).@refill@item # q@kindex @kbd{#q<move>}Insert specified string at the beginning of each line in the region(@code{viper-quote-region}). The default string is composed of the commentcharacter(s) appropriate for the current major mode.@item # s@kindex @kbd{#s<move>}Check spelling of words in the region (@code{spell-region}).The function used for spelling is determined from the variable@code{viper-spell-function}.@vindex @code{viper-spell-function}@item *@kindex @kbd{*}Call last keyboard macro.@item m .Set mark at point and push old mark off the ring@item m<@item m>Set mark at beginning and end of buffer, respectively.@item m,Jump to mark and pop mark off the ring. @xref{Mark,,Mark,emacs,The GNUEmacs Manual}, for more info.@item ] register@kindex @kbd{]<a-z>}View contents of register@item [ textmarker@kindex @kbd{[<a-z>}View filename and position of textmarker@item @@#@item @@register@item @@!@kindex @kbd{@@#}@kindex @kbd{@@<a-z>}@kindex @kbd{@@!}@cindex keyboard macros@cindex register executionBegin/end keyboard macro. @@register has a different meaning when used aftera @kbd{@@#}. @xref{Macros and Registers}, for details@item []@kindex @kbd{[]}Go to end of heading.@item g <@emph{movement command}>Search buffer for text delimited by movement command. The canonicalexample is @kbd{gw} to search for the word under the cursor.@xref{Improved Search}, for details.@refill@item C-g and C-]@kindex @kbd{C-g}@kindex @kbd{C-]}Quit and Abort Recursive edit. These may be necessary on occasion.@xref{Vi State}, for a reason.@item C-c C-g@kindex @kbd{C-c C-g}Hitting @kbd{C-c} followed by @kbd{C-g} will display the information on thecurrent buffer. This is the same as hitting @kbd{C-g} in Vi, but, asexplained above, @kbd{C-g} is needed for other purposes in Emacs.@item C-c /@kindex @kbd{C-c /}Without a prefix argument, this command togglescase-sensitive/case-insensitive search modes and plain vanilla/regularexpression search. With the prefix argument 1, i.e.,@kbd{1 C-c /}, this toggles case-sensitivity; with the prefix argument 2,toggles plain vanilla search and search usingregular expressions. @xref{Viper Specials}, for alternative ways to invokethis function.@cindex vanilla search@cindex case-sensitive search@cindex case-insensitive search@item M-p and M-n@kindex @kbd{M-p}@kindex @kbd{M-n}In the Minibuffer, these commands navigate through the minibufferhistories, such as the history of search strings, Ex commands, etc.@item C-c M-p and C-c M-n@kindex @kbd{C-c M-p}@kindex @kbd{C-c M-n}@cindex Insertion history@cindex Insertion ring@cindex Command history@cindex Command ringIn Insert or Replace state, these commands let the userperuse the history of insertion strings used in previous insert or replacecommands. Try to hit @kbd{C-c M-p} or @kbd{C-c M-n} repeatedly and see whathappens. @xref{Viper Specials}, for more.In Vi state, these commands let the user peruse the history of Vi-styledestructive commands, such as @kbd{dw}, @kbd{J}, @kbd{a}, etc.By repeatedly typing @kbd{C-c M-p} or @kbd{C-c M-n} you will cycle Viperthrough the recent history of Vi commands, displaying the commands one byone. Oncean appropriate command is found, it can be executed by typing `@kbd{.}'.Since typing @kbd{C-c M-p} is tedious, it is more convenient to bind anappropriate function to a function key on the keyboard and use that key.@xref{Viper Specials}, for details.@item Ex commands@findex @kbd{:args}@findex @kbd{:n}@findex @kbd{:pwd}@findex @kbd{:pre}The commands @kbd{:args}, @kbd{:next}, @kbd{:pre} behavedifferently. @kbd{:pwd} exists to get current directory.The commands @kbd{:b} and @kbd{:B} switch buffers around. @xref{File andBuffer Handling}, for details.There are also the new commands @kbd{:RelatedFile} and@kbd{PreviousRelatedFile} (which abbreviate to @kbd{R} and @kbd{P},respectively. @xref{Viper Specials}, for details.@findex @kbd{:RelatedFile}@findex @kbd{:PreviousRelatedFile}@end tableApart from the new commands, many old commands have been enhanced. Mostnotably, Vi style macros are much more powerful in Viper than in Vi. @xref{ViMacros}, for details.@node Useful Packages, ,New Commands, Improvements over Vi@section Useful PackagesSome Emacs packages are mentioned here as an aid to the new Viper user, toindicate what Viper is capable of.A vast number comes with the standard Emacs distribution, and many more existon the net and on the archives.This manual also mentions some Emacs features a new usershould know about. The details of these are found in the GNU EmacsManual.The features first. For details, look up the Emacs Manual.@table @samp@item Make@cindex make@cindex compilingMakes and Compiles can be done from the editor. Error messages will beparsed and you can move to the error lines.@item Shell@cindex shell@cindex interactive shellYou can talk to Shells from inside the editor. Your entire shell sessioncan be treated as a file.@item Mail@cindex email@cindex mailMail can be read from and sent within the editor. Several sophisticatedpackages exist.@item Language Sensitive EditingEditing modes are written for most computer languages in existence. Bycontrolling indentation, they catch punctuation errors.@end tableThe packages, below, represents a drop in the sea of special-purposepackages that come with standard distribution of Emacs.@table @samp@item Transparent FTP@cindex transparent ftp@pindex ange-ftp.el@code{ange-ftp.el} can ftp from the editor to files on other machinestransparent to the user.@item RCS Interfaces@cindex version maintenance@cindex RCS@pindex vc.el@code{vc.el} for doing RCS commands from inside the editor@item Directory Editor@cindex dired@pindex dired.el@code{dired.el} for editing contents of directories and for navigating inthe file system.@item Syntactic Highlighting@cindex font-lock@pindex font-lock.el@code{font-lock.el} for automatic highlighting various parts of a bufferusing different fonts and colors.@item Saving Emacs Configuration@cindex desktop@pindex desktop.el@code{desktop.el} for saving/restoring configuration on Emacs exit/startup.@item Spell Checker@cindex ispell@pindex ispell.el@code{ispell.el} for spell checking the buffer, words, regions, etc.@item File and Buffer Comparison@cindex ediff@pindex ediff.el@code{ediff.el} for finding differences between files and for applyingpatches.@end table@noindentEmacs Lisp archives exist on@samp{archive.cis.ohio-state.edu}and @samp{wuarchive.wustl.edu}@refill@node Customization,Commands,Improvements over Vi,Top@chapter Customization@cindex customizationCustomization can be done in 2 ways.@itemize @bullet@item@cindex initialization@cindex .viperElisp code in a @file{.viper} file in your home directory. Viperloads @file{.viper} just before it does the binding for modehooks. This is recommended for experts only.@item@cindex .emacsElisp code in your @file{.emacs} file before and after the @code{(require'viper)} line. This method is @emph{not} recommended, unless you know whatyou are doing. Only two variables, @code{viper-mode} and@code{viper-custom-file-name}, are supposed to be customized in @file{.emacs},prior to loading Viper (i.e., prior to @code{(require 'viper)} command.@refill@item@cindex :customizeBy executing the @kbd{:customize} Ex command. This takes you to the Emacscustomization widget, which lets you change the values of Vipercustomizable variables easily. This method is good for novice andexperts alike. The customization code in the form of Lisp commands will beplaced in @file{~/.emacs} or some other customization file depending on theversion of Emacs that you use. Still, it is recommended to separateViper-related customization produced by the Emacs customization widgetand keep it in the @file{.viper} file.Some advanced customization cannot be accomplished this way, however, andhas to be done in Emacs Lisp in the @file{.viper} file. For the commoncases, examples are provided that you can use directly.@end itemize@menu* Rudimentary Changes:: Simple constant definitions.* Key Bindings:: Enabling Emacs Keys, Rebinding keys, etc.* Packages that Change Keymaps:: How to deal with such beasts.* Viper Specials:: Special Viper commands.* Vi Macros:: How to do Vi style macros.@end menu@node Rudimentary Changes,Key Bindings,Customization,Customization@section Rudimentary Changes@cindex setting variables@cindex variables for customization@findex @kbd{:set}An easy way to customize Viper is to change the values of constants used inViper. Here is the list of the constants used in Viper and their defaultvalues. The corresponding :se command is also indicated. (The symbols@code{t} and @code{nil} represent ``true'' and ``false'' in Lisp).Viper supports both the abbreviated Vi variable names and their fullnames. Variable completion is done on full names only. @key{TAB} and@key{SPC} completevariable names. Typing `=' will complete the name and then will prompt fora value, if applicable. For instance, @kbd{:se au @key{SPC}} will complete thecommand to @kbd{:set autoindent}; @kbd{:se ta @key{SPC}} will complete the commandand prompt further like this: @kbd{:set tabstop = }.However, typing @kbd{:se ts @key{SPC}} will produce a ``No match'' messagebecause @kbd{ts} is an abbreviation for @kbd{tabstop} and Viper supportscompletion on full names only. However, you can still hit @key{RET}or @kbd{=}, which will complete the command like this: @kbd{:set ts = } andViper will be waiting for you to type a value for the tabstop variable.To get the full list of Vi variables, type @kbd{:se @key{SPC} @key{TAB}}.@table @code@item viper-auto-indent nil@itemx :se ai (:se autoindent)@itemx :se ai-g (:se autoindent-global)If @code{t}, enable auto indentation.by @key{RET}, @kbd{o} or @kbd{O} command.@code{viper-auto-indent} is a local variable. To change the value globally, use@code{setq-default}. It may be useful for certain major modes to have theirown values of @code{viper-auto-indent}. This can be achieved by using@code{setq} to change the local value of this variable in the hooks to theappropriate major modes.@kbd{:se ai} changes the value of @code{viper-auto-indent} in the currentbuffer only; @kbd{:se ai-g} does the same globally.@item viper-electric-mode tIf not @code{nil}, auto-indentation becomes electric, which means that@key{RET}, @kbd{O}, and @kbd{o} indent cursor according to the currentmajor mode. In the future, this variable may control additional electricfeatures.This is a local variable: @code{setq} changes the value of this variablein the current buffer only. Use @code{setq-default} to change the value inall buffers.@item viper-case-fold-search nil@itemx :se ic (:se ignorecase)If not @code{nil}, search ignores cases.This can also be toggled by quickly hitting @kbd{/} twice.@item viper-re-search nil@itemx :se magicIf not @code{nil}, search will use regular expressions; if @code{nil} thenuse vanilla search.This behavior can also be toggled by quickly hitting @kbd{/} trice.@item buffer-read-only@itemx :se ro (:se readonly)Set current buffer to read only. To change globally put@code{(setq-default buffer-read-only t)} in your @file{.emacs} file.@item blink-matching-paren t@itemx :se sm (:se showmatch)Show matching parens by blinking cursor.@item tab-width t (default setting via @code{setq-default})@itemx :se ts=value (:se tabstop=value)@itemx :se ts-g=value (:se tabstop-global=value)@code{tab-width} is a local variable that controls the width of the tab stops.To change the value globally, use @code{setq-default}; for local settings,use @code{setq}.The command @kbd{:se ts}sets the tab width in the currentbuffer only; it has no effect on other buffers.The command @kbd{:se ts-g} sets tab width globally,for all buffers where the tab is not yet set locally,including the new buffers.Note that typing @key{TAB} normallydoesn't insert the tab, since this key is usually bound toa text-formatting function, @code{indent-for-tab-command} (which facilitatesprogramming and document writing). Instead, the tab is inserted via thecommand @code{viper-insert-tab}, which is bound to @kbd{S-tab} (shift + tab).On some non-windowing terminals, Shift doesn't modify the @key{TAB} key, so@kbd{S-tab} behaves as if it were @key{TAB}. In such a case, you will haveto bind @code{viper-insert-tab} to some other convenient key.@item viper-shift-width 8@itemx :se sw=value (:se shiftwidth=value)The number of columns shifted by @kbd{>} and @kbd{<} commands.@item viper-search-wrap-around t@itemx :se ws (:se wrapscan)If not @code{nil}, search wraps around the end/beginning of buffer.@item viper-search-scroll-threshold 2If search lands within this many lines of the window top or bottom, thewindow will be scrolled up or down by about 1/7-th of its size, to revealthe context. If the value is negative---don't scroll.@item viper-tags-file-name "TAGS"The name of the file used as the tag table.@item viper-re-query-replace nilIf not @code{nil}, use reg-exp replace in query replace.@item viper-want-ctl-h-help nilIf not @code{nil}, @kbd{C-h} is bound to @code{help-command};otherwise, @kbd{C-h} is bound as usual in Vi.@item viper-vi-style-in-minibuffer tIf not @code{nil}, Viper provides a high degree of compatibility with Viinsert mode when you type text in the Minibuffer; if @code{nil}, typing inthe Minibuffer feels like plain Emacs.@item viper-no-multiple-ESC tIf you set this to @code{nil}, you can use @key{ESC} as Meta in Vi state.Normally, this is not necessary, since graphical displays have separateMeta keys (usually on each side of the space bar). On a dumb terminal, Vipersets this variable to @code{twice}, which is almost like @code{nil}, exceptthat double @key{ESC} beeps. This, too, lets @key{ESC} to be used as a Meta.@item viper-ESC-keyseq-timeout 200 on tty, 0 on windowing displayEscape key sequences separated by this much delay (in milliseconds) areinterpreted as command, ignoring the special meaning of @key{ESC} inVI. The default is suitable for most terminals. However, if your terminalis extremely slow, you might want to increase this slightly. You will knowif your terminal is slow if the @key{ESC} key sequences emitted by thearrow keys are interpreted as separately typed characters (and thus thearrow keys won't work). Making this value too large will slow you down, soexercise restraint.@item viper-fast-keyseq-timeout 200Key sequences separated by this many milliseconds are treated as Vi-stylekeyboard macros. If the key sequence is defined as such a macro, it will beexecuted. Otherwise, it is processed as an ordinary sequence of typed keys.Setting this variable too high may slow down your typing. Setting it toolow may make it hard to type macros quickly enough.@item viper-translate-all-ESC-keysequences @code{t} on tty, @code{nil} on windowing displayNormally, Viper lets Emacs translate only those ESC key sequences that aredefined in the low-level key-translation-map or function-key-map, such as thoseemitted by the arrow and function keys. Other sequences, e.g., @kbd{\\e/}, aretreated as @kbd{ESC} command followed by a @kbd{/}. This is good for peoplewho type fast and tend to hit other characters right after they hitESC. Other people like Emacs to translate @kbd{ESC} sequences all the time.The default is to translate all sequences only when using a dumb terminal.This permits you to use @kbd{ESC} as a meta key in insert mode. For instance,hitting @kbd{ESC x} fast would have the effect of typing @kbd{M-x}.If your dumb terminal is not so dumb and understands the meta key, then youprobably will be better off setting this variable to @code{nil}. Try and see whichway suits you best.@item viper-ex-style-motion tSet this to @code{nil}, if you want @kbd{l,h} to crosslines, etc. @xref{Movement and Markers}, for more info.@item viper-ex-style-editing tSet this to @code{nil}, if you want@kbd{C-h} and @key{DEL} to not stopat the beginning of a line in Insert state, @key{X} and @key{x} to deletecharacters across lines in Vi command state, etc.@item viper-ESC-moves-cursor-back tIt @code{t}, cursor moves back 1 character when switching from insert state to vistate. If @code{nil}, the cursor stays where it was before the switch.@item viper-always t@code{t} means: leave it to Viper to decide when a buffer must be broughtup in Vi state,Insert state, or Emacs state. This heuristics works well in virtually allcases. @code{nil} means you either has to invoke @code{viper-mode} manuallyfor each buffer (or you can add @code{viper-mode} to the appropriate major modehooks using @code{viper-load-hook}).This option must be set in the file @file{~/.viper}.@item viper-custom-file-name "~/.viper"File used for Viper-specific customization.Change this setting, if you want. Must be set in @file{.emacs} (not @file{.viper}!)before Viper is loaded. Note that youhave to set it as a string inside double quotes.@item viper-spell-function 'ispell-regionFunction used by the command @kbd{#c<move>} to spell.@item viper-glob-functionThe value of this variable is the function symbol used to expand wildcardsymbols. This is platform-dependent. The default tries to set this variableto work with most shells, MS Windows, OS/2, etc. However, if itdoesn't work the way you expect, you should write your own.Use @code{viper-glob-unix-files} and @code{viper-glob-mswindows-files} in@file{viper-util.el} as examples.This feature is used to expand wildcards in the Ex command @kbd{:e}.Note that Viper doesn't support wildcards in the @kbd{:r} and @kbd{:w}commands, because file completion is a better mechanism.@findex @code{viper-glob-function}@item ex-cycle-other-window tIf not @code{nil}, @kbd{:n} and @kbd{:b} will cycle through files in anotherwindow, if one exists.@item ex-cycle-through-non-files nil@kbd{:n} does not normally cycle through buffers. Set this to getbuffers also.@item viper-want-emacs-keys-in-insertThis is set to @code{nil} for user levels 1 and 2 and to @code{t} for userlevels 3 and 4. Users who specify level 5 are allowed to set this variableas they please (the default for this level is @code{t}). If set to@code{nil}, complete Vi compatibility is provided in Insert state. This isreally not recommended, as this precludes you from using language-specificfeatures provided by the major modes.@item viper-want-emacs-keys-in-viThis is set to @code{nil} for userlevel 1 and to @code{t} for user levels 2--4.At level 5, users are allowed to set this variable as they please (thedefault for this level is @code{t}).If set to @code{nil}, complete Vi compatibility is providedin Vi command state. Setting this to @code{nil} is really a bad idea,unless you are a novice, as this precludes the useof language-specific features provided by the major modes.@item viper-keep-point-on-repeat tIf not @code{nil}, point is not moved when the user repeats the previouscommand by typing `.' This is very useful for doing repeated changes withthe @kbd{.} key.@item viper-repeat-from-history-key 'f12Prefix key used to invoke the macros @kbd{f12 1} and @kbd{f12 2} that repeatthe second-last and the third-last destructive command.Both these macros are bound (as Viper macros) to@code{viper-repeat-from-history},which checks the second key by which it is invoked to see which of theprevious commands to invoke. Viper binds @kbd{f12 1} and @kbd{f12 2} only,but the user can bind more in @file{~/.viper}. @xref{Vi Macros}, for how to dothis.@item viper-keep-point-on-undo nilIf not @code{nil}, Viper tries to not move point when undoing commands.Instead, it will briefly move the cursor to the place where change hastaken place. However, if the undone piece of text is not seen in window,then point will be moved to the place where the change took place.Set it to @code{t} and see if you like it better.@item viper-delete-backwards-in-replace nilIf not @code{nil}, @key{DEL} key will delete characters while moving the cursorbackwards. If @code{nil}, the cursor will move backwards without deletinganything.@item viper-replace-overlay-face 'viper-replace-overlay-faceOn a graphical display, Viper highlights replacement regions instead ofputting a @samp{$} at the end. This variable controls the so called@dfn{face} used to highlight the region.By default, @code{viper-replace-overlay-face} underlines the replacement onmonochrome displays and also lays a stipple over them. On color displays,replacement regions are highlighted with color.If you know something about Emacs faces and don't like how Viper highlightsreplacement regions, you can change @code{viper-replace-overlay-face} byspecifying a new face. (Emacs faces are described in the Emacs Lispreference.) On a color display, the following customization method isusually most effective:@example(set-face-foreground viper-replace-overlay-face "DarkSlateBlue")(set-face-background viper-replace-overlay-face "yellow")@end exampleFor a complete list of colors available to you, evaluate the expression@code{(x-defined-colors)}. (Type it in the buffer @code{*scratch*} and thenhit the @kbd{C-j} key.@item viper-replace-overlay-cursor-color "Red"@vindex @code{viper-replace-overlay-cursor-color}Cursor color when it is inside the replacement region.This has effect only on color displays and only when Emacs runs as an Xapplication.@item viper-insert-state-cursor-color nil@vindex @code{viper-insert-state-cursor-color}If set to a valid color, this will be the cursor color when Viper is ininsert state.@item viper-emacs-state-cursor-color nil@vindex @code{viper-emacs-state-cursor-color}If set to a valid color, this will be the cursor color when Viper is inemacs state.@item viper-replace-region-end-delimiter "$"A string used to mark the end of replacement regions. It is used only onTTYs or if @code{viper-use-replace-region-delimiters} is non-@code{nil}.@item viper-replace-region-start-delimiter ""A string used to mark the beginning of replacement regions. It is usedonly on TTYs or if @code{viper-use-replace-region-delimiters} is non-@code{nil}.@item viper-use-replace-region-delimitersIf non-@code{nil}, Viper will always use @code{viper-replace-region-end-delimiter} and@code{viper-replace-region-start-delimiter} to delimit replacement regions,even on color displays (where this is unnecessary). By default, thisvariable is non-@code{nil} only on TTYs or monochrome displays.@item viper-allow-multiline-replace-regions tIf non-@code{nil}, multi-line text replacement regions, such as those produced bycommands @kbd{c55w}, @kbd{3C}, etc., will stay around until the user exitsthe replacement mode. In this variable is set to @code{nil}, Viper willemulate the standard Vi behavior, which supports only intra-linereplacement regions (and multi-line replacement regions are deleted).@item viper-toggle-key "\C-z"Specifies the key used to switch from Emacs to Vi and back.Must be set in @file{.viper}. This variable can't bechanged interactively after Viper is loaded.In Insert state, this key acts as a temporary escape to Vi state, i.e., itwill set Viper up so that the very next command will be executed as if itwere typed in Vi state.@item viper-ESC-key "\e"Specifies the key used to escape from Insert/Replace states to Vi.Must be set in @file{.viper}. This variable cannot bechanged interactively after Viper is loaded.@item viper-buffer-search-char nilKey used for buffer search. @xref{Viper Specials}, for details.@item viper-surrounding-word-function 'viper-surrounding-wordThe value of this variable is a function name that is used to determinewhat constitutes a word clicked upon by the mouse. This is used by mousesearch and insert.@item viper-search-face 'viper-search-faceVariable that controls how search patterns are highlighted when they arefound.@item viper-vi-state-hook nilList of parameterless functions to be run just after entering the Vicommand state.@item viper-insert-state-hook nilSame for Insert state. This hook is also run after entering Replace state.@item viper-replace-state-hook nilList of (parameterless) functions called just after entering Replace state(and after all @code{viper-insert-state-hook}).@item viper-emacs-state-hook nilList of (parameterless) functions called just after switching from Vi stateto Emacs state.@item viper-load-hook nilList of (parameterless) functions called just after loading Viper. This isthe last chance to do customization before Viper is up and running.@end table@noindentYou can reset some of these constants in Viper with the Ex command @kbd{:set}(when so indicated in the table). Or youcan include a line like this in your @file{.viper} file:@example(setq viper-case-fold-search t)@end example@vindex @code{viper-auto-indent}@vindex @code{viper-electric-mode}@vindex @code{viper-case-fold-search}@vindex @code{viper-re-search}@vindex @code{viper-shift-width}@vindex @code{buffer-read-only}@vindex @code{viper-search-wrap-around}@vindex @code{viper-search-scroll-threshold}@vindex @code{viper-search-face}@vindex @code{viper-tags-file-name}@vindex @code{viper-re-query-replace}@vindex @code{viper-want-ctl-h-help}@vindex @code{viper-vi-style-in-minibuffer}@vindex @code{viper-no-multiple-ESC}@vindex @code{viper-always}@vindex @code{viper-ESC-keyseq-timeout}@vindex @code{viper-fast-keyseq-timeout}@vindex @code{viper-ex-style-motion}@vindex @code{viper-ex-style-editing}@vindex @code{viper-ESC-moves-cursor-back}@vindex @code{viper-custom-file-name}@vindex @code{viper-spell-function}@vindex @code{ex-cycle-other-window}@vindex @code{ex-cycle-through-non-files}@vindex @code{viper-want-emacs-keys-in-insert}@vindex @code{viper-want-emacs-keys-in-vi}@vindex @code{viper-keep-point-on-repeat}@vindex @code{viper-keep-point-on-undo}@vindex @code{viper-delete-backwards-in-replace}@vindex @code{viper-replace-overlay-face}@vindex @code{viper-replace-region-end-symbol}@vindex @code{viper-replace-region-start-symbol}@vindex @code{viper-allow-multiline-replace-regions}@vindex @code{viper-toggle-key}@vindex @code{viper-ESC-key}@vindex @code{viper-buffer-search-char}@vindex @code{viper-surrounding-word-function}@vindex @code{viper-vi-state-hook}@vindex @code{viper-insert-state-hook}@vindex @code{viper-replace-state-hook}@vindex @code{viper-emacs-state-hook}@node Key Bindings, Packages that Change Keymaps, Rudimentary Changes,Customization@section Key Bindings@cindex key bindings@cindex keymapsViper lets you define hot keys, i.e., you can associate keyboard keyssuch as F1, Help, PgDn, etc., with Emacs Lisp functions (that may alreadyexist or that you will write). Each key has a "preferred form" inEmacs. For instance, the Up key's preferred form is [up], the Help key'spreferred form is [help], and the Undo key has the preferred form [f14].You can find out the preferred form of a key by typing @kbd{M-xdescribe-key-briefly} and then typing the key you want to know about.Under the X Window System, every keyboard key emits its preferred form,so you can just type@lisp(global-set-key [f11] 'calendar) ; L1, Stop(global-set-key [f14] 'undo) ; L4, Undo@end lisp@noindentto bind L1 (a key that exists on some SUN workstations) so it will invokethe Emacs Calendar and to bind L4 so it will undo changes.However, on a dumb terminal or in an Xterm window, even the standard arrowkeys maynot emit the right signals for Emacs to understand. To let Emacs know aboutthose keys, you will have to find out which key sequences they emitby typing @kbd{C-q} and then the key (you should switch to Emacs statefirst). Then you can bind those sequences to their preferred forms using@code{function-key-map} as follows:@lisp(cond ((string= (getenv "TERM") "xterm")(define-key function-key-map "\e[192z" [f11]) ; L1(define-key function-key-map "\e[195z" [f14]) ; L4, Undo@end lispThe above illustrates how to do this for Xterm. On VT100, you would have toreplace "xterm" with "vt100" and also change the key sequences (the samekey may emit different sequences on different types of terminals).The above keys are global, so they are overwritten by the local mapsdefined by the major modes and by Viper itself. Therefore, if you wish tochange a binding set by a major mode or by Viper, read this.Viper users who wish to specify their own key bindings should be concernedonly with the following three keymaps:@code{viper-vi-global-user-map} for Vi state commands,@code{viper-insert-global-user-map} for Insert state commands,and @code{viper-emacs-global-user-map} for Emacs state commands (note:customized bindings for Emacs state made to @code{viper-emacs-global-user-map}are @emph{not} inherited by Insert state).For more information on Viper keymaps, see the header of the file@file{viper.el}.If you wish to change a Viper binding, you can use the@code{define-key} command, to modify @code{viper-vi-global-user-map},@code{viper-insert-global-user-map}, and @code{viper-emacs-global-user-map}, asexplained below. Each of these key maps affects the corresponding Viper state.The keymap @code{viper-insert-global-user-map} also affects Viper's Replacestate.@noindentIf you want tobind a key, say @kbd{C-v}, to the function that scrollspage down and to make @kbd{0} display information on the current buffer,putting this in @file{.viper} will do the trick in Vi state:@example(define-key viper-vi-global-user-map "\C-v" 'scroll-down)@end example@noindentTo set a key globally,@example(define-key viper-emacs-global-user-map "\C-c m" 'smail)(define-key viper-vi-global-user-map "0" 'viper-info-on-file)@end example@noindentNote, however, that this binding may be overwritten by other keymaps, sincethe global keymap has the lowest priority.To make sure that nothing will override a binding in Emacs state, youcan write this:@example(define-key viper-emacs-global-user-map "\C-c m" 'smail)@end example@noindentTo customize the binding for @kbd{C-h} in Insert state:@example(define-key viper-insert-global-user-map "\C-h" 'my-del-backwards-function)@end example@noindentEach Emacs command key calls some Lisp function. If you have enabled theHelp, (@pxref{Rudimentary Changes}) @kbd{C-h k} will show you the functionfor each specific key; @kbd{C-h b} will show all bindings, and @kbd{C-h m}will provide information on the major mode in effect. If Help is notenabled, you can still get help in Vi state by prefixing the above commandswith @kbd{\}, e.g., @kbd{\ C-h k} (or you can use the Help menu in themenu bar, if Emacs runs under X).Viper users can also change bindings on a per major mode basis. As withglobal bindings, this can be done separately for each of the three main Viperstates. To this end, Viper provides the function@code{viper-modify-major-mode}.@findex @code{viper-modify-major-mode}To modify keys in Emacs state for @code{my-favorite-major-mode}, the userneeds to create a sparse keymap, say, @code{my-fancy-map}, bind whateverkeys necessary in that keymap, and put@example(viper-modify-major-mode 'dired-mode 'emacs-state my-fancy-map)@end example@noindentin @file{~/.viper}. To do the same in Vi and Insert states, you should use@code{vi-state} and @code{insert-state}. Changes in Insert state are alsoin effect in Replace state. For instance, suppose that the user wants touse @kbd{dd} in Vi state under Dired mode to delete files, @kbd{u} to unmarkfiles, etc. The following code in @file{~/.viper} will then do the job:@example(setq my-dired-modifier-map (make-sparse-keymap))(define-key my-dired-modifier-map "dd" 'dired-flag-file-deletion)(define-key my-dired-modifier-map "u" 'dired-unmark)(viper-modify-major-mode 'dired-mode 'vi-state my-dired-modifier-map)@end exampleA Vi purist may want to modify Emacs state under Dired mode so that@kbd{k}, @kbd{l}, etc., will move around in directory buffers, as inVi. Although this is not recommended, as these keys are bound to usefulDired functions, the trick can be accomplished via the following code:@example(setq my-dired-vi-purist-map (make-sparse-keymap))(define-key my-dired-vi-purist-map "k" 'viper-previous-line)(define-key my-dired-vi-purist-map "l" 'viper-forward-char)(viper-modify-major-mode 'dired-mode 'emacs-state my-dired-vi-purist-map)@end exampleYet another way to customize key bindings in a major mode is to edit thelist @code{viper-major-mode-modifier-list} using the customization widget.@vindex @code{viper-major-mode-modifier-list}(This variable is in the Viper-misc customization group.)The elements of this list are triples of the form: (major-mode viper-statekeymap), where the keymap contains bindings that are supposed to be activein the given major mode and the given viper-state.Effects similar to key binding changes can be achieved by defining Vikeyboard macros using the Ex commands @kbd{:map} and @kbd{:map!}. Thedifference is that multi-key Vi macros do not override the keys they arebound to, unless these keys are typed in quick succession. So, with macros,one can use the normal keys alongside with the macros. If per-modemodifications are needed, the user can try both ways and see which one ismore convenient.@findex @kbd{:map}@xref{Vi Macros}, for details.Note: in major modes that come up in @emph{Emacs state} by default, theaforesaid modifications may not take place immediately (but only after thebuffer switches to some other Viper state and then back to Emacs state). Toavoid this, one should add @code{viper-change-state-to-emacs} to anappropriate hook of that major mode. (Check the function@code{viper-set-hooks} in @file{viper.el} for examples.) However, if youdid not set @code{viper-always} to @code{nil}, chances are that you won'tneed to perform the above procedure, because Viper will take care of mostuseful defaults.Finally, Viper has a facility that lets the user define per-bufferbindings, i.e., bindings that are in effect in some specific buffersonly. Unlike per-mode bindings described above, per-buffer bindings can bedefined based on considerations other than the major mode. This is donevia the function @code{viper-add-local-keys}, which lets one specify bindingsthat should be in effect in the current buffer only and for a specific Viperstate. For instance,@lisp(viper-add-local-keys 'vi-state '(("ZZ" .@: TeX-command-master) ("ZQ" .@: viper-save-kill-buffer)))@end lisp@noindentredefines @kbd{ZZ} to invoke @code{TeX-command-master} in @code{vi-state}and @kbd{ZQ} to save-then-kill the current buffer. These bindings takeeffect only in the buffer where this command is executed. The typical useof this function is to execute the above expression from within a functionthat is included in a hook to some major mode. For instance, the aboveexpressioncould be called from a function, @code{my-tex-init}, which may be added to@code{tex-mode-hook} as follows:@lisp(add-hook 'tex-mode-hook 'my-tex-init)@end lisp@noindentWhen TeX mode starts, the hook is executed and the above Lisp expression isevaluated. Then, the bindings for @kbd{ZZ} and @kbd{ZQ} are changed in Vicommand mode for all buffers in TeX mode.Another useful application is to bind @kbd{ZZ} to @code{send-mail}in the Mail mode buffers (the specifics of this depend on which mailpackage you are using, @code{rmail}, @code{mh-e}, @code{vm}, etc.For instance, here is how to do this for @code{mh-e}, the Emacs interfaceto MH:@lisp(defun mh-add-vi-keys () "Set up ZZ for MH-e and XMH." (viper-add-local-keys 'vi-state '(("ZZ" .@: mh-send-letter))))(add-hook 'mh-letter-mode-hook 'mh-add-vi-keys)@end lispYou can also use @code{viper-add-local-keys} to set per bufferbindings in Insert state and Emacs state by passing as a parameter thesymbols @code{insert-state} and @code{emacs-state}, respectively.As with global bindings, customized local bindings done to Emacs stateare not inherited by Insert state.On rare occasions, local keys may be added by mistake. Usually this is doneindirectly, by invoking a major mode that adds local keys (e.g.,@code{shell-mode} redefines @key{RET}). In such a case, exiting the wrongmajor mode won't rid you from unwanted local keys, since these keys arelocal to Viper state and the current buffer, not to the major mode.In such situations, the remedy is to type @kbd{M-x viper-zap-local-keys}.So much about Viper-specific bindings.@xref{Customization,,Customization,emacs,The GNU EmacsManual}, and the Emacs quick reference card for the general info on keybindings in Emacs.@vindex @code{function-key-map}@vindex @code{viper-vi-global-user-map}@vindex @code{viper-insert-global-user-map}@vindex @code{viper-emacs-global-user-map}@findex @code{viper-add-local-keys}@findex @code{viper-zap-local-keys}@node Packages that Change Keymaps,Viper Specials,Key Bindings,Customization@subsection Packages that Change Keymaps@cindex C-c and Viper@cindex Viper and C-cViper is designed to coexist with all major and minor modes of Emacs. Thismeans that bindings set by those modes are generally available with Viper(unless you explicitly prohibit them by setting@code{viper-want-emacs-keys-in-vi} and @code{viper-want-emacs-keys-in-insert} to@code{nil}).If @code{viper-always} is set to @code{t} (which is the default), Viperwill try to bring each bufferin the Viper state that is most appropriate for that buffer.Usually, this would be the Vi state, but sometimes it could be the Insertstate or the Emacs state.Some major mode bindings will necessarily be overwritten by Viper. Indeed, inVi state, most of the 1-character keys are used for Vi-style editing. Thisusually causes no problems because most packages designed for editing filestypically do not bind such keys. Instead, they use key sequences that startwith @kbd{C-x} and @kbd{C-c}. This is why it was so important for us tofree up @kbd{C-x} and @kbd{C-c}.It is common for language-specific major modes to bind @key{TAB} and@kbd{C-j} (the line feed) keys to various formatting functions. This isextremely useful, but may require some getting used to for a Vi user. If youdecide that this feature is not for you, you can re-bind these keys asexplained earlier (@pxref{Customization}).Binding for @key{TAB} is one of the most unusual aspects of Viper for manynovice users. In Emacs, @key{TAB} is used to format text and programs, andis extremely useful. For instance, hitting @key{TAB} causes the currentline to be re-indented in accordance with the context. In programming,this is very important, since improper automatic indentation wouldimmediately alert the programmer to a possible error. For instance, if a@kbd{)} or a @kbd{"} is missing somewhere above the currentline, @key{TAB} is likely to mis-indent the line.For this reason, Viper doesn't change the standard Emacs binding of@key{TAB}, thereby sacrificing Vi compatibility(except for users at level 1). Instead, in Viper, the key@kbd{S-tab} (shift+ tab) is chosen to emulate Vi's @key{TAB}.We should note that on some non-windowing terminals, Shift doesn't modifythe @key{TAB} key, so @kbd{S-tab} behaves as if it were @key{TAB}. In sucha case, you will have to bind @code{viper-insert-tab} to some otherconvenient key.Some packages, notably Dired, Gnus, Info, etc., attach special meaning tocommon keys like @key{SPC}, @kbd{x}, @kbd{d}, @kbd{v}, and others. Thismeans that Vi command state is inappropriate for working with thesepackages. Fortunately, these modes operate on read-only buffers and aredesigned not for editing files, but for special-purpose browsing, readingnews, mail, etc., and Vi commands are meaningless in these situations. Forthis reason, Viper doesn't force Vi state on such major modes---itbrings them in Emacs state. You can switch to Vi state by typing @kbd{C-z}if, for instance, you want to do Vi-style search in a buffer (although,usually, incremental search, which is bound to @kbd{C-s}, is sufficient inthese situations). But you should then switch back to Emacs state if youplan to continue using these major modes productively. You can also switchto Vi temporarily, to execute just one command. This is done by typing@kbd{C-c \}. (In some of these modes, @kbd{/} and @kbd{:} are boundVi-style, unless these keys perform essential duties.)If you would like certain major modes to come up in Emacs state rather thanVi state (but Viper thinks otherwise), you should put these major modeson the @code{viper-emacs-state-mode-list} list and delete them from@code{viper-vi-state-mode-list}.Likewise, you can force Viper's Insert state on a major mode by putting itin @code{viper-insert-state-mode-list}.@vindex @code{viper-emacs-state-mode-list}@vindex @code{viper-insert-state-mode-list}@vindex @code{viper-vi-state-mode-list}It is also possible to impose Vi on some major modes, even though they maybind common keys to specialized commands. This might make sense for modesthat bind only a small number of common keys. For instance, Viper subvertsthe Shell mode by changing the bindings for @kbd{C-m} and @kbd{C-d} using@code{viper-add-local-keys} described in the section on customization(@pxref{Customization}).In some cases, some @emph{minor} modes might override certain essentialbindings in Vi command state. This is not a big problem because thiscan happen only in the beginning, when the minor mode kicks in. Typing@code{M-x viper-mode} will correct the situation. Viper knows aboutseveral such minor modes and takes care of them, so the above trickis usually not necessary. If you find that some minor mode, e.g.,@code{nasty-mode} interferes with Viper, putting the following in@file{.viper} should fix the problem:@lisp(viper-harness-minor-mode "nasty-mode")@end lisp@noindentThe argument to @code{viper-harness-minor-mode} is the name of the file for theoffending minor mode with the suffixes @file{.el} and @file{.elc} removed.It may not be always obvious which minor mode is at fault. The onlyguidance here is to look into the file that defines the minor mode you aresuspecting, say @file{nasty-mode.el}, and see if it has a variable called@code{nasty-mode-map}. Then check if there is a statement of the form@lisp(define-key nasty-mode-map key function)@end lisp@noindentthat binds the misbehavingkeys. If so, use the above line to harness @code{nasty-mode}. If yoursuspicion is wrong, no harm is done if you harness a minor mode thatdoesn't need to be harnessed.It is recommended to harness even those minor modes that don't overrideViper keys, but still have their own keymaps. A general way tomake a minor mode, @code{my-mode},compatible with Viper is to have the file @file{my-mode.el} include the following code:@lisp(when (fboundp 'viper-harness-minor-mode) (let ((lib (file-name-sans-extension (file-name-nondirectory load-file-name)))) (viper-harness-minor-mode lib)))@end lisp@vindex @code{viper-want-emacs-keys-in-vi}@vindex @code{viper-want-emacs-keys-in-insert}@vindex @code{viper-always}@findex @code{viper-set-hooks}@findex @code{viper-mode}@findex @code{viper-harness-minor-mode}@findex @code{remove-hook}@findex @code{add-hook}@node Viper Specials,Vi Macros,Packages that Change Keymaps,Customization@section Viper SpecialsViper extends Vi with a number of useful features. This includes varioussearch functions, histories of search strings, Ex commands, insertions, andVi's destructive commands. In addition, Viper supports file name completionand history, completion of Ex commands and variables, and many otherfeatures. Some of these features are explained in detail elsewhere in thisdocument. Other features are explained here.@table @code@item (viper-buffer-search-enable)@item viper-buffer-search-char nilEnable buffer search. Explicit call to @code{viper-buffer-search-enable}sets @code{viper-buffer-search-char} to @kbd{g}. Alternatively, the user canset @code{viper-buffer-search-char} in @file{.viper} to a key sequenceto be used for buffer search. There is no need to call@code{viper-buffer-search-enable} in that case.@findex @code{viper-buffer-search-enable}@vindex @code{viper-buffer-search-char}@item viper-toggle-search-styleThis function, bound to @kbd{C-c /}, lets one toggle case-sensitive andcase-insensitive search, and also switch between plain vanilla search andsearch via regular expressions. Without the prefix argument, the user isasked which mode to toggle. With prefix argument 1, this togglescase-sensitivity. With prefix argument 2, regular expression/vanilla searchwill be toggled.However, we found that the most convenient way to togglethese options is to bind a Vi macro tobind @kbd{//} to toggles case sensitivity and to @kbd{///} to togglesvanilla search. Thus, quickly hitting @kbd{/} twice will switch Viper fromcase sensitive search to case-insensitive. Repeating this once again willrestore the original state. Likewise, quickly hitting @kbd{/} three timeswill switch you from vanilla-style search to search via regular expressions.If you hit something other than @kbd{/} after the first @kbd{/} or if thesecond @kbd{/} doesn't follow quickly enough, then Viper will issue theusual prompt @kbd{/} and will wait for input, as usual in Vi.If you don't like this behavior, you can ``unrecord'' these macros in your@file{~/.viper} file. For instance, if you don't like the above feature, putthis in @file{~/.viper}:@example(viper-set-searchstyle-toggling-macros 'undefine)@end example@findex @code{viper-set-searchstyle-toggling-macros}If you don't like this feature as a default, but would still like to haveit in some major modes, you can do so by first unsetting it globally, asshown above, and then setting it in the desired major modes as follows:@example(viper-set-searchstyle-toggling-macros nil 'c-mode)(viper-set-searchstyle-toggling-macros nil 'lisp-mode)@end example@item Vi-isms in Emacs stateSome people find it useful to use the Vi-style search key, `/', to invokesearch in modes which Viper leaves in emacs-state. These modes are:@code{dired-mode}, @code{mh-folder-mode},@code{Info-mode}, and @code{Buffer-menu-mode}(more may be added in the future). So, in the above modes, Viper binds `/'so that it will behave Vi-style. Furthermore, in those major modes, Viperbinds `:' to invoke ex-style commands, like in vi-state. And, as describedabove, `//' and `///' get bound to Vi-style macros that togglecase-insensitivity and regexp-search.If you don't like these features---which I don't really understand---youcan unbind `/' and `:' in @code{viper-dired-modifier-map} (for Dired) or in@code{viper-slash-and-colon-map}, for other modes.@vindex @code{viper-slash-and-colon-map}@vindex @code{viper-dired-modifier-map}To unbind the macros `//' and `///' for a major mode where you feel theyare undesirable, execute @code{viper-set-emacs-state-searchstyle-macros} with anon-@code{nil} argument. This can be done either interactively, by supplying aprefix argument, or by placing@example(viper-set-emacs-state-searchstyle-macros 'undefine)@end example@findex @code{viper-set-emacs-state-searchstyle-macros}in the hook to the major mode (e.g., @code{dired-mode-hook}).@xref{Vi Macros}, for more information on Vi macros.@item viper-heading-start@item viper-heading-end@cindex headings@cindex sections@cindex paragraphs@cindex sentencesRegular Expressions for @kbd{[[} and @kbd{]]}. Note that Emacs definesRegexps for paragraphs and sentences. @xref{Paragraphs,,Paragraphs andSentences,emacs,The GNU Emacs Manual}, for details.@item M-x viper-set-expert-level@findex @code{viper-set-expert-level}Change your user level interactively.@item viper-smart-suffix-list '("" "tex" "c" "cc" "el" "p")@vindex @code{viper-smart-suffix-list}Viper supports Emacs-style file completion when it prompts the user for afile name. However, in many cases, the same directory may contain fileswith identical prefix but different suffixes, e.g., prog.c, prog.o,paper.tex, paper.dvi. In such cases, completion will stop at the `.'.If the above variable is a list of strings representing suffixes, Viper willtry these suffixesin the order listed and will check if the corresponding file exists.For instance, if completion stopped at `paper.'@: and the user typed@key{RET},then Viper will check if the files `paper.', `paper.tex', `paper.c', etc., exist.It will take the first such file. If no file exists, Viper will give a chanceto complete the file name by typing the appropriate suffix. If `paper.'@: wasthe intended file name, hitting return will accept it.To turn this feature off, set the above variable to @code{nil}.@item viper-insertion-ring-size 14@vindex @code{viper-insertion-ring-size}@cindex Insertion ringViper remembers what was previously inserted in Insert and Replace states.Several such recent insertions are kept in a special ring of strings of size@code{viper-insertion-ring-size}.If you enter Insert or Replace state you can reinsert strings from thisring by typing @kbd{C-c M-p} or @kbd{C-c M-n}. The former will search thering inthe direction of older insertions, and the latter will search inthe direction of newer insertions. Hitting @kbd{C-c M-p} or @kbd{C-c M-n}in successionwill undo the previous insertion from the ring and insert the next item onthe ring. If a larger ring size is needed, change the value of the abovevariable in the @file{~/.viper} file.Since typing these sequences of keys may be tedious, it is suggested that theuser should bind a function key, such as @kbd{f31}, as follows:@example(define-key viper-insert-global-user-map [f31] 'viper-insert-prev-from-insertion-ring)@end exampleThis binds @kbd{f31} (which is usually @kbd{R11} on a Sun workstation)to the function that inserts the previous string in the insertion history.To rotate the history in the oppositedirection, you can either bind an unused key to@code{viper-insert-next-from-insertion-ring} or hit any digit (1 to 9) then@kbd{f31}.One should not bind the above functions to @kbd{M-p} or @kbd{M-n}, sincethis will interfere with the Minibuffer histories and, possibly, othermajor modes.@item viper-command-ring-size 14@vindex @code{viper-command-ring-size}@cindex Destructive command ring@cindex Destructive command historyViper keeps track of the recent history of destructivecommands, such as @kbd{dw}, @kbd{i}, etc.In Vi state,the most recent command can be re-executed by hitting `@kbd{.}', as in Vi.However, repeated typing @kbd{C-c M-p} will cause Viper to show theprevious destructive commands in the minibuffer. Subsequent hitting `@kbd{.}'will execute the command that was displayed last.The key @kbd{C-c M-n} will cycle through the command history in theopposite direction.Since typing @kbd{C-c M-p} may be tedious, it is more convenient to bind anappropriate function to an unused function key on the keyboard and use thatkey. For instance, the following@example(define-key viper-vi-global-user-map [f31] 'viper-prev-destructive-command)@end examplebinds the key @kbd{f31} (which is usually @kbd{R11} on a Sun workstation)to the function that searches the command history in the direction of oldercommands. To search in the oppositedirection, you can either bind an unused key to@code{viper-next-destructive-command} or hit any digit (1 to 9) then @kbd{f31}.One should not bind the above functions to @kbd{M-p} or @kbd{M-n}, sincethis will interfere with the Minibuffer histories and, possibly, othermajor modes.@item viper-minibuffer-vi-face 'viper-minibuffer-vi-face@item viper-minibuffer-insert-face 'viper-minibuffer-insert-face@item viper-minibuffer-emacs-face 'viper-minibuffer-emacs-faceThese faces control the appearance of the minibuffer text in thecorresponding Viper states. You can change the appearance of these facesthrough Emacs' customization widget, which is accessible through themenubar.Viper is located in this widget under the @emph{Emulations} customizationsubgroup of the @emph{Editing} group. All Viper faces are grouped togetherin Viper's @emph{Highlighting} customization subgroup.Note that only the text you type in is affected by the above faces.Prompts and Minibuffer messages are not affected.Purists who do not like adornments in the minibuffer can always zap them byputting@example(copy-face 'default 'viper-minibuffer-vi-face)(copy-face 'default 'viper-minibuffer-insert-face)(copy-face 'default 'viper-minibuffer-emacs-face)@end examplein the @file{~/.viper} file or through the customization widget, asdescribed above. However, in that case, the user will not have anyindication of the current Viper state in the minibuffer. (This is importantif the user accidentally switches to another Viper state by typing @key{ESC} or@kbd{C-z}).@item M-x viper-go-away@findex @code{viper-go-away}Make Viper disappear from the face of your running Emacs instance. If yourfingers start aching again, @kbd{M-x viper-mode} might save your day.@item M-x toggle-viper-mode@findex @code{toggle-viper-mode}Toggle Viperization of Emacs on and off.@end table@cindex Multifile documents and programsViper provides some support for multi-file documents and programs.If a document consists of several files we can designate one of them as amaster and put the following at the end of that file:@lisp;; Local Variables:;; eval: (viper-setup-master-buffer "file1" "file2" "file3" "file4");; End:@end lisp@noindentwhere @code{file1} to @code{file4} are names of files related to the masterfile. Next time, when the master file is visited, the command@code{viper-setup-master-buffer} will be evaluated and the above files willbe associated with the master file. Then, the new Ex command@kbd{:RelatedFile} (abbr.@: @kbd{:R}) will display files 1 to 4 one afteranother, so you can edit them. If a file is not in any Emacs buffer, itwill be visited. The command @kbd{PreviousRelatedFile} (abbr., @kbd{:P})goes through the file list in the opposite direction.@findex @kbd{:RelatedFile}@findex @kbd{:PreviousRelatedFile}These commands are akin to @kbd{:n} and @kbd{:N}, but they allow the user tofocus on relevant files only.Note that only the master file needs to have the aforementioned block ofcommands. Also, ";;" above can be replaced by some othermarkers. Semicolon is good for Lisp programs, since it is considered acomment designator there. For LaTeX, this could be "%%%", and for C theabove block should be commented out.Even though these commands are sometimes useful, they are no substitute forthe powerful @emph{tag table} facility of Emacs. Viper's @kbd{:tag} commandin a primitive interface to Emacs tags. @xref{Tags,Tags,Tags,emacs,The GNU Emacs Manual}, for more information on tags.The following two commands are normally bound to a mouse click and are partof Viper. They work only if Emacs runs as an application under XWindows (or under some other window system for which a port of GNU Emacs 20is available). Clicking the mouse when Emacs is invoked in an Xterm window(using @code{emacs -nw}) will do no good.@table @code@cindex mouse@cindex mouse-search@item viper-mouse-search-key (meta shift 1)@vindex @code{viper-mouse-insert-key}This variable controls the @emph{mouse-search} feature of Viper. Thedefault valuestates that holding Meta and Shift keys while clicking mouse button 1should initiate search for a region under the mouse pointer (definedbelow). This command can take a prefix argument, which indicates theoccurrence of the pattern to search for.Note: while loading initially, Viper binds this mouse action only if it isnot already bound to something else. If you want to use the mouse-searchfeature, and the @kbd{Meta-Shift-Mouse-1} mouse action is already bound tosomething else, you can rebind the mouse-search feature by setting@code{viper-mouse-search-key} to something else in your @code{~/.viper}file:@lisp(setq viper-mouse-search-key '(meta 1))@end lispThis would bind mouse search to the action invoked by pressing theMeta key and clicking mouse button 1. The allowed values of@code{viper-mouse-search-key} are lists that contain a mouse-button number(1,2, or 3) and any combination of the words `control', `meta', and`shift'.If the requested mouse action (e.g., (meta 1)) is already taken for otherpurposes then you have to confirm your intention by placing the followingcommand in @code{~/.viper} after setting @code{viper-mouse-search-key}:@lisp(viper-bind-mouse-search-key 'force)@end lispYou can also change this setting interactively, through the customizationwidget of Emacs (type @kbd{:customize}).The region that is chosen as a pattern to search for is determined asfollows. If search is invoked via a single click, Viper chooses the regionthat lies between the beginning of the ``word'' under the pointer (``word''is understood in Vi sense) and the end of that word. The only differencewith Vi's words is that in Lisp major modes `-' is considered analphanumeric symbol. This is done for the convenience of working with Lispsymbols, which often have an `-' in them. Also, if you click on anon-alphanumeric character that is not a word separator (in Vi sense) thenthis character will also be considered alphanumeric, provided that it isadjacent (from either side) to an alphanumeric character. This usefulfeature gives added control over the patterns selected by the mouse click.On a double-click, the region is determined by the beginning of the currentVi's ``Word'' (i.e., the largest non-separator chunk of text) and the Endof that ``Word'' (as determined by the @kbd{E} command).On a triple-click, the region consists of the entire line where the clickoccurred with all leading and trailing spaces and tabs removed.@cindex mouse-insert@item viper-mouse-insert-key (meta shift 2)@vindex @code{viper-mouse-insert-key}This variable controls the @emph{mouse-insert} feature of Viper.The above default value states thatholding Meta and Shift keys while clicking mouse button 2should insert the region surrounding themouse pointer. The rules defining this region are the same as formouse-search. This command takes an optional prefix argument, whichindicates how many such regions to snarf from the buffer and insert. (Incase of a triple-click, the prefix argument is ignored.)Note: while loading initially, Viper binds this mouse action only if it notalready bound to something else. If you want to use this feature and thedefault mouse action is already bound, you can rebind mouse-insert byplacing this command in @code{~/.viper}:@lisp(setq viper-mouse-insert-key '(meta 2))@end lispIf you want to bind mouse-insert to an action even if this action isalready taken for other purposes in Emacs, then you should add this commandto @code{~/.viper}, after setting @code{viper-mouse-insert-key}:@lisp(viper-bind-mouse-insert-key 'force)@end lispThis value can also be changed via the Emacs customization widget at themenubar.@item viper-multiclick-timeoutThis variable controls the rate at which double-clicking must occur for thepurpose of mouse search and mouse insert. By default, this is set to@code{double-click-time} in Emacs and to@code{mouse-track-multi-click-time} milliseconds in XEmacs.@end table@kindex @kbd{S-Mouse-1}@kindex @kbd{S-Mouse-2}@kindex @kbd{meta shift button1up}@kindex @kbd{meta shift button2up}@vindex @code{viper-multiclick-timeout}@findex @code{viper-mouse-click-insert-word}@findex @code{viper-mouse-click-search-word}Note: The above functions search and insert in the selected window ofthe latest active frame. This means that you can click in another window oranother frame and have search or insertion done in the frame and window youjust left. This lets one use these functions in a multi-frameconfiguration. However, this may require some getting used to. Forinstance, if you are typing in a frame, A, and then move the mouse to frameB and click to invoke mouse search, search (or insertion) will be performedin frame A. To perform search/insertion in frame B, you will first have toshift focus there, which doesn't happen until you type a character orperform some other action in frame B---mouse search doesn't shift focus.If you decide that you don't like the above feature and always wantsearch/insertion be performed in the frame where the click occurs, don'tbind (and unbind, if necessary) @code{viper-mouse-catch-frame-switch} fromthe mouse event it is bound to.Mouse search is integrated with Vi-style search, so you canrepeat it with @kbd{n} and @kbd{N}. It should be also noted that, whilecase-sensitivity of search in Viper is controlled by the variable@code{viper-case-fold-search}, the case of mouse search iscontrolled by the Emacs variable @code{case-fold-search}, which may be setdifferently from @code{viper-case-fold-search}. Therefore, case-sensitivityof mouse search may be different from that of the usual Vi-style search.Finally, if the way Viper determines the word to be searched for or to beinserted is not what you want, there is a variable,@code{viper-surrounding-word-function}, which can be changed to indicateanother function for snarfing words out of the buffer. The catch is thatyou will then have to write such a function and make it known to yourEmacs. The function @code{viper-surrounding-word} in @file{viper.el} can beused as a guiding example.@node Vi Macros, ,Viper Specials,Customization@section Vi Macros@cindex Vi macrosViper supports much enhanced Vi-style macros and also facilitates the useof Emacs-style macros. To define a temporary macro, it is generally moreconvenient to use Emacs keyboard macro facility. Emacs keyboard macros areusually defined anonymously, and the latest macro can be executed by typing@kbd{C-x e} (or @kbd{*}, if Viper is in Vi state). If you need to use severaltemporary macros, Viper lets you save them to aregister (a lowercase letter); such macros can then be executed by typing@kbd{@@a} in Vi state (if a macro was previously saved in register@kbd{a}).@xref{Macros and Registers}, for details.If, however, you need to use a macro regularly, it must be given apermanent name and saved. Emacs manual explains how to do this, butinvocation of named Emacs macros is quite different from Vi's. First,invocation of permanent Emacs macros takes time because it requires typingtoo many keys (to a Vi user's taste, anyway).Second, binding such macros to function keys, forfast access, hogs valuable real estate on the keyboard.Vi-style macros are better in that respect, since Vi lets the user overloadthe meaning of key sequences: keys typed in fast succession are treatedspecially, if this key sequence is bound to a macro.Viper provides Vi-style keyboard macros through the usual Ex commands,@kbd{:map} and@kbd{:map!}. These macros are much more powerful in Viper thanthey are in the original Vi and in other emulators. This is because Viperimplements an enhanced vi-styleinterface to the powerful Emacs keyboard macro facility.First, any Emacscommand can be executed while defining a macro, not just the Vicommands. In particular, the user can invoke Emacs commands via @kbd{M-xcommand-name} or by pressing various function keys on the keyboard. Onecan even use the mouse, although this is usually not useful and is notrecommended (and macros defined with the use of the mouse cannot be saved incommand history and in the startup file, for future use).Macros defined by mixing Vi and Emacs commands are represented asvectors. So, don't be confused when you see one (usually through thehistory of Ex commands). For instance, if @kbd{gg} is defined by typing@kbd{l}, the up-arrow key and @kbd{M-x next-line}, its definition will lookas follows in Emacs:@example[l up (meta x) n e x t - l i n e return]@end exampleSecond, Viper macros are defined in a WYSIWYG style. This means thatcommands are executed as you type them, so you can see precisely what isbeing defined. Third, macros can be bound to arbitrary sequences of keys,not just to printable keys. For instance, one can define a macro that willbe invoked by hitting @kbd{f3} then @kbd{f2} function keys. (The keys@kbd{delete} and @kbd{backspace} are excluded; also, a macro invocationsequence can't start with @key{ESC}. Some other keys, such as @kbd{f1} and@kbd{help}, can't be bound to macros under Emacs, since theyare bound in @code{key-translation-map}, which overrides any other bindingthe user gives to keys. In general, keys that have a binding in@code{key-translation-map} can't be bound to a macro.)Fourth, in Viper, one can define macros that are specific to a givenbuffer, a given major mode, or macros that are defined for all buffers. Infact, the same macro name can have several different definitions: oneglobal, several definitions for various major modes, anddefinitions for various specific buffers. Buffer-specific definitionsoverride mode-specific definitions, which, in turn, override globaldefinitions.As if all that is not enough, Viper (through its interface to Emacsmacros) lets the user define keyboard macros that ask for confirmation oreven prompt the user for input and then continue. To do this, one shouldtype @kbd{C-x q} (for confirmation) or @kbd{C-u C-x q} (for prompt).For details, @pxref{Keyboard Macro Query,,Customization,emacs,The GNU EmacsManual} @refillWhen the user finishes defining a macro (which is done by typing @kbd{C-x)} ---a departure from Vi), you will be asked whether you want thismacro to be global, mode-specific, or buffer-specific. You will also begiven a chance to save the macro in your @file{~/.viper} file.This is the easiest way to save a macro and makeit permanently available. If you work your startup files with bare hands,here is how Viper saves the above macro so that it will beavailable in Viper's Insert state (and Replace state) in buffer @code{my-buf}only:@example(viper-record-kbd-macro "gg" 'insert-state [l up (meta x) n e x t - l i n e return] "my-buf")@end example@noindentTo do the same for Vi state and all buffers with the major mode@code{cc-mode}, use:@example(viper-record-kbd-macro "gg" 'vi-state [l up (meta x) n e x t - l i n e return] 'cc-mode)@end example@noindentBoth macro names and macro definitions are vectors of symbols that denotekeys on the keyboard. Some keys, like @kbd{\}, @kbd{ }, or digit-keys mustbe escaped with a backslash. Modified keys are represented as lists. Forinstance, holding Meta and Control and pressing @kbd{f4} is represented as@kbd{(control meta f4)}.If all members of a vectors are printable characters (or sequences, such as@kbd{\e}, @kbd{\t}, for @key{ESC} and @key{TAB}), then they can also be represented asstrings:@example(viper-record-kbd-macro "aa" 'vi-state "aaa\e" "my-buffer")@end example@noindentThus, typing @kbd{aa} fast in Vi state will switch Viper to Insert state(due to the first @kbd{a}), insert @kbd{aa}, and then it will switch back to Vistate. All this will take effect only in the buffer named @code{my-buffer}.Note that the last argument to @code{viper-record-kbd-macro} must be either astring (a buffer name), a symbol representing a major mode, or @code{t};the latter says that the macro is to be defined for all buffers(which is how macros are defined in original Vi).For convenience, Viper also lets you define Vi-style macros in its Emacsstate. There is no Ex command, like @kbd{:map} and @kbd{:map!} for doingthis, but the user can include such a macro in the @file{~/.viper} file. Theonly thing is that the @code{viper-record-kbd-macro} command should specify@code{emacs-state} instead of @code{vi-state} or @code{insert-state}.The user can get rid of a macro either by using the Ex commands @kbd{:unmap}and @kbd{:unmap!} or by issuing a call to @code{viper-unrecord-kbd-macro}.The latter is more powerful, since it can delete macros even in@code{emacs-state}. However, @code{viper-unrecord-kbd-macro} is usuallyneeded only when the user needs to get rid of the macros that are alreadypredefined in Viper.The syntax is:@findex @code{viper-unrecord-kbd-macro}@example(viper-unrecord-kbd-macro macro state)@end example@noindentThe second argument must be @code{vi-state}, @code{insert-state}, or@code{emacs-state}. The first argument is a name of a macro. To avoidmistakes in specifying names of existing macros, type @kbd{M-xviper-describe-kbd-macros} and use a name from the list displayed by thiscommand.If an error occurs during macro definition, Emacsaborts the process, and it must be repeated. This is analogous to Vi,except that in Vi the user doesn't know there is an error until the macro isactually run. All that means that in order for a definition to besuccessful, the user must do some simple planning of the process inadvance, to avoid errors. For instance, if you want to map @kbd{gg} to@kbd{llll} in Vi state, you must make sure that there is enough room on thecurrent line. Since @kbd{l} moves the cursor forward, it may signal anerror on reaching the end of line, which will abort the definition.These precautions are necessary only when defining macros; they will helpavoid the need to redo the job. When macros are actually run, an errorduring the execution will simply terminate the current execution(but the macro will remain mapped).A macro name can be a string of characters or a vector of keys.The latter makes it possible to define macros bound to, say, double-hitson a function key, such as @kbd{up} or @kbd{f13}.This is very useful if you run out of function keys on your keyboard; itmakes Viper macro facility a @emph{keyboard doubler}, so to speak.Elsewhere (@xref{Key Bindings}, for details), we reviewthe standard Emacs mechanism for binding function keys to commands.For instance,@example(global-set-key [f13] 'repeat-complex-command)@end example@noindentbinds the key f13 to the Emacs function that repeats the last minibuffercommand. Under Viper, however, you may still use this key for additionalpurposes, if you bind, say, a double-hitting action for that key to someother function. Emacs doesn't allow the user to do that, but Viper doesthis through its keyboard macro facility. To do this, type @kbd{:map }first. When you are asked to enter a macro name, hit f13 twice, followed by@key{RET} or @key{SPC}.Emacs will now start the mapping process by actually executingVi and Emacs commands, so that you could see what will happen each time themacro is executed. Suppose now we wanted to bind the key sequence@kbd{f13 f13} to the command @code{eval-last-sexp}. To accomplish this, wecan type @kbd{M-x eval-last-sexp} followed by @kbd{C-x )}.If you answer positively to Viper's offer to save this macro in @file{~/.viper}for future uses, the following will be inserted in that file:@example(viper-record-kbd-macro [f16 f16] 'vi-state [(meta x) e v a l - l a s t - s e x p] 'lisp-interaction-mode)@end exampleTo illustrate the above point, Viper provides two canned macros, which, bydefault, are bound to @kbd{[f12 \1]} and @kbd{[f12 \2]} (invoked by typing@kbd{f12} then @kbd{1} and @kbd{2}, respectively). These macros are usefulshortcuts to Viper's command ring history. The first macro will execute thesecond-last destructive command (the last one is executed by @kbd{.}, asusual). The second macro executes the third-last command.If you need to go deeper into the command history, you will have to useother commands, as described earlier in this section; or you can bind,say, @kbd{f12 \3} like this:@example(viper-record-kbd-macro [f12 \3] 'vi-state [(meta x) r e p e a t - f r o m - h i s t o r y] t)@end exampleNote that even though the macro uses the function key @kbd{f12}, the key isactually free and can still be bound to some Emacs function via@code{define-key} or @code{global-set-key}.Viper allows the user to define macro names that are prefixes of other macros.For instance, one can define @kbd{[[} and @kbd{[[[[} to be macros.If you type the exact sequence of such keys and then pause, Viper willexecute the right macro. However, if you don't pause and, say, type@kbd{[[[[text} then the conflict is resolved as follows. If only one of thekey sequences, @kbd{[[} or @kbd{[[[[} has a definition applicable to thecurrent buffer, then, in fact, there is no conflict and the right macrowill be chosen. If both have applicable definitions, then the first onefound will be executed. Usually this is the macro with a shorter name. So,in our case, @kbd{[[[[text} will cause the macro @kbd{[[} to be executedtwice and then the remaining keys, @kbd{t e x t}, will be processed.When defining macros using @kbd{:map} or @kbd{:map!}, the user entersthe actually keys to be used to invoke the macro. For instance, youshould hit the actual key @kbd{f6} if it is to be part of a macroname; you do @emph{not} write @kbd{f 6}. When entering keys, Viperdisplays them as strings or vectors (e.g., @code{"abc"} or @code{[f6f7 a]}). The same holds for unmapping. Hitting @key{TAB} whiletyping a macro name in the @kbd{:unmap} or @kbd{:unmap!} command willcause name completion. Completions are displayed as strings orvectors. However, as before, you don't actually type @samp{"},@samp{[}, or @samp{]} that appear in the completions. These aremeta-symbols that indicate whether the corresponding macro name is avector or a string.One last difference from Vi: Vi-style keyboard macros cannot be defined interms of other Vi-style keyboard macros (but named Emacs macros are OK).More precisely, while defining or executing a macro, the special meaningof key sequences (as Vi macros) is ignored.This is because it is all too easy to create an infinite loop in this way.Since Viper macros are much more powerful than Vi's it is impossible todetect such loops. In practice, this is not really a limitation but,rather, a feature.We should also note that Vi macros are disabled in the Minibuffer, whichhelps keep some potential troubles away.The rate at which the user must type keys in order for them to berecognized as a timeout macro is controlled by the variable@code{viper-fast-keyseq-timeout}, which defaults to 200 milliseconds.For the most part, Viper macros defined in @file{~/.viper} can be sharedbetween X and TTY modes.The problem with TTY may be that the function keys there generate sequencesof events instead of a single event (as under a window system).Emacs maps some of these sequences back to the logical keys(e.g., the sequences generated by the arrow keys are mapped to @kbd{up},@kbd{left}, etc.). However, not all function keys are mapped in this way.Macros that are bound to key sequences that contain such unmapped functionkeys have to be redefined for TTY's (and possibly for every type of TTY youmay be using). To do this, start Emacs on an appropriate TTY device anddefine the macro using @kbd{:map}, as usual.@findex @code{viper-describe-kbd-macros}Finally, Viper provides a function that conveniently displays all macroscurrently defined. To see all macros along with their definitions, type@kbd{M-x viper-describe-kbd-macros}.@node Commands,,Customization,Top@chapter CommandsThis section is a semi-automatically bowdlerized version of the Vireference created by @* @samp{maart@@cs.vu.nl} and others. It can befound on the Vi archives. This reference has been adapted for Viper.@refill@menu* Groundwork:: Textual Conventions and Viper basics* Text Handling:: Moving, Editing, Undoing.* Display:: Scrolling.* File and Buffer Handling:: Editing, Writing and Quitting.* Mapping:: Mapping Keys, Keyboard Macros* Shell Commands:: Accessing Shell Commands, Processing Text* Options:: Ex options, the @kbd{:set} commands* Emacs Related Commands:: Meta Keys, Windows* Mouse-bound Commands:: Search and insertion of text@end menu@node Groundwork, Text Handling, Commands, Commands@comment node-name, next, previous, up@section GroundworkThe VI command set is based on the idea of combining motion commandswith other commands. The motion command is used as a text regionspecifier for other commands.We classify motion commands into @dfn{point commands} and@dfn{line commands}.@refill@cindex point commandsThe point commands are:@quotation@kbd{h}, @kbd{l}, @kbd{0}, @kbd{$}, @kbd{w}, @kbd{W}, @kbd{b}, @kbd{B},@kbd{e}, @kbd{E}, @kbd{(}, @kbd{)}, @kbd{/}, @kbd{?}, @kbd{`}, @kbd{f},@kbd{F}, @kbd{t}, @kbd{T}, @kbd{%}, @kbd{;}, @kbd{,}, @kbd{^}@end quotation@cindex line commandsThe line commands are:@quotation@kbd{j}, @kbd{k}, @kbd{+}, @kbd{-}, @kbd{H}, @kbd{M}, @kbd{L}, @kbd{@{},@kbd{@}}, @kbd{G}, @kbd{'}, @kbd{[[}, @kbd{]]}, @kbd{[]}@end quotation@noindentText Deletion Commands (@pxref{Deleting Text}), Change commands(@pxref{Changing Text}), even Shell Commands (@pxref{Shell Commands})use these commands to describe a region of text to operate on.@cindex r and R region specifiersViper adds two region descriptors, @kbd{r} and @kbd{R}. These describethe Emacs regions (@pxref{Basics}), but they are not movement commands.The command description uses angle brackets @samp{<>} to indicatemetasyntactic variables, since the normal conventions of using simpletext can be confusing with Viper where the commands themselves arecharacters. Watch out where @kbd{<} shift commands and @kbd{<count>} arementioned together!!!@kindex <move>@kindex <a-z>@kindex <address>@cindex <move>@cindex <a-z>@cindex <address>@cindex movements@samp{<move>} refers to the above movement commands, and @samp{<a-z>}refers to registers or textmarkers from @samp{a} to @samp{z}. Notethat the @samp{<move>} is described by full move commands, that is tosay they will take counts, and otherwise behave like normal move commands.@cindex Ex addresses@samp{<address>} refers to Ex line addresses, which include@table @kbd@item .@: <No address>Current line@item .+n .-nAdd or subtract for current line@item numberActual line number, use @kbd{.=} to get the line number@item '<a-z>Textmarker@item $Last line@item x,yWhere x and y are one of the above@item %@cindex % (Ex address)For the whole file, same as (1,$).@item /<pat>/@itemx ?<pat>?Next or previous line with pattern <pat>.Note that the pattern is allowed to contain newline character (inserted as@kbd{C-qC-j}). Therefore, one can search for patterns that span severallines.@end table@cindex % (Current file)Note that @samp{%} is used in Ex commands @kbd{:e} and @kbd{:r <shell-cmd>}to mean current file. If you want a @samp{%} in your command, it must beescaped as @samp{\%}. Note that @kbd{:w} and the regular @kbd{:r <file>}command doesn't support the meta symbols @samp{%} and @samp{#}, becausefile history is a better mechanism.@cindex # (Previous file)Similarly, @samp{#} expands to the previous file. The previous file isthe first file in @kbd{:args} listing. This defaults to previous windowin the VI sense if you have one window only.@kindex <args>@kindex <cmd>@cindex <args>@cindex <cmd>@noindentOthers like @samp{<args> -- arguments}, @samp{<cmd> -- command} etc.should be fairly obvious.@noindentCommon characters referred to include:@table @kbd@item <sp>Space@item <ht>Tab@item <lf>Linefeed@item <esc>Escape@item <cr>Return, Enter@end table@cindex <cr>@cindex <esc>@cindex <lf>@cindex <ht>@cindex <sp>@cindex words@cindex WORDS@cindex char@cindex CHARWe also use @samp{word} for alphanumeric/non-alphanumeric words, and@samp{WORD} for whitespace delimited words. @samp{char} refers to any@acronym{ASCII} character, @samp{CHAR} to non-whitespace character.Brackets @samp{[]} indicate optional parameters; @samp{<count>} alsooptional, usually defaulting to 1. Brackets are elided for@samp{<count>} to eschew obfuscation.Viper's idea of Vi's words is slightly different from Vi. First, Viperwords understand Emacs symbol tables. Therefore, all symbols declared to bealphanumeric in a symbol table can automatically be made part of the Viperword. This is useful when, for instance, editing text containing European,Cyrillic, Japanese, etc., texts.Second, Viper lets you depart from Vi's idea of a word by changing the asyntax preference via the customization widget (the variable@code{viper-syntax-preference}) or by executing@code{viper-set-syntax-preference} interactively.By default, Viper syntax preference is @code{reformed-vi}, which means thatViper considers only those symbols to be part of a word that are specifiedas word-symbols by the current Emacs syntax table (which may be differentfor different major modes) plus the underscore symbol @kbd{_}, minus thesymbols that are not considered words in Vi (e.g., `,',;, etc.), but may beconsidered as word-symbols by various Emacs major modes. Reformed-Vi worksvery close to Vi, and it also recognizes words in otheralphabets. Therefore, this is the most appropriate mode for editing textand is likely to fit all your needs.You can also set Viper syntax preference to @code{strict-vi}, which wouldcause Viper to view all non-English letters as non-word-symbols.You can also specify @code{emacs} as your preference, which wouldmake Viper use exactly the same notion of a word as Emacs does. Inparticular, the underscore may not be part of a word in some major modes.Finally, if @code{viper-syntax-preference} is set to @code{extended}, Viperwords would consist of characters that are classified as alphanumeric@emph{or} as parts of symbols. This is convenient for editing programs.@code{viper-syntax-preference} is a local variable, so it can have differentvalues for different major modes. For instance, in programming modes it canhave the value @code{extended}. In text modes where words contain specialcharacters, such as European (non-English) letters, Cyrillic letters, etc.,the value can be @code{reformed-vi} or @code{emacs}.If you consider using different syntactic preferences for different majormodes, you should execute, for example,@example(viper-set-syntax-preference nil "extended")@end examplein the appropriate major mode hooks.@vindex @code{viper-syntax-preference}@findex @code{viper-set-syntax-preference}@cindex syntax tableThe above discussion concerns only the movement commands. In regularexpressions, words remain the same as in Emacs. That is, the expressions@code{\w}, @code{\>}, @code{\<}, etc., use Emacs' idea of what is a word,and they don't look into the value of variable@code{viper-syntax-preference}. This is because Viper avoids changingsyntax tables in order to not thwart the various major modes that set thesetables.The usual Emacs convention is used to indicate Control Characters, i.eC-h for Control-h. @emph{Do not confuse this with a sequence of separatecharactersC, -, h!!!} The @kbd{^} is itself, never used to indicate aControl character.Finally, we note that Viper's Ex-style commands can be made to work on thecurrent Emacs region. This is done by typing a digit argument before@kbd{:}. For instance, typing @kbd{1:} will prompt you with something like@emph{:123,135}, assuming that the current region starts at line 123 andends at line 135. There is no need to type the line numbers, since Viperinserts them automatically in front of the Ex command.@cindex Ex commands@node Text Handling, Display, Groundwork, Commands@section Text Handling@menu* Move Commands:: Moving, Searching* Marking:: Textmarkers in Viper and the Emacs Mark.* Appending Text:: Text insertion, Shifting, Putting* Editing in Insert State:: Autoindent, Quoting etc.* Deleting Text:: Deleting* Changing Text:: Changing, Replacement, Joining* Search and Replace:: Searches, Query Replace, Pattern Commands* Yanking:: Yanking, Viewing Registers* Undoing:: Multiple Undo, Backups@end menu@node Move Commands,Marking,,Text Handling@subsection Move Commands@cindex movement commands@cindex searching@cindex textmarkers@cindex markers@cindex column movement@cindex paragraphs@cindex headings@cindex sections@cindex sentences@cindex matching parens@cindex paren matching@table @kbd@item <count> h C-h<count> chars to the left.@item <count> j <lf> C-n<count> lines downward.@item <count> l <sp><count> chars to the right.@item <count> k C-p<count> lines upward.@item <count> $To the end of line <count> from the cursor.@item <count> ^To the first CHAR <count> - 1 lines lower.@item <count> -To the first CHAR <count> lines higher.@item <count> + <cr>To the first CHAR <count> lines lower.@item 0To the first char of the line.@item <count> |To column <count>@item <count> f<char><count> <char>s to the right (find).@item <count> t<char>Till before <count> <char>s to the right.@item <count> F<char><count> <char>s to the left.@item <count> T<char>Till after <count> <char>s to the left.@item <count> ;Repeat latest @kbd{f t F T} <count> times.@item <count> ,Repeat latest @kbd{f t F T}<count> times in opposite direction.@item <count> w<count> words forward.@item <count> W<count> WORDS forward.@item <count> b<count> words backward.@item <count> B<count> WORDS backward.@item <count> eTo the end of word <count> forward.@item <count> ETo the end of WORD <count> forward.@item <count> GGo to line <count> (default end-of-file).@item <count> HTo line <count> from top of the screen (home).@item <count> LTo line <count> from bottom of the screen (last).@item MTo the middle line of the screen.@item <count> )<count> sentences forward.@item <count> (<count> sentences backward.@item <count> @}<count> paragraphs forward.@item <count> @{<count> paragraphs backward.@item <count> ]]To the <count>th heading.@item <count> [[To the <count>th previous heading.@item <count> []To the end of <count>th heading.@item m<a-z>Mark the cursor position with a letter.@item `<a-z>To the mark.@item '<a-z>To the first CHAR of the line with the mark.@item [<a-z>Show contents of textmarker.@item ]<a-z>Show contents of register.@item ``To the cursor position before the latest absolutejump (of which are examples @kbd{/} and @kbd{G}).@item ''To the first CHAR of the line on which the cursorwas placed before the latest absolute jump.@item <count> /<string>To the <count>th occurrence of <string>.@item <count> /<cr>To the <count>th occurrence of <string> from previous @kbd{/ or ?}.@item <count> ?<string>To the <count>th previous occurrence of <string>.@item <count> ?<cr>To the <count>th previous occurrence of <string> from previous @kbd{?@: or /}.@item nRepeat latest @kbd{/} @kbd{?} (next).@item NRepeat latest search in opposite direction.@item C-c /Without a prefix argument, this command togglescase-sensitive/case-insensitive search modes and plain vanilla/regularexpression search. With the prefix argument 1, i.e.,@kbd{1 C-c /}, this toggles case-sensitivity; with the prefix argument 2,toggles plain vanilla search and search usingregular expressions. @xref{Viper Specials}, for alternative ways to invokethis function.@cindex vanilla search@cindex case-sensitive search@cindex case-insensitive search@item %Find the next bracket/parenthesis/brace and go to its match.By default, Viper ignores brackets/parentheses/braces that occur insideparentheses. You can change this by setting@code{viper-parse-sexp-ignore-comments} to @code{nil} in your @file{.viper} file.This option can also be toggled interactively if you quickly hit @kbd{%%%}.This latter feature is implemented as a vi-style keyboard macro. If youdon't want this macro, put@example(viper-set-parsing-style-toggling-macro 'undefine)@end example@findex @code{viper-set-parsing-style-toggling-macro}in your @file{~/.viper} file.@end table@kindex @kbd{%}@kindex @kbd{C-c /}@kindex @kbd{N}@kindex @kbd{n}@kindex @kbd{?<cr>}@kindex @kbd{/<cr>}@kindex @kbd{?<string>}@kindex @kbd{/<string>}@kindex @kbd{''}@kindex @kbd{``}@kindex @kbd{]<a-z>}@kindex @kbd{[<a-z>}@kindex @kbd{'<a-z>}@kindex @kbd{`<a-z>}@kindex @kbd{m<a-z>}@kindex @kbd{[]}@kindex @kbd{[[}@kindex @kbd{]]}@kindex @kbd{@{}@kindex @kbd{@}}@kindex @kbd{(}@kindex @kbd{)}@kindex @kbd{M}@kindex @kbd{L}@kindex @kbd{H}@kindex @kbd{G}@kindex @kbd{E}@kindex @kbd{e}@kindex @kbd{B}@kindex @kbd{b}@kindex @kbd{W}@kindex @kbd{w}@kindex @kbd{,}@kindex @kbd{;}@kindex @kbd{T<char>}@kindex @kbd{F<char>}@kindex @kbd{t<char>}@kindex @kbd{f<char>}@kindex @kbd{|}@kindex @kbd{0}@kindex @kbd{<cr>}@kindex @kbd{+}@kindex @kbd{-}@kindex @kbd{^}@kindex @kbd{$}@kindex @kbd{C-p}@kindex @kbd{<lf>}@kindex @kbd{<sp>}@kindex @kbd{C-n}@kindex @kbd{C-h}@kindex @kbd{h}@kindex @kbd{j}@kindex @kbd{k}@kindex @kbd{l}@vindex @code{viper-parse-sexp-ignore-comments}@node Marking,Appending Text,Move Commands,Text Handling@subsection MarkingEmacs mark is referred to in the region specifiers @kbd{r} and @kbd{R}.@xref{Emacs Preliminaries}, and @xref{Basics}, for explanation. Alsosee @ref{Mark,,Mark,emacs,The GNU Emacs manual}, for an explanation ofthe Emacs mark ring.@cindex marking@table @kbd@item m<a-z>Mark the current file and position with the specified letter.@item m .Set the Emacs mark (@pxref{Emacs Preliminaries}) at point.@item m ^Set the Emacs mark (@pxref{Emacs Preliminaries}) back to where it was lastset with the @kbd{m.} command. This is useful when you set the mark with@kbd{m.}, but then some other command (such as @kbd{L} or @kbd{G}) changesit in a way that you didn't like.@item m <Set the Emacs mark at beginning of buffer.@item m >Set the Emacs mark at end of buffer.@item m ,Jump to the Emacs mark.@item :mark <char>Mark position with text marker named <char>. This is an Ex command.@item :k <char>Same as @kbd{:mark}.@item ``Exchange point and mark.@item ''Exchange point and mark and go to the first CHAR on line.@item '<a-z>Go to specified Viper mark.@itemGo to specified Viper mark and go to the first CHAR on line.@end table@kindex @kbd{m<a-z>}@kindex @kbd{m.}@kindex @kbd{m>}@kindex @kbd{m<}@kindex @kbd{m,}@kindex @kbd{m^}@findex @kbd{:mark}@findex @kbd{:k}@kindex @kbd{''}@kindex @kbd{``}@kindex @kbd{`<a-z>}@kindex @kbd{'<a-z>}@node Appending Text, Editing in Insert State, Marking,Text Handling@subsection Appending Text@xref{Options}, to see how to change tab and shiftwidth size. See the GNUEmacs manual, or try @kbd{C-ha tabs} (If you have turned Emacs help on).Check out the variable @code{indent-tabs-mode} to put in just spaces.Also see options for word-wrap.@cindex inserting@cindex appending@cindex paste@cindex put@table @kbd@item <count> a<count> times after the cursor.@item <count> A<count> times at the end of line.@item <count> i<count> times before the cursor (insert).@item <count> I<count> times before the first CHAR of the line@item <count> oOn a new line below the current (open).The count is only useful on a slow terminal.@item <count> OOn a new line above the current.The count is only useful on a slow terminal.@item <count> ><move>Shift the lines described by <count><move> oneshiftwidth to the right (layout!).@item <count> >>Shift <count> lines one shiftwidth to the right.@item <count> ["<a-z1-9>]pPut the contents of the (default undo) buffer<count> times after the cursor. The register willbe automatically down-cased.@item <count> ["<a-z1-9>]PPut the contents of the (default undo) buffer<count> times before the cursor. The register will@item [<a-z>Show contents of textmarker.@item ]<a-z>Show contents of register.@item <count> .Repeat previous command <count> times. For destructivecommands as well as undo.@item f1 1 and f1 2While @kbd{.} repeats the last destructive command,these two macros repeat the second-last and the third-last destructivecommands. @xref{Vi Macros}, for more information on Vi macros.@item C-c M-p and C-c M-nIn Vi state,these commands help peruse the history of Vi's destructive commands.Successive typing of @kbd{C-c M-p} causes Viper to search the history inthe directionof older commands, while hitting @kbd{C-c M-n} does so in reverseorder. Each command in the history is displayed in the Minibuffer. Thedisplayed command canthen be executed by typing `@kbd{.}'.Since typing the above sequences of keys may be tedious, thefunctions doing the perusing can be bound to unused keyboard keys in the@file{~/.viper} file. @xref{Viper Specials}, for details.@end table@kindex @kbd{C-c M-p}@kindex @kbd{C-c M-n}@kindex @kbd{.}@kindex @kbd{]<a-z>}@kindex @kbd{[<a-z>}@kindex @kbd{P}@kindex @kbd{p}@kindex @kbd{"<a-z1-9>p}@kindex @kbd{"<a-z1-9>P}@kindex @kbd{>>}@kindex @kbd{><move>}@kindex @kbd{O}@kindex @kbd{o}@kindex @kbd{i}@kindex @kbd{A}@kindex @kbd{a}@node Editing in Insert State, Deleting Text, Appending Text,Text Handling@subsection Editing in Insert StateMinibuffer can be edited similarly to Insert state, and you can switchbetween Insert/Replace/Vi states at will.Some users prefer plain Emacs feel in the Minibuffer. To this end, set@var{viper-vi-style-in-minibuffer} to @code{nil}.@cindex Insert state@table @kbd@item C-vDeprive the next char of its special meaning (quoting).@item C-hOne char back.@item C-wOne word back.@item C-uBack to the begin of the change on thecurrent line.@end table@kindex @kbd{C-u}@kindex @kbd{C-w}@kindex @kbd{C-v}@node Deleting Text, Changing Text, Editing in Insert State, Text Handling@subsection Deleting TextThere is one difference in text deletion that you should beaware of. This difference comes from Emacs and was adopted in Viperbecause we find it very useful. In Vi, if you delete a line, say, and thenanother line, these two deletions are separated and are put backseparately if you use the @samp{p} command. In Emacs (and Viper), successiveseries of deletions that are @emph{not interrupted} by other commands arelumped together, so the deleted text gets accumulated and can be put backas one chunk. If you want to break a sequence of deletions so that thenewly deleted text could be put back separately from the previously deletedtext, you should perform a non-deleting action, e.g., move the cursor onecharacter in any direction.@cindex shifting text@table @kbd@item <count> xDelete <count> chars under and after the cursor.@item <count> XDelete <count> chars before the cursor.@item <count> d<move>Delete from point to endpoint of <count><move>.@item <count> ddDelete <count> lines.@item DThe rest of the line.@item <count> <<move>Shift the lines described by <count><move> oneshiftwidth to the left (layout!).@item <count> <<Shift <count> lines one shiftwidth to the left.@end table@kindex @kbd{<<}@kindex @kbd{<<move>}@kindex @kbd{D}@kindex @kbd{dd}@kindex @kbd{d<move>}@kindex @kbd{X}@kindex @kbd{x}@node Changing Text, Search and Replace, Deleting Text,Text Handling@subsection Changing Text@cindex joining lines@cindex changing case@cindex quoting regions@cindex substitution@table @kbd@item <count> r<char>Replace <count> chars by <char> - no <esc>.@item <count> ROverwrite the rest of the line,appending change @var{count - 1} times.@item <count> sSubstitute <count> chars.@item <count> SChange <count> lines.@item <count> c<move>Change from begin to endpoint of <count><move>.@item <count> ccChange <count> lines.@item <count> CThe rest of the line and <count> - 1 next lines.@item <count> =<move>Reindent the region described by move.@item <count> ~Switch lower and upper cases.@item <count> JJoin <count> lines (default 2).@item :[x,y]s/<pat>/<repl>/<f>Substitute (on lines x through y) the pattern<pat> (default the last pattern) with <repl>. Usefulflags <f> are @samp{g} for @samp{global} (i.e.@: change everynon-overlapping occurrence of <pat>) and @samp{c} for@samp{confirm} (type @samp{y} to confirm a particularsubstitution, else @samp{n} ). Instead of @kbd{/} anypunctuation CHAR unequal to <space> <tab> and <lf> can be used asdelimiter.In Emacs, @samp{\&} stands for the last matched expression, so@kbd{s/[ab]+/\&\&/} will double the string matched by @kbd{[ab]}.Viper doesn't treat @samp{&} specially, unlike Vi: use @samp{\&} instead.Viper does not parse search patterns and does not expand special symbolsfound there (e.g., @samp{~} is not expanded to the result of the previoussubstitution).Note: @emph{The newline character (inserted as @kbd{C-qC-j})can be used in <repl>}.@item :[x,y]copy [z]Copy text between @kbd{x} and @kbd{y} to the position after @kbd{z}.@item :[x,y]t [z]Same as @kbd{:copy}.@item :[x,y]move [z]Move text between @kbd{x} and @kbd{y} to the position after @kbd{z}.@item &Repeat latest Ex substitute command, e.g.@kbd{:s/wrong/right}.@item :x,yp@itemx :g/Pat/p@itemx :v/Pat/pThe above commands display certain buffer lines in atemporary buffer. The first form above displays the buffer lines between@kbd{x} and @kbd{y}. The second displays the lines of the buffer, whichmatch a given pattern. The third form displays the lines that do @emph{not}match the given pattern.@item #c<move>Change upper-case characters in the region to lower-case.@item #C<move>Change lower-case characters in the region to upper-case.@item #q<move>Insert specified string at the beginning of each line in the region@item C-c M-p and C-c M-nIn Insert and Replace states, these keys are bound to commands that perusethe history of the textpreviously inserted in other insert or replace commands. By repeatedly typing@kbd{C-c M-p} or @kbd{C-c M-n}, you will cause Viper toinsert these previously used strings one by one.When a new string is inserted, the previous one is deleted.In Vi state, these keys are bound to functions that peruse the history ofdestructive Vi commands.@xref{Viper Specials}, for details.@end table@kindex @kbd{C-c M-p}@kindex @kbd{C-c M-n}@kindex @kbd{#q<move> }@kindex @kbd{#C<move>}@kindex @kbd{#c<move>}@kindex @kbd{&}@kindex @kbd{\&}@findex @kbd{:substitute/<pat>/<repl>/<f>}@findex @kbd{:s/<pat>/<repl>/<f>}@findex @kbd{:copy [z]}@findex @kbd{:t [z]}@findex @kbd{:move [z]}@kindex @kbd{J}@kindex @kbd{~}@kindex @kbd{=<move>}@kindex @kbd{C}@kindex @kbd{cc}@kindex @kbd{c<move>}@kindex @kbd{S}@kindex @kbd{s}@kindex @kbd{R}@kindex @kbd{r<char>}@node Search and Replace, Yanking, Changing Text,Text Handling@subsection Search and Replace@xref{Groundwork}, for Ex address syntax. @xref{Options}, to see how toget literal (non-regular-expression) search and how to stop search fromwrapping around.@table @kbd@item C-c /Toggle case-sensitive search. With prefix argument, toggle vanilla/regularexpression search.@item <count> /<string>To the <count>th occurrence of <string>.Viper does not parse search patterns and does not expand special symbolsfound there (e.g., @samp{~} is not expanded to the result of the previoussubstitution).@item <count> ?<string>To the <count>th previous occurrence of <string>.@item <count> g<move>Search for the text described by move. (off by default)@item nRepeat latest @kbd{/} @kbd{?} (next).@item NIdem in opposite direction.@item %Find the next bracket and go to its match@item :[x,y]g/<string>/<cmd>@cindex text processingSearch globally [from line x to y] for <string>and execute the Ex <cmd> on each occurrence.@item :[x,y]v/<string>/<cmd>Execute <cmd> on the lines that don't match.@item #g<move>Execute the last keyboard macro for each line in the region.@xref{Macros and Registers}, for more info.@item QQuery Replace.@item :ta <name>Search in the tags file where <name> is defined (file, line), and go to it.@item :[x,y]s/<pat>/<repl>/<f>Substitute (on lines x through y) the pattern <pat> (default the lastpattern) with <repl>. Usefulflags <f> are @samp{g} for @samp{global} (i.e.@: change everynon-overlapping occurrence of <pat>) and @samp{c} for@samp{confirm} (type @samp{y} to confirm a particularsubstitution, else @samp{n}). Instead of @kbd{/} anypunctuation character other than <space> <tab> and <lf> can be used asdelimiter.Note: @emph{The newline character (inserted as @kbd{C-qC-j})can be used in <repl>}.@item &Repeat latest Ex substitute command, e.g.@: @kbd{:s/wrong/right}.@item :global /<pattern>/<ex-command>@itemx :g /<pattern>/<ex-command>Execute <ex-command> on all lines that match <pattern>.@item :vglobal /<pattern>/<ex-command>@itemx :v /<pattern>/<ex-command>Execute <ex-command> on all lines that do not match <pattern>.@end table@kindex @kbd{&}@findex @kbd{:substitute/<pat>/<repl>/<f>}@kindex @kbd{Q}@kindex @kbd{#g<move>}@findex @kbd{:v}@findex @kbd{:g}@findex @kbd{:global}@findex @kbd{:vglobal}@findex @kbd{:tag <name>}@kindex @kbd{%}@kindex @kbd{N}@kindex @kbd{n}@kindex @kbd{g<move>}@kindex @kbd{?<string>}@kindex @kbd{/<string>}@node Yanking,Undoing,Search and Replace,Text Handling@subsection Yanking@cindex cut and paste@cindex paste@table @kbd@item <count> y<move>Yank from begin to endpoint of <count><move>.@item <count> "<a-z>y<move>Yank from begin to endpoint of <count><move> to register.@item <count> "<A-Z>y<move>Yank from begin to endpoint of <count><move> and appendto register.@item <count> yy<count> lines.@item <count> YIdem (should be equivalent to @kbd{y$} though).@item m<a-z>Mark the cursor position with a letter.@item [<a-z>Show contents of textmarker.@item ]<a-z>Show contents of register.@item <count> ["<a-z1-9>]pPut the contents of the (default undo) buffer<count> times after the cursor. The register willbe automatically down-cased.@item <count> ["<a-z1-9>]PPut the contents of the (default undo) buffer<count> times before the cursor. The register will@end table@kindex @kbd{P}@kindex @kbd{p}@kindex @kbd{"<a-z1-9>p}@kindex @kbd{"<a-z1-9>P}@kindex @kbd{]<a-z>}@kindex @kbd{[<a-z>}@kindex @kbd{m<a-z>}@kindex @kbd{Y}@kindex @kbd{yy}@kindex @kbd{"<A-Z>y<move>}@kindex @kbd{"<a-z>y<move>}@kindex @kbd{y<move>}@kindex @kbd{yank}@findex @kbd{:yank}@node Undoing,, Yanking,Text Handling@subsection Undoing@cindex undo@cindex backup files@table @kbd@item u UUndo the latest change.@item .Repeat undo.@item :q!Quit Vi without writing.@item :e!Re-edit a messed-up file.@item :recRecover file from autosave. Viper also creates backup filesthat have a @samp{~} appended to them.@end table@findex @kbd{:rec}@findex @kbd{:e!}@findex @kbd{:q!}@kindex @kbd{.}@kindex @kbd{U}@kindex @kbd{u}@node Display, File and Buffer Handling, Text Handling, Commands@section Display@cindex scrolling@table @kbd@item C-gAt user level 1,give file name, status, current line numberand relative position.@*At user levels 2 and higher, abort the current command.@item C-c gGive file name, status, current line number and relative position -- alluser levels.@item C-lRefresh the screen.@item <count> C-eExpose <count> more lines at bottom, cursor stays put (if possible).@item <count> C-yExpose <count> more lines at top, cursor stays put (if possible).@item <count> C-dScroll <count> lines downward (default the number of the previous scroll;initialization: half a page).@item <count> C-uScroll <count> lines upward (default the number of the previous scroll;initialization: half a page).@item <count> C-f<count> pages forward.@item <count> C-b<count> pages backward (in older versions @kbd{C-b} only works without count).@item <count> z<cr>@item zHPut line <count> at the top of the window (default the current line).@item <count> z-@item zLPut line <count> at the bottom of the window(default the current line).@item <count> z.@item zMPut line <count> in the center of the window(default the current line).@end table@kindex @kbd{zM}@kindex @kbd{zL}@kindex @kbd{zH}@kindex @kbd{z<cr>}@kindex @kbd{z.}@kindex @kbd{z-}@kindex @kbd{z<cr>}@kindex @kbd{C-b}@kindex @kbd{C-f}@kindex @kbd{C-u}@kindex @kbd{C-d}@kindex @kbd{C-y}@kindex @kbd{C-e}@kindex @kbd{C-l}@kindex @kbd{C-g}@node File and Buffer Handling, Mapping, Display,Commands@section File and Buffer Handling@cindex multiple filesIn all file handling commands, space should be typed before entering the filename. If you need to type a modifier, such as @kbd{>>} or @kbd{!}, don'tput any space between the command and the modifier.Note that many Ex commands, e.g., @kbd{:w}, accept command arguments. Theeffect is that the command would start acting on the current region. Forinstance, if the current region spans the lines 11 through 22, then if youtype @kbd{1:w} you would see @samp{:11,22w} in the minibuffer.@table @kbd@item :qQuit buffer except if modified.@item :q!Quit buffer without checking. In Viper, these two commandsare identical. Confirmation is required if exiting modified buffers thatvisit files.@item :suspend@item :stopSuspend Viper@item :[x,y] wWrite the file. Viper makes sure that a final newline is always added toany file where this newline is missing. This is done by setting Emacsvariable @code{require-final-newline} to @code{t}. If you don't like thisfeature, use @code{setq-default} to set @code{require-final-newline} to@code{nil}. This must be done in @file{.viper} file.@item :[x,y] w <name>Write to the file <name>.@item :[x,y] w>> <name>Append the buffer to the file <name>. There should be no space between@kbd{w} and @kbd{>>}. Type space after the @kbd{>>} and see what happens.@item :w!@: <name>Overwrite the file <name>. In Viper, @kbd{:w} and @kbd{:w!} are identical.Confirmation is required for writing to an existing file (if this is notthe file the buffer is visiting) or to a read-only file.@item :x,y w <name>Write lines x through y to the file <name>.@item :wqWrite the file and kill buffer.@item :r <file> [<file> ...]Read file into a buffer, inserting its contents after the current line.@item :xitSame as @kbd{:wq}.@item :Write@itemx :WSave all unsaved buffers, asking for confirmation.@item :WWrite@itemx :WWLike @kbd{W}, but without asking for confirmation.@item ZZSave current buffer and kill it. If user level is 1, then save all filesand kill Emacs. Killing Emacs is the wrong way to use it, so you shouldswitch to higher user levels as soon as possible.@item :x [<file>]Save and kill buffer.@item :x!@: [<file>]@kbd{:w![<file>]} and @kbd{:q}.@item :prePreserve the file -- autosave buffers.@item :recRecover file from autosave.@item :f [<file>]without the argument, prints file name and character/line information afoutthe currently visited file. With an argument, sets the currently visitedfilename to @file{file}.@item :cd [<dir>]Set the working directory to <dir> (default home directory).@item :pwdPrint present working directory.@item :e [+<cmd>] <files>Edit files. If no filename is given, edit the file visited by the currentbuffer. If buffer was modified or the file changed on disk, ask forconfirmation. Unlike Vi, Viper allows @kbd{:e} to take multiple arguments.The first file is edited the same way as in Vi. The rest are visitedin the usual Emacs way.@item :e!@: [+<cmd>] <files>Re-edit file. If no filename, re-edit current file.In Viper, unlike Vi, @kbd{e!} is identical to @kbd{:e}. In both cases, theuser is asked to confirm if there is a danger of discarding changes to abuffer.@item :q!Quit Vi without writing.@item C-^Edit the alternate (normally the previous) file.@item :rewObsolete@item :argsList files not shown anywhere with counts for next@item :n [count] [+<cmd>] [<files>]Edit <count> file, or edit files. The count comes from @kbd{:args}.@item :N [count] [+<cmd>] [<files>]Like @kbd{:n}, but the meaning of the variable@var{ex-cycle-other-window} is reversed.@item :bSwitch to another buffer. If @var{ex-cycle-other-window} is @code{t},switch in another window. Buffer completion is supported.The variable @var{viper-read-buffer-function} controls which function isactually used to read the buffer name. The default is @code{read-buffer},but better alternatives are also available in Emacs (e.g.,@code{iswitchb-read-buffer}).@vindex @var{viper-read-buffer-function}@item :BLike @kbd{:b}, but the meaning of @var{ex-cycle-other-window} is reversed.@item :<address>r <name>Read the file <name> into the buffer after the line <address>.@item v, V, C-vEdit a file in current or another window, or in another frame. File nameis typed in Minibuffer. File completion and history are supported.@end table@kindex @kbd{v}@kindex @kbd{V}@findex @kbd{:args}@findex @kbd{:rew}@kindex @kbd{C-^}@findex @kbd{:e!@: [<files>]}@findex @kbd{:e [<files>]}@findex @kbd{:edit [<files>]}@findex @kbd{:edit!@: [<files>]}@findex @kbd{:q!}@findex @kbd{:q}@findex @kbd{:quit}@findex @kbd{:quit!}@findex @kbd{:f}@findex @kbd{:rec}@findex @kbd{:r}@findex @kbd{:read}@findex @kbd{:pre}@kindex @kbd{ZZ}@findex @kbd{:wq}@findex @kbd{:w <file>}@findex @kbd{:w!@: <file>}@findex @kbd{:w >> <file>}@findex @kbd{:write <file>}@findex @kbd{:write!@: <file>}@findex @kbd{:write >> <file>}@findex @kbd{:W}@findex @kbd{:WW}@findex @kbd{:Write}@findex @kbd{:WWrite}@findex @kbd{:WWrite}@findex @kbd{:x}@findex @kbd{:x!}@findex @kbd{:suspend}@findex @kbd{:stop}@findex @kbd{:n [<count> | <file>]}@findex @kbd{:cd [<dir>]}@findex @kbd{:pwd}@node Mapping, Shell Commands, File and Buffer Handling, Commands@section Mapping@cindex key bindings@cindex key mapping@table @kbd@item :map <string>Start defining a Vi-style keyboard macro.For instance, typing@kbd{:map www} followed by @kbd{:!wc %} and then typing @kbd{C-x )}will cause @kbd{www} to run wc oncurrent file (Vi replaces @samp{%} with the current file name).@item C-x )Finish defining a keyboard macro.In Viper, this command completes the process of defining all keyboardmacros, whether they are Emacs-style or Vi-style.This is a departure from Vi, needed to allow WYSIWYG mapping ofkeyboard macros and to permit the use of function keys and arbitrary Emacsfunctions in the macros.@item :unmap <string>Deprive <string> of its mappings in Vi state.@item :map!@: <string>Map a macro for Insert state.@item :unmap!@: <string>Deprive <string> of its mapping in Insert state (see @kbd{:unmap}).@item @@<a-z>In Vi state,execute the contents of register as a command.@item @@@@In Vi state,repeat last register command.@item @@#In Vi state,begin keyboard macro. End with @@<a-z>. This willput the macro in the proper register. Register willbe automatically down-cased.@xref{Macros and Registers}, for more info.@item @@!<a-z>In Vi state,yank anonymous macro to register@item *In Vi state,execute anonymous macro (defined by C-x( and C-x )).@item C-x eLike @kbd{*}, but works in all Viper states.@item #g<move>Execute the last keyboard macro for each line in the region.@xref{Macros and Registers}, for more info.@item [<a-z>Show contents of textmarker.@item ]<a-z>Show contents of register.@end table@kindex @kbd{]<a-z>}@kindex @kbd{[<a-z>}@kindex @kbd{#g<move>}@kindex @kbd{*}@kindex @kbd{@@!<a-z>}@kindex @kbd{@@#}@kindex @kbd{@@@@}@kindex @kbd{@@<a-z>}@findex @kbd{:unmap <char>}@findex @kbd{:map <char> <seq>}@findex @kbd{:unmap!@: <char>}@findex @kbd{:map!@: <char> <seq>}@node Shell Commands, Options, Mapping, Commands@section Shell Commands@cindex % (Current file)The symbol @samp{%} is used in Ex shell commands to mean current file. Ifyou want a @samp{%} in your command, it must be escaped as @samp{\%}.@cindex @samp{%} (Ex address)However if @samp{%} is the first character, it stands as the address forthe whole file.@cindex @samp{#} (Previous file)Similarly, @samp{#} expands to the previous file. The previous file is thefirst file in @kbd{:args} listing. This defaults to the previous file inthe VI sense if you have one window.@refillSymbols @samp{%} and @samp{#} are also used in the Ex commands @kbd{:e} and@kbd{:r <shell-cmd>}. The commands @kbd{:w} and the regular @kbd{:r<file>} command don't support these meta symbols, because file history is abetter mechanism.@cindex shell commands@table @kbd@item :shExecute a subshell in another window@item :[x,y]!<cmd>Execute a shell <cmd> [on lines x through y;% is replace by current file, \% is changed to %@item :[x,y]!!@: [<args>]Repeat last shell command [and append <args>].@item :!<cmd>Just execute command and display result in a buffer.@item :!!@: <args>Repeat last shell command and append <args>@item <count> !<move><cmd>The shell executes <cmd>, with standardinput the lines described by <count><move>,next the standard output replaces those lines(think of @samp{cb}, @samp{sort}, @samp{nroff}, etc.).@item <count> !!<cmd>Give <count> lines as standard input to theshell <cmd>, next let the standard outputreplace those lines.@item :[x,y] w !<cmd>Let lines x to y be standard input for <cmd>(notice the <sp> between @kbd{w} and @kbd{!}).@item :<address>r !<cmd>Put the output of <cmd> after the line <address> (default current).@item :<address>r <name>Read the file <name> into the buffer after the line <address> (defaultcurrent).@item :makeRun the make command in the current directory.@end table@findex @kbd{:<address>r <name>}@findex @kbd{:<address>r !<cmd>}@findex @kbd{!<cmd>}@findex @kbd{!!<cmd>}@findex @kbd{!<move><cmd>}@findex @kbd{:w !<cmd>}@findex @kbd{:x,y w !<cmd>}@findex @kbd{:!!@: <args>}@findex @kbd{:!<cmd>}@findex @kbd{:sh}@findex @kbd{:make}@node Options,Emacs Related Commands,Shell Commands,Commands@section Options@cindex Vi options@table @kbd@item autoindent@itemx ai@cindex autoindentautoindent -- In append mode after a <cr> thecursor will move directly below the firstcharacter on the previous line.This setting affects the current buffer only.@item autoindent-global@itemx ai-globalSame as `autoindent', but affects all buffers.@item noautoindent@itemx noaiCancel autoindent.@item noautoindent-global@itemx noai-gCancel autoindent-global.@item ignorecase@itemx ic@cindex case and searchingignorecase -- No distinction between upper and lower cases when searching.@item noignorecase@itemx noicCancel ignorecase.@item magic@itemx ma@cindex literal searchingRegular expressions used in searches; nomagic means no regexps.@item nomagic@item nomaCancel magic.@item readonly@itemx ro@cindex readonly filesreadonly -- The file is not to be changed.If the user attempts to write to this file, confirmation will be requested.@item noreadonly@itemx noroCancel readonly.@item shell=<string>@itemx sh=<string>@cindex shellshell -- The program to be used for shell escapes(default @samp{$SHELL} (default @file{/bin/sh})).@item shiftwidth=<count>@itemx sw=<count>@cindex layout@cindex shifting textshiftwidth -- Gives the shiftwidth (default 8 positions).@item showmatch@itemx sm@cindex paren matching@cindex matching parensshowmatch -- Whenever you append a @kbd{)}, Vi showsits match if it's on the same page; also with@kbd{@{} and @kbd{@}}. If there's no match, Vi will beep.@item noshowmatch@itemx nosmCancel showmatch.@item tabstop=<count>@itemx ts=<count>@cindex changing tab width@cindex tabbingtabstop -- The length of a <ht>; warning: this isonly IN the editor, outside of it <ht>s havetheir normal length (default 8 positions).This setting affects the current buffer only.@item tabstop-global@itemx ts-gSame as `tabstop', but affects all buffers.@item wrapmargin=<count>@itemx wm=<count>@cindex auto fill@cindex word wrapwrapmargin -- In append mode Vi automaticallyputs a <lf> whenever there is a <sp> or <ht>within <wm> columns from the right margin.@item wrapscan@itemx ws@cindex searchingwrapscan -- When searching, the end isconsidered @samp{stuck} to the begin of the file.@item nowrapscan@itemx nowsCancel wrapscan.@item :set <option>Turn <option> on.@item :set no<option>Turn <option> off.@item :set <option>=<value>Set <option> to <value>.@end table@findex @kbd{:set <option>=<value>}@findex @kbd{:set no<option>}@findex @kbd{:set <option>}@findex @kbd{:set ws}@findex @kbd{:set wrapscan}@findex @kbd{:set wm=<count>}@findex @kbd{:set wrapmargin=<count>}@findex @kbd{:set ts=<count>}@findex @kbd{:set tabstop=<count>}@findex @kbd{:set tab-stop-local=<count>}@findex @kbd{:set sm}@findex @kbd{:set showmatch}@findex @kbd{:set sw=<count>}@findex @kbd{:set shiftwidth=<count>}@findex @kbd{:set sh=<string>}@findex @kbd{:set shell=<string>}@findex @kbd{:set ro}@findex @kbd{:set readonly}@findex @kbd{:set magic}@findex @kbd{:set ic}@findex @kbd{:set ignorecase}@findex @kbd{:set ai}@findex @kbd{:set autoindent}@node Emacs Related Commands,,Options,Commands@section Emacs Related Commands@table @kbd@item C-\Begin Meta command in Vi or Insert states. Most often used as C-\ x (M-x).Note: Emacs binds @kbd{C-\} to a function that offers to change thekeyboard input method in the multilingual environment. Viper overrides thisbinding. However, it is still possible to switch the input method by typing@kbd{\ C-\} in the Vi command state and @kbd{C-z \ C-\} in the Insert state.Or you can use the MULE menu on the menubar.@item C-zIn Insert and Replace states, prepare Viper to accept the next command andexecute it as if Viper was in Vi state. Then return to Insert state.In Vi state, switch to Emacs state; in Emacs state, switch to Vi state.@item C-c \Switches to Vi state for the duration of a single command. Then goes backto the original Viper state. Works from Vi, Insert, Replace, and Emacs states.@item C-x0Close Window@item C-x1Close Other Windows@item C-x2Split Window@item C-xoMove among windows@item C-xC-fEmacs find-file, useful in Insert state@item C-yPut back the last killed text. Similar to Vi's @kbd{p}, but also works inInsert and Replace state. This command doesn't work in Vi command state,since this binding is taken for something else.@item M-yUndoes the last @kbd{C-y} and puts another kill from the kill ring.Using this command, you can try may different kills until you find the oneyou need.@end table@kindex @kbd{M-y}@kindex @kbd{C-y}@kindex @kbd{C-xC-f}@kindex @kbd{C-xo}@kindex @kbd{C-x2}@kindex @kbd{C-x1}@kindex @kbd{C-x0}@kindex @kbd{C-z}@kindex @kbd{C-\}@kindex @kbd{C-c\}@node Mouse-bound Commands,,,Commands@section Mouse-bound CommandsThe following two mouse actions are normally bound to special search andinsert commands in of Viper:@table @kbd@item S-Mouse-1Holding Shift and clicking mouse button 1 willinitiate search fora region under the mouse pointer.This command can take a prefix argument. Note: Viper sets thisbinding only if this mouse action is notalready bound to something else.@xref{Viper Specials}, for more information.@refill@item S-Mouse-2Holding Shift and clicking button 2 of the mouse willinsert a region surrounding the mouse pointer.This command can also take a prefix argument.Note: Viper sets this binding only if this mouse action is notalready bound to something else.@xref{Viper Specials}, for more details.@refill@end table@kindex @kbd{S-Mouse-1}@kindex @kbd{S-Mouse-2}@kindex @kbd{meta button1up}@kindex @kbd{meta button2up}@node Acknowledgments,,,Top@comment node-name, next, previous, up@unnumbered AcknowledgmentsViper, formerly known as VIP-19, was written by Michael Kifer. Viper isbased on the original VIP package by Masahiko Sato and on its enhancement,VIP 4.4, by Aamod Sane. This manual is an adaptation of the manual for VIP4.4, which, in turn, was based on Sato's manual for VIP 3.5.Many contributors on the Net pointed out bugs and suggested a number ofuseful features. Scott Bronson and Samuel Padgett contributed patches thatwere incorporated in this code. Here is a hopefully complete list ofcontributors:@exampleaaronl@@vitelus.com (Aaron Lehmann),ahg@@panix.com (Al Gelders),amade@@diagram.fr (Paul-Bernard Amade),ascott@@fws214.intel.com (Andy Scott),bronson@@trestle.com (Scott Bronson),cook@@biostat.wisc.edu (Tom Cook),csdayton@@midway.uchicago.edu (Soren Dayton),dave@@hellgate.utah.edu,dm@@scs.cs.nyu.edu (David Mazieres),dominik@@strw.LeidenUniv.nl (Carsten Dominik),dwallach@@cs.princeton.edu (Dan Wallach),dwight@@toolucky.llnl.gov (Dwight Shih),dxc@@xprt.net (David X Callaway),edmonds@@edmonds.home.cs.ubc.ca (Brian Edmonds),gin@@mo.msk.ru (Golubev I.N.),gviswana@@cs.wisc.edu (Guhan Viswanathan),gvr@@halcyon.com (George V.@: Reilly),hatazaki@@bach.convex.com (Takao Hatazaki),hpz@@ibmhpz.aug.ipp-garching.mpg.de (Hans-Peter Zehrfeld),irie@@t.email.ne.jp (Irie Tetsuya),jackr@@dblues.engr.sgi.com (Jack Repenning),jamesm@@bga.com (D.J.@: Miller II),jjm@@hplb.hpl.hp.com (Jean-Jacques Moreau),jl@@cse.ogi.edu (John Launchbury),jobrien@@hchp.org (John O'Brien),johnw@@borland.com (John Wiegley),kanze@@gabi-soft.fr (James Kanze),kin@@isi.com (Kin Cho),kwzh@@gnu.org (Karl Heuer),lindstro@@biostat.wisc.edu (Mary Lindstrom),lektu@@terra.es (Juanma Barranquero),lennart.borgman.073@@student.lu.se (Lennart Borgman),minakaji@@osaka.email.ne.jp (Mikio Nakajima),Mark.Bordas@@East.Sun.COM (Mark Bordas),meyering@@comco.com (Jim Meyering),martin@@xemacs.org (Martin Buchholz),mbutler@@redfernnetworks.com (Malcolm Butler),mveiga@@dit.upm.es (Marcelino Veiga Tuimil),paulk@@summit.esg.apertus.com (Paul Keusemann),pfister@@cs.stonybrook.edu (Hanspeter Pfister),phil_brooks@@MENTORG.COM (Phil Brooks),pogrell@@informatik.hu-berlin.de (Lutz Pogrell),pradyut@@cs.uchicago.edu (Pradyut Shah),roderick@@argon.org (Roderick Schertler),rxga@@ulysses.att.com,sawdey@@lcse.umn.edu (Aaron Sawdey),simonb@@prl.philips.co.uk (Simon Blanchard),spadgett1@@nc.rr.com (Samuel Padgett),stephen@@farrell.org (Stephen Farrell),storm@@cua.dk (Kim F. Storm),sudish@@MindSpring.COM (Sudish Joseph),schwab@@issan.informatik.uni-dortmund.de (Andreas Schwab)terra@@diku.dk (Morten Welinder),thanh@@informatics.muni.cz (Han The Thanh),toma@@convex.convex.com,vrenjak@@sun1.racal.com (Milan Vrenjak),whicken@@dragon.parasoft.com (Wendell Hicken),zapman@@cc.gatech.edu (Jason Zapman II),@end example@node Key Index,Function Index,,Top@comment node-name, next, previous, up@unnumbered Key Index@printindex ky@node Function Index,Variable Index,Key Index,Top@comment node-name, next, previous, up@unnumbered Function Index@printindex fn@node Variable Index,Package Index,Function Index,Top@comment node-name, next, previous, up@unnumbered Variable Index@printindex vr@node Package Index,Concept Index,Variable Index,Top@comment node-name, next, previous, up@unnumbered Package Index@printindex pg@node Concept Index,,Package Index,Top@comment node-name, next, previous, up@unnumbered Concept Index@printindex cp@setchapternewpage odd@contents@bye@ignore arch-tag: f53e866a-15cf-4b1e-aead-77da9da1e864@end ignore