Mercurial > hg > xemacs-beta
comparison man/viper.texi @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | ac2d302a0011 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 % -*-texinfo-*- | |
2 | |
3 % | |
4 \input texinfo | |
5 | |
6 @comment Using viper.info instead of viper in setfilename breaks DOS. | |
7 @setfilename ../info/viper.info | |
8 @comment @setfilename viper.info | |
9 | |
10 @iftex | |
11 @finalout | |
12 @end iftex | |
13 | |
14 @titlepage | |
15 @title Viper Is a Package for Emacs Rebels | |
16 @subtitle a Vi emulator for GNU Emacs 19 and XEmacs 19 | |
17 @subtitle June 1996, Viper Version 2.90 | |
18 | |
19 @author Masahiko Sato (VIP 3.5) | |
20 @author Aamod Sane (VIP 4.4) | |
21 @author Michael Kifer (Viper) | |
22 | |
23 @page | |
24 @vskip 0pt plus 1fill | |
25 @end titlepage | |
26 | |
27 @unnumbered Distribution | |
28 | |
29 @noindent | |
30 Copyright @copyright{} 1995, 1996 Free Software Foundation, Inc. | |
31 | |
32 Permission is granted to make and distribute verbatim copies of | |
33 this manual provided the copyright notice and this permission notice | |
34 are preserved on all copies. | |
35 | |
36 @ignore | |
37 Permission is granted to process this file through TeX and print the | |
38 results, provided the printed document carries copying permission | |
39 notice identical to this one except for the removal of this paragraph | |
40 (this paragraph not being relevant to the printed manual). | |
41 | |
42 @end ignore | |
43 Permission is granted to copy and distribute modified versions of this | |
44 manual under the conditions for verbatim copying, provided that the entire | |
45 resulting derived work is distributed under the terms of a permission | |
46 notice identical to this one. | |
47 | |
48 Permission is granted to copy and distribute translations of this manual | |
49 into another language, under the same conditions as for modified versions. | |
50 | |
51 @ifinfo | |
52 @node Top, Overview,, (DIR) | |
53 | |
54 @unnumbered Viper | |
55 | |
56 We believe that one or more of the following statements are adequate | |
57 descriptions: | |
58 | |
59 @example | |
60 Viper Is a Package for Emacs Rebels; | |
61 it is a VI Plan for Emacs Rescue | |
62 and/or a venomous VI PERil. | |
63 @end example | |
64 | |
65 Technically speaking, Viper is a Vi emulation package for GNU Emacs 19 and | |
66 XEmacs 19. Because of its reliance on minor mode keymaps, Viper will not | |
67 work under Emacs 18. Viper implements most Vi and Ex commands. It gives you | |
68 the best of both worlds: Vi keystrokes for editing combined with the GNU | |
69 Emacs environment. Viper also fixes some common complaints with Vi | |
70 commands. This manual describes Viper, concentrating on the differences | |
71 from Vi and new features of Viper. | |
72 | |
73 Viper, formerly known as VIP-19, was written by Michael Kifer. It is based | |
74 on VIP version 3.5 by Masahiko Sato and VIP version 4.4 by Aamod Sane. | |
75 Viper tries to be compatible with these packages. | |
76 | |
77 Viper is intended to be usable without reading this manual --- the defaults | |
78 are set to make Viper as close to Vi as possible. At startup, Viper will | |
79 try to set the most appropriate default environment for you, based on | |
80 your familiarity with Emacs. It will also tell you the basic GNU Emacs window | |
81 management commands to help you start immediately. | |
82 | |
83 Although this manual explains how to customize Viper, some basic | |
84 familiarity with Emacs Lisp would be a plus. | |
85 | |
86 It is recommended that you read the Overview node. The other nodes may | |
87 be visited as needed. | |
88 | |
89 Comments and bug reports are welcome. | |
90 @code{kifer@@cs.emacs.edu} is the current address for Viper bug reports. | |
91 Please use the Ex command @kbd{:submitReport} for this purpose.@refill | |
92 | |
93 @end ifinfo | |
94 | |
95 @menu | |
96 * Overview:: Must read to get started | |
97 * Improvements over Vi:: New features, Improvements | |
98 * Customization:: How to customize Viper | |
99 * Commands:: Vi and Ex Commands | |
100 | |
101 * Key Index:: Index of Vi and Ex Commands | |
102 * Function Index:: Index of Viper Functions | |
103 * Variable Index:: Index of Viper Variables | |
104 * Package Index:: Index of Packages Mentioned in this Document | |
105 * Concept Index:: Vi, Ex and Emacs concepts | |
106 | |
107 * Acknowledgments:: | |
108 @end menu | |
109 @iftex | |
110 @unnumbered Introduction | |
111 | |
112 We believe that one or more of the following statements are adequate | |
113 descriptions: | |
114 | |
115 @example | |
116 Viper Is a Package for Emacs Rebels; | |
117 it is a VI Plan for Emacs Rescue | |
118 and/or a venomous VI PERil. | |
119 @end example | |
120 | |
121 Technically speaking, Viper is a Vi emulation package for GNU Emacs 19 and | |
122 XEmacs 19. Because of its reliance on minor mode keymaps, | |
123 it will not work under Emacs 18. Viper contains virtually all of | |
124 Vi and Ex functionality and much more. It gives you the best of both | |
125 worlds: Vi keystrokes for editing combined with the GNU Emacs | |
126 environment. Viper also fixes some common complaints with Vi commands. | |
127 This manual describes Viper, concentrating on the differences from Vi and | |
128 on the new features of Viper. | |
129 | |
130 Viper, formerly known as VIP-19, was written by Michael Kifer. It is based | |
131 on VIP version 3.5 by Masahiko Sato and VIP version 4.4 by Aamod Sane. | |
132 Viper tries to be compatible with these packages. | |
133 | |
134 Viper is intended to be usable without reading this manual --- the defaults | |
135 are set to make Viper as close to Vi as possible. At startup, Viper will | |
136 attempt to set the most appropriate default environment for you, based on | |
137 your familiarity with Emacs. It will also tell you the basic GNU Emacs window | |
138 management commands to help you start immediately. | |
139 | |
140 Although this manual explains how to customize Viper, some basic | |
141 familiarity with Emacs Lisp would be a plus. | |
142 | |
143 It is recommended that you read the chapter Overview. The other chapters | |
144 will be useful for customization and advanced usage. | |
145 | |
146 You should also learn to use the Info on-line hypertext manual system that | |
147 comes with Emacs. This manual can be read as an Info file. Try the command | |
148 @kbd{ESC x info} with vanilla Emacs sometime. | |
149 | |
150 Comments and bug reports are welcome. | |
151 @code{kifer@@cs.sunysb.edu} is the current address for Viper bug reports. | |
152 Please use the Ex command @kbd{:submitReport} for this purpose.@refill | |
153 | |
154 @end iftex | |
155 | |
156 @node Overview,Improvements over Vi,Top,Top | |
157 @chapter Overview of Viper | |
158 | |
159 Viper is a Vi emulation on top of Emacs. At the same time, Viper provides a | |
160 virtually unrestricted access to Emacs facilities. Perfect compatibility | |
161 with Vi is possible but not desirable. This chapter tells you about the | |
162 Emacs ideas that you should know about, how to use Viper within Emacs and | |
163 some incompatibilities. | |
164 | |
165 Viper was formerly known as VIP-19, which was | |
166 a descendant of VIP 3.5 by Masahiko Sato and VIP 4.4 by Aamod Sane. | |
167 | |
168 @menu | |
169 * Emacs Preliminaries:: Basic concepts in Emacs. | |
170 * Loading Viper:: Loading and Preliminary Configuration. | |
171 * States in Viper:: Viper has four states orthogonal to | |
172 modes in Emacs. | |
173 * The Minibuffer:: Command line in Emacs. | |
174 * Multiple Files in Viper:: True multiple file handling. | |
175 * Unimplemented Features:: That are unlikely to be implemented. | |
176 @end menu | |
177 | |
178 @node Emacs Preliminaries, Loading Viper, Overview, Overview | |
179 @section Emacs Preliminaries | |
180 | |
181 @cindex buffer | |
182 @cindex point | |
183 @cindex mark | |
184 @cindex text | |
185 @cindex looking at | |
186 @cindex end (of buffer) | |
187 @cindex end (of line) | |
188 @cindex region | |
189 | |
190 Emacs can edit several files at once. A file in Emacs is placed in a | |
191 @dfn{buffer} that usually has the same name as the file. Buffers are also used | |
192 for other purposes, such as shell interfaces, directory editing, etc. | |
193 @xref{Dired,,Directory Editor,emacs,The | |
194 Gnu Emacs Manual}, for an example.@refill | |
195 | |
196 A buffer has a distinguished position called the @dfn{point}. | |
197 A @dfn{point} is always between 2 characters, and is @dfn{looking at} | |
198 the right hand character. The cursor is positioned on the right hand | |
199 character. Thus, when the @dfn{point} is looking at the end-of-line, | |
200 the cursor is on the end-of-line character, i.e. beyond the last | |
201 character on the line. This is the default Emacs behavior.@refill | |
202 | |
203 The default settings of Viper try to mimic the behavior of Vi, | |
204 preventing the cursor from going beyond the last character on the line. | |
205 By using Emacs commands directly (such as those bound to arrow keys), it is | |
206 possible | |
207 to get the cursor beyond the end-of-line. However, this won't (or shouldn't) | |
208 happen if you restrict yourself to standard Vi keys, unless you modify the | |
209 default editing style. @xref{Customization}.@refill | |
210 | |
211 In addition to the @dfn{point}, there is another distinguished buffer | |
212 position called the @dfn{mark}. @xref{Mark,,Mark,emacs,The GNU Emacs | |
213 manual}, for more info on the mark. The text between the @dfn{point} and the | |
214 @dfn{mark} is called the @dfn{region} of the buffer. For the Viper user, | |
215 this simply means that in addition to the Vi textmarkers a--z, there is | |
216 another marker called @dfn{mark}. This is similar to the unnamed Vi marker | |
217 used by the jump commands (`` and ''), which move the cursor to the | |
218 position of the last absolute jump. | |
219 Viper provides access to the region in most | |
220 text manipulation commands as @kbd{r} and @kbd{R} suffix to commands | |
221 that operate on text regions, e.g., @kbd{dr} to delete region, etc. | |
222 @xref{Basics}, for more info.@refill | |
223 | |
224 @cindex window | |
225 @cindex mode line | |
226 @cindex buffer information | |
227 @cindex Minibuffer | |
228 @cindex command line | |
229 @cindex buffer (modified) | |
230 | |
231 Emacs divides the screen into tiled @dfn{windows}. You can see the | |
232 contents of a buffer through the window associated with the buffer. The | |
233 cursor of the screen is positioned on the character after @dfn{point}. | |
234 Every window has a @dfn{mode line} that displays information about the buffer. | |
235 You can change the format of the mode | |
236 line, but normally if you see @samp{**} at the beginning of a mode line it | |
237 means that the buffer is @dfn{modified}. If you write out the contents of | |
238 a buffer to a file, then the buffer will become not modified. Also if | |
239 you see @samp{%%} at the beginning of the mode line, it means that the file | |
240 associated with the buffer is write protected. The mode line will also | |
241 show the buffer name and current major and minor modes (see below). | |
242 A special buffer called @dfn{Minibuffer} is displayed as the last line | |
243 in a Minibuffer window. The Minibuffer window is used for command input | |
244 output. Viper uses Minibuffer window for @kbd{/} and @kbd{:} | |
245 commands.@refill | |
246 | |
247 @cindex mode | |
248 @cindex keymap | |
249 @cindex local keymap | |
250 @cindex global keymap | |
251 @cindex major mode | |
252 @cindex minor mode | |
253 | |
254 An Emacs buffer can have a @dfn{major mode} that customizes Emacs for | |
255 editing text of a particular sort by changing the functionality of the keys. | |
256 Keys are defined using a @dfn{keymap} that records the bindings between | |
257 keystrokes and | |
258 functions. The @dfn{global keymap} is common to all the | |
259 buffers. Additionally, each buffer has its @dfn{local keymap} that determines the | |
260 @dfn{mode} of the buffer. If a function is bound to some key in the local | |
261 keymap then that function will be executed when you type the key. | |
262 If no function is bound to a key in the | |
263 local map, however, the function bound to the key in the global map | |
264 will be executed. @xref{Major Modes,Major Modes,Major Modes,emacs,The | |
265 GNU Emacs Manual}, for more information.@refill | |
266 | |
267 A buffer can also have a @dfn{minor mode}. Minor modes are options that you | |
268 can use or not. A buffer in @code{text-mode} can have @code{auto-fill-mode} | |
269 as minor mode, which can be turned off or on at any time. In Emacs 19, a | |
270 minor mode may have it own keymap, which overrides the local keymap when | |
271 the minor mode is turned on. For more information, @pxref{Minor | |
272 Modes,Minor Modes,Minor Modes,emacs,The GNU Emacs Manual} @refill | |
273 | |
274 @cindex Viper as minor mode | |
275 @cindex Control keys | |
276 @cindex Meta key | |
277 | |
278 Viper is implemented as a collection of minor modes. Different minor modes | |
279 are involved when Viper emulates Vi command mode, Vi insert mode, etc. | |
280 You can also turn Viper on and off at any time while in Vi command mode. | |
281 @xref{States in Viper}, for | |
282 more information.@refill | |
283 | |
284 Emacs uses Control and Meta modifiers. These are denoted as C | |
285 and M, e.g. @kbd{^Z} as @kbd{C-z} and @kbd{Meta-x} as @kbd{M-x}. | |
286 The Meta key is usually located on each side of the Space bar; it is used | |
287 in a manner similar to the Control key, e.g., @kbd{M-x} means typing | |
288 @kbd{x} while holding the Meta key down. | |
289 For keyboards that do not have a Meta key, @key{ESC} is used as Meta. | |
290 Thus @kbd{M-x} is typed as @kbd{ESC x}. Viper uses @key{ESC} to switch | |
291 from Insert state to Vi state. Therefore Viper defines @kbd{_} as its Meta | |
292 key in Vi state. @xref{Vi State}, for more info.@refill | |
293 | |
294 Emacs is structured as a lisp interpreter around a C core. Emacs keys | |
295 cause lisp functions to be called. It is possible to call these | |
296 functions directly, by typing @kbd{M-x function-name}. | |
297 | |
298 @node Loading Viper, States in Viper, Emacs Preliminaries, Overview | |
299 @section Loading Viper | |
300 | |
301 First, make sure that all six Viper files @file{viper*.el} are somewhere on | |
302 Emacs @dfn{load path}. The load path is a list of directories where Emacs | |
303 looks for its Lisp code; it is similar to Unix environment variable | |
304 @var{PATH}. The load path is determined by the Lisp variable | |
305 @code{load-path}. | |
306 | |
307 Type @code{C-h v load-path RET} to check the current load path of your | |
308 Emacs. (Here and later, @kbd{RET} stands for carriage return.) If the files | |
309 @file{viper*.el} are not in any directory on the load path, you should | |
310 create your own directory and put it on the load path; then put | |
311 @file{viper*.el} in that directory. To put a new directory, say | |
312 @file{~/emacslib}, on your load path, add the following line at the | |
313 beginning of your @file{~/.emacs} file: | |
314 @lisp | |
315 (setq load-path (cons "~/emacslib" load-path)) | |
316 @end lisp | |
317 It is recommended that you compile @file{viper.el} by running | |
318 @example | |
319 make all | |
320 @end example | |
321 in the directory where Viper was unpacked. The best way to ensure that | |
322 Viper is installed properly is to run | |
323 @example | |
324 make install | |
325 @end example | |
326 in the directory where Viper was unpacked. See README in the Viper | |
327 distribution for the details on which modifications to the make file may be | |
328 necessary. | |
329 | |
330 Once Viper is settled on the load path, | |
331 the most common way to load it automatically is to include the line: | |
332 | |
333 @lisp | |
334 (require 'viper) | |
335 @end lisp | |
336 | |
337 @noindent | |
338 in your @file{~/.emacs} file. The @file{.emacs} file is placed in your home | |
339 directory and it will be executed every time you invoke Emacs. | |
340 Viper also uses the file @file{~/.vip} for Viper-specific customization. | |
341 If you wish | |
342 to be in Vi command state whenever this is appropriate, you can include the | |
343 following | |
344 line in your @file{.vip}: | |
345 @lisp | |
346 (setq vip-always t) | |
347 @end lisp | |
348 @noindent | |
349 (@xref{Vi State}, for the explanation of Vi mode.) | |
350 | |
351 Once invoked, Viper will arrange to bring up Emacs buffers in Vi state | |
352 whenever this makes sense. | |
353 @xref{Packages that Change Keymaps}, to find out when forcing Vi command state | |
354 on a buffer may be counter-productive. | |
355 | |
356 Even if your @file{.emacs} and @file{.vip} files do not contain any of the | |
357 above lines, you can still load Viper and enter Vi state by typing the | |
358 following from within Emacs: | |
359 | |
360 @lisp | |
361 M-x load-library RET viper RET | |
362 M-x viper-mode | |
363 @end lisp | |
364 | |
365 @noindent | |
366 Ask your local Emacs administrator if this fails to work. | |
367 | |
368 When Emacs first comes up, if you have not specified a file on the | |
369 command line, it will show the @samp{*scratch*} buffer, in the | |
370 @samp{Lisp Interaction} mode. After you invoke Viper, you can start | |
371 editing files by using @kbd{:e}, @kbd{:vi}, or @kbd{v} commands. | |
372 (@xref{File and Buffer Handling}, for more information on @kbd{v} and other | |
373 new commands that, in many cases, are more convenient than @kbd{:e}, | |
374 @kbd{:vi}, and similar old-style Vi commands.)@refill | |
375 | |
376 @node States in Viper, The Minibuffer, Loading Viper,Overview | |
377 @section States in Viper | |
378 | |
379 @kindex @kbd{C-z} | |
380 @kindex @kbd{C-z} | |
381 @kindex @kbd{ESC} | |
382 @kindex @kbd{i} | |
383 @cindex Emacs state | |
384 @cindex Vi state | |
385 @cindex Insert state | |
386 @cindex Replace state | |
387 @cindex Ex commands | |
388 | |
389 Viper has four states, Emacs, Vi, Insert, and Replace. | |
390 | |
391 @table @samp | |
392 @item Emacs state | |
393 This is the mode plain vanilla Emacs is normally in. After you have loaded | |
394 Viper, @kbd{C-z} will normally take you to Vi command state. Another | |
395 @kbd{C-z} will take you back to Emacs state. This toggle key can be | |
396 changed, @pxref{Customization} You can also type @kbd{M-x viper-mode} to | |
397 change to Vi state.@refill | |
398 | |
399 For users who chose to set their user level to 1 at Viper setup time, | |
400 switching to Emacs state is deliberately made harder in order to not | |
401 confuse the novice user. In this case, @kbd{C-z} will either iconify Emacs | |
402 (if Emacs runs as an application under X Windows) or it will stop Emacs (if | |
403 Emacs runs on a dumb terminal or in an Xterm window). | |
404 | |
405 @item Vi state | |
406 This is the Vi command mode. Any of the Vi commands, such as @kbd{i, o, a}, | |
407 @dots{}, will take you to Insert state. All Vi commands may | |
408 be used in this mode. Most Ex commands can also be used. | |
409 For a full list of Ex commands supported by Viper, type | |
410 @kbd{:} and then @kbd{TAB}. To get help on any issue, including the Ex | |
411 commands, type @kbd{:help}. This will invoke Viper Info | |
412 (if it is installed). Then typing @kbd{i} will prompt you for a topic to | |
413 search in the index. Note, to search for Ex commands in the index, you | |
414 should start them with a ``@kbd{:}'', e.g., @kbd{:WW}. | |
415 | |
416 @item Insert state | |
417 Insert state is the Vi insertion mode. @kbd{ESC} will take you back to | |
418 Vi state. Insert state editing can be done, including auto-indentation. By | |
419 default, Viper disables Emacs keybindings in Insert state. | |
420 | |
421 @item Replace state | |
422 Commands like @kbd{cw} invoke the Replace state. When you cross the | |
423 boundary of a replacement region (usually designated via a @samp{$} sign), | |
424 it will automatically change to Insert state. You do not have to worry | |
425 about it. The key bindings remain practically the same as in Insert | |
426 state. If you type ESC, Viper will switch to Vi command mode, terminating the | |
427 replacement state. @refill | |
428 @end table | |
429 | |
430 @cindex mode line | |
431 | |
432 The modes are indicated on the @dfn{mode line} as <E>, <I>, <V>, and <R>, | |
433 so that the multiple modes do not confuse you. Most of your editing can be | |
434 done in Vi and Insert states. Viper will try to make all new buffers be in Vi | |
435 state, but sometimes they may come up in Emacs state. @kbd{C-z} | |
436 will take you to Vi state in such a case. In some major modes, like Dired, | |
437 Info, Gnus, etc., you should not switch to Vi state (and Viper will not | |
438 attempt to do so) because these modes are not intended for text editing and | |
439 many of the Vi keys have special meaning there. If you plan to read news, | |
440 browse directories, read mail, etc., from Emacs (which you should start | |
441 doing soon!), you should learn about the meaning of the various keys in | |
442 those special modes (typing @kbd{C-h m} in a buffer provides | |
443 help with key bindings for the major mode of that buffer). | |
444 | |
445 If you switch to Vi in Dired or similar modes---no harm is | |
446 done. It is just that | |
447 the special keybindings provided by those modes will be temporarily | |
448 overshadowed by Viper's bindings. Switching back to Viper's | |
449 Emacs state will revive the environment provided by the current major mode. | |
450 | |
451 States in Viper are orthogonal to Emacs major modes, such as C mode or Dired | |
452 mode. You can turn Viper on and off for any Emacs state. When Viper is turned | |
453 on, Vi state can be used to move around. In Insert state, the bindings for | |
454 these modes can be accessed. For beginners (users at Viper levels 1 and 2), | |
455 these bindings are suppressed in Insert state, so that new users are not | |
456 confused by the Emacs states. Note that unless you allow Emacs bindings in | |
457 Insert state, you cannot do many interesting things, like language | |
458 sensitive editing. For the novice user (at Viper level 1), all major mode | |
459 bindings are turned off in Vi state as well. This includes the bindings for | |
460 key sequences that start with @kbd{C-c}, which practically means that all | |
461 major mode bindings are supported. @xref{Customization}, to find out how | |
462 to allow Emacs keys in Insert state. | |
463 | |
464 @menu | |
465 * Emacs State:: This is the state you should learn more about when | |
466 you get up to speed with Viper. | |
467 * Vi State:: Vi commands are executed in this state. | |
468 * Insert State:: You can enter text, and also can do sophisticated | |
469 editing if you know enough Emacs commands. | |
470 * Replace State:: Like Insert mode, but it is invoked via the | |
471 replacement commands, such as cw, C, R, etc. | |
472 @end menu | |
473 | |
474 @node Emacs State, Vi State, States in Viper, States in Viper | |
475 @subsection Emacs State | |
476 | |
477 @kindex @kbd{C-z} | |
478 @cindex Emacs state | |
479 | |
480 | |
481 You will be in this mode only by accident (hopefully). This is the state | |
482 Emacs is normally in (imagine!!). Now leave it as soon as possible by | |
483 typing @kbd{C-z}. The you will be in Vi state (sigh of relief) :-). | |
484 | |
485 Emacs state is actually a Viperism to denote all the major and minor modes | |
486 (@xref{Emacs Preliminaries}) other than Viper that Emacs can be in. Emacs | |
487 can have several modes, such as C mode for editing C programs, LaTeX mode | |
488 for editing LaTeX documents, Dired for directory editing, etc. These are | |
489 major modes, each with a different set of key-bindings. Viper states are | |
490 orthogonal to these Emacs major modes. The presence of these language | |
491 sensitive and other modes is a major win over Vi. @xref{Improvements over | |
492 Vi}, for more.@refill | |
493 | |
494 The bindings for these modes can be made available in the Viper Insert state | |
495 as well as in Emacs state. Unless you specify your user level as 1 (a | |
496 novice), all major mode key sequences that start with @kbd{C-x} and | |
497 @kbd{C-c} are also available in Vi state. This is important because major | |
498 modes designed for editing files, such as cc-mode or latex-mode, use key | |
499 sequences that begin with @kbd{C-x} and @kbd{C-c}. | |
500 | |
501 There is also a key that lets you temporarily escape to Vi command state | |
502 from Emacs state: typing @kbd{M-C-z} (or @kbd{ESC C-z}) will let | |
503 you execute a single Vi command while staying in Viper's Emacs state. | |
504 At present, this works only for 1-character Vi commands (and for some | |
505 complex commands). | |
506 | |
507 @node Vi State, Insert State, Emacs State, States in Viper | |
508 @subsection Vi State | |
509 | |
510 @cindex Vi state | |
511 | |
512 This is the Vi command mode. When Viper is in Vi state, you will see the sign | |
513 <V> in the mode line. Most keys will work as in Vi. The notable | |
514 exceptions are: | |
515 | |
516 @table @kbd | |
517 @item C-x | |
518 @kindex @kbd{C-x} | |
519 @kbd{C-x} is used to invoke Emacs commands, mainly those that do window | |
520 management. @kbd{C-x 2} will split a window, @kbd{C-x 0} will close a | |
521 window. @kbd{C-x 1} will close all other windows. @kbd{C-xb} is used to | |
522 switch buffers in a window, and @kbd{C-xo} to move through windows. | |
523 These are about the only necessary keystrokes. | |
524 For the rest, see the GNU Emacs Manual. | |
525 | |
526 @item C-c | |
527 @kindex @kbd{C-c} | |
528 For user levels 2 and higher, this key serves as a prefix key for the key | |
529 sequences used by various major modes. For users at Viper level 1, @kbd{C-c} | |
530 simply beeps. | |
531 | |
532 @item C-g and C-] | |
533 @kindex @kbd{C-g} | |
534 @kindex @kbd{C-]} | |
535 | |
536 These are the Emacs @samp{quit} keys. | |
537 There will be cases where you will have to | |
538 use @kbd{C-g} to quit. Similarly, @kbd{C-]} is used to exit | |
539 @samp{Recursive Edits} in Emacs for which there is no comparable Vi | |
540 functionality and no key-binding. Recursive edits are indicated by | |
541 @samp{[]} brackets framing the modes on the mode line. | |
542 @xref{Recursive Edit,Recursive | |
543 Edit,Recursive Edit,emacs,The GNU Emacs Manual}. | |
544 At user level 1, @kbd{C-g} is bound to @code{vip-info-on-file} | |
545 function instead. | |
546 @refill | |
547 @item Underscore | |
548 @kindex @kbd{_} | |
549 @cindex Meta key | |
550 | |
551 Viper uses @kbd{ESC} as a switch between Insert and Vi states. Emacs uses | |
552 @kbd{ESC} for Meta. We need a Meta key to call the Meta key functions | |
553 such as @kbd{M-x function name}. The underscore key, @kbd{_}, was chosen, | |
554 since it is the only reasonable, free Vi key left. Thus, in Vi state, to | |
555 get @kbd{M-x}, you should type @kbd{_x} (if the keyboard has no Meta key). | |
556 It is possible to use @kbd{ESC} as Meta, but then you cannot | |
557 press @kbd{ESC} multiple times in Vi state. @xref{Customization}, to find | |
558 out how to rebind ESC to be Meta.@refill | |
559 @end table | |
560 @noindent | |
561 Other differences are mostly improvements. The ones you should know | |
562 about are: | |
563 | |
564 @table @samp | |
565 @item Undo | |
566 @kindex @kbd{u} | |
567 @kbd{u} will undo. Undo can be repeated by the @kbd{.} key. Undo itself | |
568 can be undone. Another @kbd{u} will change the direction. The presence | |
569 of repeatable undo means that @kbd{U}, undoing lines, is not very | |
570 important. Therefore, @kbd{U} also calls @code{vip-undo}. | |
571 @cindex multiple undo | |
572 @cindex undo | |
573 | |
574 | |
575 @item Counts | |
576 Most commands, @kbd{~}, @kbd{[[}, @kbd{p}, @kbd{/}, @dots{}, etc., take counts. | |
577 | |
578 @comment ]] Just to balance parens | |
579 @item Regexps | |
580 Viper uses Emacs Regular Expressions for searches. These are a superset of | |
581 Vi regular | |
582 expressions, excepting the change-of-case escapes @samp{\u}, @samp{\L}, | |
583 @dots{}, etc. @xref{Regular Expressions,,Regular Expressions,emacs,The | |
584 GNU Emacs Manual}, for details. | |
585 Files specified to @kbd{:e} use @code{csh} regular expressions | |
586 (globbing, wildcards, what have you). | |
587 However, the function @code{vip-toggle-search-style}, bound to @kbd{C-c /}, | |
588 lets the user switch from search with regular expressions to plain vanilla | |
589 search and vice versa. It also lets one switch from case-sensitive search | |
590 to case-insensitive and back. | |
591 @xref{Viper Specials}, for more details. | |
592 @cindex regular expressions | |
593 @cindex vanilla search | |
594 @cindex case-sensitive search | |
595 @cindex case-insensitive search | |
596 @kindex @kbd{C-c /} | |
597 | |
598 @item Ex commands | |
599 @cindex Ex commands | |
600 The current working directory of a buffer is automatically inserted in the | |
601 minibuffer if you | |
602 type @kbd{:e} then space. | |
603 Absolute filenames are required less often in Viper. | |
604 For path names, | |
605 Emacs uses a convention that is slightly different from that of Unix. | |
606 It is designed to minimize the need for deleting path names that Emacs | |
607 provides in its prompts. (This is usually convenient, but occasionally | |
608 the prompt may suggest a wrong path name for you.) If you see a prompt | |
609 @kbd{/usr/foo/} and you wish to edit the file @kbd{~/.vip}, you don't | |
610 have to erase the prompt. Instead, simply continue typing what you | |
611 need. Emacs will interpret @kbd{/usr/foo/~/.vip} correctly. Similarly, | |
612 if the prompt is @kbd{~/foo/} and you need to get to @kbd{/bar/file}, keep | |
613 typing. Emacs interprets @kbd{~/foo//bar/} as @kbd{/bar/file}, since when it | |
614 sees @samp{//}, it understands that @kbd{~/foo/} is to be discarded. | |
615 | |
616 The command @kbd{:cd} will change the default directory for the | |
617 current buffer. The command @kbd{:e} will interpret the | |
618 filename argument in @code{csh}. @xref{Customization}, if you | |
619 want to change the default shell. | |
620 The command @kbd{:next} takes counts from | |
621 @kbd{:args}, so that @kbd{:rew} is obsolete. Also, @kbd{:args} will show only | |
622 the invisible files (i.e., those that are not currently seen in Emacs | |
623 windows). | |
624 | |
625 When applicable, Ex commands support file completion and history. This | |
626 means that by typing a partial file name and then @kbd{TAB}, Emacs will try | |
627 to complete the name or it will offer a menu of possible completions. | |
628 This works similarly to Tcsh and extends the behavior of Csh. While Emacs | |
629 is waiting for a file name, you can type @kbd{M-p} to get the previous file | |
630 name you typed. Repeatedly typing @kbd{M-p} and @kbd{M-n} will let you | |
631 browse through the file history. | |
632 | |
633 Like file names, partially typed Ex commands can be completed by typing | |
634 @kbd{TAB}, and Viper keeps the history of Ex commands. After typing | |
635 @kbd{:}, you can browse through the previously entered Ex commands by | |
636 typing @kbd{M-p} and @kbd{M-n}. Viper tries to rationalize when it puts Ex | |
637 commands on the history list. For instance, if you typed @kbd{:w! foo}, | |
638 only @kbd{:w!} will be placed on the history list. This is because the | |
639 last history element is the default that can be invoked simply by typing | |
640 @kbd{: RET}. If @kbd{:w! foo} were placed on the list, it would be all to | |
641 easy to override valuable data in another file. Reconstructing the full | |
642 command, @kbd{:w! foo}, from the history is still not that hard, since Viper | |
643 has a separate history for file names. By typing @kbd{: M-p}, you will get | |
644 @kbd{:w!} in the Minibuffer. Then, repeated @kbd{M-p} will get you through | |
645 the file history, inserting one file name after another. | |
646 | |
647 In contrast to @kbd{:w! foo}, if the command were @kbd{:r foo}, the entire | |
648 command will appear in the history list. This is because having @kbd{:r} | |
649 alone as a default is meaningless, since this command requires a file | |
650 argument. | |
651 @refill | |
652 @end table | |
653 @noindent | |
654 As Vi, Viper's destructive commands can be re-executed by typing `@kbd{.}'. | |
655 However, in addition, Viper keeps track of the history of such commands. This | |
656 history can be perused by typing @kbd{C-c M-p} and @kbd{C-c M-n}. | |
657 Having found the appropriate command, it can be then executed by typing | |
658 `@kbd{.}'. | |
659 @xref{Improvements over Vi}, for more information. | |
660 | |
661 @node Insert State, Replace State, Vi State, States in Viper | |
662 @subsection Insert State | |
663 | |
664 @cindex Insert state | |
665 | |
666 To avoid confusing the beginner (at Viper level 1 and 2), Viper makes only the | |
667 standard Vi keys available in Insert state. The implication is that | |
668 Emacs major modes cannot be used Insert state. | |
669 It is strongly recommended that as soon as you are comfortable, make the | |
670 Emacs state bindings visible (by changing your user level to 3 or higher). | |
671 @xref{Customization}, | |
672 to see how to do this.@refill | |
673 | |
674 Once this is done, it is possible to do quite a bit of editing in | |
675 Insert state. For instance, Emacs has a @dfn{yank} command, @kbd{C-y}, | |
676 which is similar to Vi's @kbd{p}. However, unlike @kbd{p}, @kbd{C-y} can be | |
677 used in Insert state of Viper. Emacs also has a kill ring where it keeps | |
678 pieces of text you deleted while editing buffers. The command @kbd{M-y} is | |
679 used to delete the text previously put back by Emacs' @kbd{C-y} or by Vi's | |
680 @kbd{p} command and reinsert text that was placed on the kill-ring earlier. | |
681 | |
682 This works both in Vi and Insert states. | |
683 In Vi state, @kbd{M-y} is a much better alternative to the usual Vi's way | |
684 of recovering the 10 previously deleted chunks of text. In Insert state, | |
685 you can | |
686 use this as follows. Suppose you deleted a piece of text and now you need | |
687 to re-insert it while editing in Insert mode. The key @kbd{C-y} will put | |
688 back the most recently deleted chunk. If this is not what you want, type | |
689 @kbd{M-y} repeatedly and, hopefully, you will find the chunk you want. | |
690 | |
691 Finally, in Insert and Replace states, Viper provides the history of | |
692 pieces of text inserted in previous insert or replace commands. These | |
693 strings of text can be recovered by repeatedly typing @kbd{C-c M-p} or | |
694 @kbd{C-c M-n} while in Insert or Replace state. (This feature is disabled | |
695 in the minibuffer: the above keys are usually bound to other histories, | |
696 which are more appropriate in the minibuffer.) | |
697 | |
698 | |
699 @cindex Meta key | |
700 | |
701 You can call Meta functions from Insert state. The Vi-to-Emacs toggle key, | |
702 normally @kbd{C-z}, is bound to Meta in Insert state. Thus @kbd{M-x} is | |
703 typed as @kbd{C-zx}. The key @kbd{_} will now insert itself---it is not a | |
704 Meta key in Insert state. (It is well understood that switching Meta keys | |
705 around is inconvenient. However, there seems to be no way around this | |
706 problem, short of changing Vi ESC key to something | |
707 else. @xref{Customization}, for the information on @code{vip-ESC-key}, which | |
708 can be used to free up @kbd{ESC} and designate some other key to do escape | |
709 from Insert state to Vi state.) | |
710 | |
711 Other Emacs commands that are useful in Insert state are @kbd{C-e} | |
712 and @kbd{C-a}, which move the cursor to the end and the beginning of the | |
713 current line, respectively. You can also use @kbd{M-f} and @kbd{M-b}, | |
714 which move the cursor forward (or backward) one word. | |
715 If your display has a Meta key, these functions are invoked by holding the | |
716 Meta key and then typing @kbd{f} and @kbd{b}, respectively. On displays | |
717 without the Meta key, these functions are invoked by typing | |
718 @kbd{C-z f} and @kbd{C-z b} (@kbd{C-z} simulates the Meta key in Insert | |
719 state, as explained above). | |
720 | |
721 When Viper is in Insert state, you will see <I> in the mode line. | |
722 | |
723 @node Replace State,, Insert State, States in Viper | |
724 @subsection Replace State | |
725 | |
726 @cindex Replace state | |
727 | |
728 This state is entered through Vi replacement commands, such as @kbd{C}, | |
729 @kbd{cw}, etc., or by typing @kbd{R}. In Replace state, Viper puts <R> in the | |
730 mode line to let you know which state is in effect. If Replace state is | |
731 entered through @kbd{R}, Viper stays in that state until the user hits ESC. | |
732 If this state is entered via the other replacement commands, then Replace | |
733 state is in effect until you hit @kbd{ESC} or until you cross the rightmost | |
734 boundary of the replacement region. In the latter case, Viper changes its | |
735 state from Replace to Insert (which you will notice by the change in the | |
736 mode line). | |
737 | |
738 Since Viper runs under Emacs, it is possible to switch between buffers | |
739 while in Replace state. You can also move the cursor using the arrow keys | |
740 (even on dumb terminals!) and the mouse. Because of this freedom (which is | |
741 unattainable in regular Vi), it is possible to take the cursor outside the | |
742 replacement region. (This may be necessary for several reasons, including | |
743 the need to enable text selection and region-setting with the mouse.) | |
744 | |
745 The issue then arises as to what to do when the user | |
746 hits the ESC key. In Vi, this would cause the text between cursor and | |
747 the end of the replacement region to be deleted. But what if, as is | |
748 possible in Viper, the cursor is not inside the replacement region? | |
749 | |
750 To solve the problem, Viper keeps track of the last cursor position while it | |
751 was still inside the replacement region. So, in the above situation, Viper | |
752 would delete text between this position and the end of the replacement | |
753 region. | |
754 | |
755 @node The Minibuffer,Multiple Files in Viper, States in Viper, Overview | |
756 @section The Minibuffer | |
757 | |
758 @cindex Minibuffer | |
759 | |
760 The Minibuffer is where commands are entered in. Editing can be done | |
761 by commands from Insert state, namely: | |
762 | |
763 @table @kbd | |
764 @item C-h | |
765 Backspace | |
766 @item C-w | |
767 Delete Word | |
768 @item C-u | |
769 Erase line | |
770 @item C-v | |
771 Quote the following character | |
772 @item RET | |
773 Execute command | |
774 @item C-g and C-] | |
775 Emacs quit and abort keys. These may be necessary. @xref{Vi State}, for an | |
776 explanation. | |
777 @item M-p and M-n | |
778 These keys are bound to functions that peruse minibuffer history. The | |
779 precise history to be perused depends on the context. It may be the history | |
780 of search strings, Ex commands, file names, etc. | |
781 @end table | |
782 | |
783 Most of the Emacs keys are functional in the Minibuffer. While in the | |
784 Minibuffer, Viper tries to make editing resemble Vi's behavior when the | |
785 latter is waiting for the user to type an Ex command. In particular, you | |
786 can use the regular Vi commands to edit the Minibuffer. You can switch | |
787 between the Vi state and Insert state at will, and even use the replace mode. | |
788 Initially, the Minibuffer comes up in Insert state. | |
789 | |
790 Some users prefer plain Emacs bindings in the Minibuffer. To this end, set | |
791 @code{vip-vi-style-in-minibuffer} to @code{nil} in @file{.vip}. | |
792 @xref{Customization}, to learn how to do this. | |
793 | |
794 When the Minibuffer changes Viper states, you will notice that the appearance | |
795 of the text there changes as well. This is useful because the Minibuffer | |
796 has no mode line to tell which Vi state it is in. | |
797 The appearance of the text in the Minibuffer can be changed. | |
798 @xref{Viper Specials}, for more details. | |
799 | |
800 @node Multiple Files in Viper,Unimplemented Features,The Minibuffer,Overview | |
801 @section Multiple Files in Viper | |
802 | |
803 @cindex multiple files | |
804 @cindex managing multiple files | |
805 | |
806 Viper can edit multiple files. This means, for example that you never need | |
807 to suffer through @code{No write since last change} errors. | |
808 Some Viper elements are common over all the files. | |
809 | |
810 @table @samp | |
811 @item Textmarkers | |
812 @cindex markers | |
813 @cindex textmarkers | |
814 Textmarkers remember @emph{files and positions}. | |
815 If you set marker @samp{a} in | |
816 file @file{foo}, start editing file @file{bar} and type @kbd{'a}, then | |
817 @emph{YOU WILL SWITCH TO FILE @file{foo}}. You can see the contents of a | |
818 textmarker using the Viper command @kbd{[<a-z>} where <a-z> are the | |
819 textmarkers, e.g., @kbd{[a} to view marker @samp{a} .@refill | |
820 @item Repeated Commands | |
821 Command repetitions are common over files. Typing @kbd{!!} will repeat the | |
822 last @kbd{!} command whichever file it was issued from. | |
823 Typing @kbd{.} will repeat the last command from any file, and | |
824 searches will repeat the last search. Ex commands can be repeated by typing | |
825 @kbd{:RET}.@refill | |
826 Note: in some rare cases, that @kbd{:RET} may do something dangerous. | |
827 However, usually its effect can be undone by typing @kbd{u}. | |
828 @item Registers | |
829 @cindex registers | |
830 Registers are common to files. Also, text yanked with @kbd{y} can be | |
831 put back (@kbd{p}) into any file. The Viper command @kbd{]<a-z>}, where <a-z> are | |
832 the registers, can be used to look at the contents of a register, e.g., | |
833 type @kbd{]a} to view register @samp{a}. | |
834 | |
835 There is one difference in text deletion that you should be | |
836 aware of. This difference comes from Emacs and was adopted in Viper | |
837 because we find it very useful. In Vi, if you delete a line, say, and then | |
838 another line, these two deletions are separated and are put back | |
839 separately if you use the @samp{p} command. In Emacs (and Viper), successive | |
840 series of deletions that are @emph{not interrupted} by other commands are | |
841 lumped together, so the deleted text gets accumulated and can be put back | |
842 as one chunk. If you want to break a sequence of deletions so that the | |
843 newly deleted text could be put back separately from the previously deleted | |
844 text, you should perform a non-deleting action, e.g., move the cursor one | |
845 character in any direction. | |
846 @item Absolute Filenames | |
847 @cindex absolute paths | |
848 The current directory name for a file is automatically prepended to the | |
849 file name in any | |
850 @kbd{:e}, @kbd{:r}, @kbd{:w}, etc., command (in Emacs, each buffer has a | |
851 current directory). | |
852 This directory is inserted in the Minibuffer once you type space after | |
853 @kbd{:e, r}, etc. Viper also supports completion of file names and Ex | |
854 commands (@kbd{TAB}), and it keeps track of | |
855 command and file history (@kbd{M-p}, @kbd{M-n}). | |
856 Absolute filenames are required less | |
857 often in Viper. | |
858 | |
859 You should be aware that Emacs interprets @kbd{/foo/bar//bla} as | |
860 @kbd{/bla} and @kbd{/foo/~/bar} as @kbd{~/bar}. This is designed to | |
861 minimize the need for erasing path names that Emacs suggests in its | |
862 prompts, if a suggested path name is not what you wanted. | |
863 | |
864 The command @kbd{:cd} will change the default directory for the | |
865 current Emacs buffer. The Ex command @kbd{:e} will interpret the | |
866 filename argument in @samp{csh}, by default. @xref{Customization}, if you | |
867 want to change this. | |
868 @end table | |
869 | |
870 @noindent | |
871 Currently undisplayed files can be listed using the @kbd{:ar} command. The | |
872 command @kbd{:n} can be given counts from the @kbd{:ar} list to switch to | |
873 other files. | |
874 | |
875 @node Unimplemented Features,,Multiple Files in Viper,Overview | |
876 @section Unimplemented Features | |
877 | |
878 Unimplemented features include: | |
879 | |
880 @itemize @bullet | |
881 @item | |
882 @kbd{:ab} and @kbd{:una} are not implemented. | |
883 Both @kbd{:map} and @kbd{:ab} are considered obsolete, since Emacs has much | |
884 more powerful facilities for defining keyboard macros and abbreviations. | |
885 @item | |
886 @kbd{:set option?} is not implemented. The current | |
887 @kbd{:set} can also be used to set Emacs variables. | |
888 @item | |
889 @kbd{:se list} requires modification of the display code for Emacs, so | |
890 it is not implemented. | |
891 A useful alternative is @code{cat -t -e file}. Unfortunately, it cannot | |
892 be used directly inside Emacs, since Emacs will obdurately change @samp{^I} | |
893 back to normal tabs.@refill | |
894 @end itemize | |
895 | |
896 @comment node-name, next, previous, up | |
897 @node Improvements over Vi, Customization, Overview, Top | |
898 @chapter Improvements over Vi | |
899 | |
900 Some common problems with Vi and Ex have been solved in Viper. This | |
901 includes better implementation of existing commands, new commands, and | |
902 the facilities provided by Emacs. | |
903 | |
904 @menu | |
905 * Basics:: Basic Viper differences, Multi-file effects. | |
906 * Undo and Backups:: Multiple undo, auto-save, backups and changes | |
907 * History:: History for Ex and Vi commands. | |
908 * Macros and Registers:: Keyboard Macros (extended ".") @@reg execution. | |
909 * Completion:: Filename and Command Completion for Ex. | |
910 * Improved Search:: Incremental Search and Buffer Content Search. | |
911 * Abbreviation Facilities:: Normal Abbrevs, Templates, and Dynamic Abbrevs. | |
912 * Movement and Markers:: Screen Editor movements, viewing textmarkers. | |
913 * New Commands:: Commands that do not exist in Vi. | |
914 * Useful Packages:: A Sampling of some Emacs packages, and things | |
915 you should know about. | |
916 @end menu | |
917 | |
918 @node Basics, Undo and Backups, Improvements over Vi, Improvements over Vi | |
919 @section Basics | |
920 | |
921 The Vi command set is based on the idea of combining motion commands | |
922 with other commands. The motion command is used as a text region | |
923 specifier for other commands. | |
924 We classify motion commands into @dfn{point commands} and | |
925 @dfn{line commands}.@refill | |
926 | |
927 @cindex point commands | |
928 | |
929 The point commands are: | |
930 | |
931 @quotation | |
932 @kbd{h}, @kbd{l}, @kbd{0}, @kbd{$}, @kbd{w}, @kbd{W}, @kbd{b}, @kbd{B}, | |
933 @kbd{e}, @kbd{E}, @kbd{(}, @kbd{)}, @kbd{/}, @kbd{?}, @kbd{`}, @kbd{f}, | |
934 @kbd{F}, @kbd{t}, @kbd{T}, @kbd{%}, @kbd{;}, @kbd{,}, @kbd{^} | |
935 @end quotation | |
936 | |
937 @cindex line commands | |
938 | |
939 The line commands are: | |
940 | |
941 @quotation | |
942 @kbd{j}, @kbd{k}, @kbd{+}, @kbd{-}, @kbd{H}, @kbd{M}, @kbd{L}, @kbd{@{}, | |
943 @kbd{@}}, @kbd{G}, @kbd{'}, @kbd{[[}, @kbd{]]}, @kbd{[]} | |
944 @end quotation | |
945 | |
946 @cindex region | |
947 @cindex region specification | |
948 @cindex expanding (region) | |
949 @cindex describing regions | |
950 @cindex movement commands | |
951 | |
952 @noindent | |
953 If a point command is given as an argument to a modifying command, the | |
954 region determined by the point command will be affected by the modifying | |
955 command. On the other hand, if a line command is given as an argument to a | |
956 modifying command, the region determined by the line command will be | |
957 enlarged so that it will become the smallest region properly containing the | |
958 region and consisting of whole lines (we call this process @dfn{expanding | |
959 the region}), and then the enlarged region will be affected by the modifying | |
960 command. | |
961 Text Deletion Commands (@xref{Deleting Text}), Change commands | |
962 (@xref{Changing Text}), even Shell Commands (@xref{Shell Commands}) | |
963 use these commands to describe a region of text to operate on. | |
964 Thus, type @kbd{dw} to delete a word, @kbd{>@}} to shift a paragraph, or | |
965 @kbd{!'afmt} to format a region from @samp{point} to textmarker | |
966 @samp{a}. | |
967 | |
968 @cindex r and R region specifiers | |
969 | |
970 Viper adds the region specifiers @samp{r} and @samp{R}. Emacs has a | |
971 special marker called @dfn{mark}. The text-area between the current cursor | |
972 position @dfn{point} and the @dfn{mark} is called the @dfn{region}. | |
973 @samp{r} specifies the raw region and @samp{R} is the expanded region | |
974 (i.e., the minimal contiguous chunk of full lines that contains the raw | |
975 region). | |
976 @kbd{dr} will now delete the region, @kbd{>r} will shift it, etc. | |
977 @kbd{r,R} are not motion commands, however. The special mark is set by | |
978 @kbd{m.} and other commands. @xref{Marking}, for more info. | |
979 | |
980 Viper also adds counts to most commands for which it would make sense. | |
981 | |
982 In the Overview chapter, some Multiple File issues were discussed | |
983 (@xref{Multiple Files in Viper}). In addition to the files, Emacs has | |
984 buffers. These can be seen in the @kbd{:args} list and switched using | |
985 @kbd{:next} if you type @kbd{:set ex-cycle-through-non-files t}, or | |
986 specify @code{(setq ex-cycle-through-non-files t)} in your @file{.vip} | |
987 file. @xref{Customization}, for details. | |
988 | |
989 @node Undo and Backups, History, Basics, Improvements over Vi | |
990 @section Undo and Backups | |
991 | |
992 @cindex undo | |
993 | |
994 Viper provides multiple undo. The number of undo's and the size is limited | |
995 by the machine. The Viper command @kbd{u} does an undo. Undo can be | |
996 repeated by typing @kbd{.} (a period). Another @kbd{u} will undo the undo, | |
997 and further | |
998 @kbd{.} will repeat it. Typing @kbd{u} does the first undo, and changes the | |
999 direction. | |
1000 | |
1001 @cindex backup files | |
1002 @cindex auto save | |
1003 | |
1004 Since the undo size is limited, Viper can create backup files and | |
1005 auto-save files. It will normally do this automatically. It is possible | |
1006 to have numbered backups, etc. For details, @pxref{Backup,,Backup and | |
1007 Auto-Save,emacs,The GNU Emacs Manual} @refill | |
1008 | |
1009 @comment [ balance parens | |
1010 @cindex viewing registers and markers | |
1011 @cindex registers | |
1012 @cindex markers | |
1013 @cindex textmarkers | |
1014 | |
1015 The results of the 9 previous changes are available in the 9 numeric | |
1016 registers, as in Vi. The extra goody is the ability to @emph{view} these | |
1017 registers, in addition to being able to access them through @kbd{p} and | |
1018 @kbd{M-y} (@xref{Insert State}, for details.) | |
1019 The Viper command @kbd{] register} will display the contents of any | |
1020 register, numeric or alphabetical. The related command @kbd{[ textmarker} | |
1021 will show the text around the textmarker. @samp{register} and @samp{textmarker} | |
1022 can be any letters from a through z. | |
1023 @comment ] balance parens | |
1024 | |
1025 @node History, Macros and Registers, Undo and Backups,Improvements over Vi | |
1026 @section History | |
1027 | |
1028 @cindex history | |
1029 @cindex Minibuffer | |
1030 | |
1031 History is provided for Ex commands, Vi searches, file names, pieces of | |
1032 text inserted in earlier commands that use Insert or Replace state, and for | |
1033 destructive commands in Vi state. These are | |
1034 useful for fixing those small typos that screw up searches and @kbd{:s}, | |
1035 and for eliminating routine associated with repeated typing of file names | |
1036 or pieces of text that need to be inserted frequently. | |
1037 At the @kbd{:} or @kbd{/} prompts in the Minibuffer, you can do the following: | |
1038 | |
1039 @table @kbd | |
1040 @item M-p and M-n | |
1041 To move to previous and next history items. This causes the history | |
1042 items to appear on the command line, where you can edit them, or | |
1043 simply type Return to execute. | |
1044 @item M-r and M-s | |
1045 To search backward and forward through the history. | |
1046 @item RET | |
1047 Type RET to accept a default (which is displayed in the prompt). | |
1048 @end table | |
1049 | |
1050 The history of insertions can be perused by | |
1051 typing @kbd{C-c M-p} and @kbd{C-c M-n} while in Insert or Replace state. | |
1052 The history of destructive Vi commands can be perused via the same keys | |
1053 when Viper is in Vi state. @xref{Viper Specials}, for details. | |
1054 | |
1055 All Ex commands have a file history. For instance, typing @kbd{:e}, space | |
1056 and then @kbd{M-p} will bring up the name of the previously typed file | |
1057 name. Repeatedly typing @kbd{M-p}, @kbd{M-n}, etc., will let you browse | |
1058 through the file history. | |
1059 | |
1060 Similarly, commands that have to do with switching buffers | |
1061 have a buffer history, and commands that expect strings or regular | |
1062 expressions keep a history on those items. | |
1063 | |
1064 @node Macros and Registers,Completion,History,Improvements over Vi | |
1065 @section Macros and Registers | |
1066 | |
1067 @cindex keyboard macros | |
1068 @cindex macros | |
1069 @cindex registers | |
1070 @cindex register execution | |
1071 | |
1072 Viper facilitates the use of Emacs-style keyboard macros. @kbd{@@#} will | |
1073 start a macro definition. As you type, the commands will be executed, and | |
1074 remembered (This is called ``learn mode'' in some editors.) | |
1075 @kbd{@@register} will complete the macro, putting it into @samp{register}, | |
1076 where @samp{register} is any character from @samp{a} through @samp{z}. Then | |
1077 you can execute this macro using @kbd{@@register}. It is, of course, | |
1078 possible to yank some text into a register and execute it using | |
1079 @kbd{@@register}. Typing @kbd{@@@@}, @kbd{@@RET}, or @kbd{@@LF} will | |
1080 execute the last macro that was executed using @kbd{@@register}.@refill | |
1081 | |
1082 Viper will automatically lowercase the register, so that pressing the | |
1083 @kbd{SHIFT} key for @kbd{@@} will not create problems. This is for | |
1084 @kbd{@@} macros and @kbd{"p} @emph{only}. In the case of @kbd{y}, | |
1085 @kbd{"Ayy} will append to @emph{register a}. For @kbd{[,],',`}, it | |
1086 is an error to use a Uppercase register name. | |
1087 | |
1088 @comment [ balance parens | |
1089 @cindex viewing registers and markers | |
1090 | |
1091 The contents of a register can be seen by @kbd{]register}. (@kbd{[textmarker} | |
1092 will show the contents of a textmarker). | |
1093 @comment ] balance parens | |
1094 | |
1095 @cindex last keyboard macro | |
1096 | |
1097 The last keyboard macro can also be executed using | |
1098 @kbd{*}, and it can be yanked into a register using @kbd{@@!register}. | |
1099 This is useful for Emacs style keyboard macros defined using @kbd{C-x(} | |
1100 and @kbd{C-x)}. Emacs keyboard macros have more capabilities. | |
1101 @xref{Keyboard Macros,,Keyboard Macros,emacs, The GNU Emacs Manual}, for | |
1102 details.@refill | |
1103 | |
1104 Keyboard Macros allow an interesting form of Query-Replace: | |
1105 @kbd{/pattern} or @kbd{n} to go to the next pattern (the query), followed by a | |
1106 Keyboard Macro execution @kbd{@@@@} (the replace). | |
1107 | |
1108 Viper also provides Vi-style macros. @xref{Vi Macros}, for details. | |
1109 | |
1110 | |
1111 @node Completion, Improved Search, Macros and Registers, Improvements over Vi | |
1112 @section Completion | |
1113 | |
1114 @cindex completion | |
1115 | |
1116 Completion is done when you type @kbd{TAB}. The Emacs completer does not | |
1117 grok wildcards in filenames. Once you type a wildcard, the completer will | |
1118 no longer work for that path. Remember that Emacs interprets a file name | |
1119 of the form @kbd{/foo//bar} as @kbd{/bar} and @kbd{/foo/~/bar} as | |
1120 @kbd{~/bar}. | |
1121 | |
1122 @node Improved Search, Abbreviation Facilities, Completion, Improvements over Vi | |
1123 @section Improved Search | |
1124 | |
1125 @cindex buffer search | |
1126 @cindex word search | |
1127 | |
1128 Viper provides buffer search, the ability to search the buffer for a region | |
1129 under the cursor. You have to turn this on in @file{.vip} either by calling | |
1130 | |
1131 @example | |
1132 (vip-buffer-search-enable) | |
1133 @end example | |
1134 | |
1135 @noindent | |
1136 or by setting @code{vip-buffer-search-char} to, say, @kbd{f3}: | |
1137 @example | |
1138 (setq vip-buffer-search-char [f3]) | |
1139 @end example | |
1140 | |
1141 @noindent | |
1142 If the user calls @code{vip-buffer-search-enable} explicitly (the first | |
1143 method), then @code{vip-buffer-search-char} will be set to @kbd{g}. | |
1144 Regardless of how this feature is enabled, the key | |
1145 @code{vip-buffer-search-char} will take movement commands, like | |
1146 @kbd{w,/,e}, to find a region and then search for the contents of that | |
1147 region. This command is very useful for searching for variable names, etc., | |
1148 in a program. The search can be repeated by @kbd{n} or reversed by @kbd{N}. | |
1149 | |
1150 @cindex incremental search | |
1151 | |
1152 Emacs provides incremental search. As you type the string in, the | |
1153 cursor will move to the next match. You can snarf words from the buffer | |
1154 as you go along. Incremental Search is normally bound to @kbd{C-s} and | |
1155 @kbd{C-r}. @xref{Customization}, to find out how to change the bindings | |
1156 of @kbd{C-r or C-s}. | |
1157 For details, @pxref{Incremental Search,,Incremental | |
1158 Search,emacs,The GNU Emacs Manual} @refill | |
1159 | |
1160 @cindex query replace | |
1161 | |
1162 Viper also provides a query replace function that prompts through the | |
1163 Minibuffer. It is invoked by the @kbd{Q} key in Vi state. | |
1164 | |
1165 @cindex mouse search | |
1166 | |
1167 On a window display, Viper supports mouse search, i.e., you can search for a | |
1168 word by clicking on it. @xref{Viper Specials}, for details. | |
1169 | |
1170 Finally, on a window display, Viper highlights search patterns as it finds | |
1171 them. This is done through what is known as @emph{faces} in Emacs. The | |
1172 variable that controls how search patterns are highlighted is | |
1173 @code{vip-search-face}. | |
1174 If you don't want any highlighting at all, put | |
1175 @example | |
1176 (copy-face 'default 'vip-search-face) | |
1177 @end example | |
1178 @vindex @code{vip-search-face} | |
1179 @noindent | |
1180 in @file{~/.vip}. If you want to change how patterns are highlighted, you | |
1181 will have to set the variable @code{vip-search-face} to some other face, | |
1182 such as @code{highlight}. If none of the existing faces fits the bill, you | |
1183 may have to create your own. Further details on faces can be found | |
1184 in the Emacs Lisp Manual. | |
1185 | |
1186 @node Abbreviation Facilities,Movement and Markers,Improved Search,Improvements over Vi | |
1187 @section Abbreviation Facilities | |
1188 | |
1189 @cindex abbrevs | |
1190 | |
1191 It is possible in Emacs to define abbrevs based on the contents of the | |
1192 buffer. | |
1193 Sophisticated templates can be defined using the Emacs abbreviation | |
1194 facilities. @xref{Abbrevs,,Abbreviations,emacs,The GNU Emacs Manual}, for | |
1195 details. | |
1196 | |
1197 @cindex dynamic abbrevs | |
1198 | |
1199 Emacs also provides Dynamic Abbreviations. Given a partial word, Emacs | |
1200 will search the buffer to find an extension for this word. For instance, | |
1201 one can type @samp{Abbreviations} by typing @samp{A}, followed by a keystroke | |
1202 that completed the @samp{A} to @samp{Abbreviations}. Repeated typing | |
1203 will search further back in the buffer, so that one could get | |
1204 @samp{Abbrevs} by repeating the | |
1205 keystroke, which appears earlier in the text. Emacs binds this to | |
1206 @kbd{ESC /}, so you will have to find a key and bind the function | |
1207 @code{dabbrev-expand} to that key. | |
1208 Facilities like this make Vi's @kbd{:ab} command obsolete. | |
1209 | |
1210 @node Movement and Markers, New Commands, Abbreviation Facilities, Improvements over Vi | |
1211 @section Movement and Markers | |
1212 | |
1213 @cindex Ex style motion | |
1214 @cindex line editor motion | |
1215 | |
1216 Viper can be set free from the line--limited movements in Vi, such as @kbd{l} | |
1217 refusing to move beyond the line, @kbd{ESC} moving one character back, | |
1218 etc. These derive from Ex, which is a line editor. If your @file{.vip} | |
1219 contains | |
1220 | |
1221 @example | |
1222 @code{(setq vip-ex-style-motion nil)} | |
1223 @end example | |
1224 | |
1225 @noindent | |
1226 the motion will be a true screen editor motion. One thing you must then | |
1227 watch out for is that it is possible to be on the end-of-line character. | |
1228 The keys @kbd{x} and @kbd{%} will still work correctly, i.e., as if they | |
1229 were on the last character. | |
1230 | |
1231 @vindex @code{vip-syntax-preference} | |
1232 @cindex syntax table | |
1233 | |
1234 The word-movement commands @kbd{w}, @kbd{e}, etc., and the associated | |
1235 deletion/yanking commands, @kbd{dw}, @kbd{yw}, etc., can be made to | |
1236 understand Emacs syntax tables. If the variable | |
1237 @code{vip-syntax-preference} is set to @code{'strict-vi} (the default) then | |
1238 the meaning of @emph{word} is the same as in | |
1239 Vi. However, if the value is @code{'reformed-vi} then the alphanumeric | |
1240 symbols will be those specified by the current Emacs syntax table (which | |
1241 may be different for different major modes) plus the underscore symbol | |
1242 @code{_}. The user can also specify the value @code{'emacs}, which would | |
1243 make Viper use exactly the Emacs notion of word. In particular, the | |
1244 underscore may not be part of a word. Finally, if | |
1245 @code{vip-syntax-preference} is set to @code{'extended}, Viper words would | |
1246 consist of characters that are classified as alphanumeric @emph{or} as | |
1247 parts of symbols. This is convenient for writing programs and in many other | |
1248 situations. | |
1249 | |
1250 @code{vip-syntax-preference} is a local variable, so it can have different | |
1251 values for different major modes. For instance, in programming modes it can | |
1252 have the value @code{'extended}. In text modes where words contain special | |
1253 characters, such as European (non-English) letters, Cyrillic letters, etc., | |
1254 the value can be @code{'reformed-vi} or @code{'emacs}. | |
1255 | |
1256 Changes to @code{vip-syntax-preference} should be done in the hooks to | |
1257 various major modes. Furthermore, for these changes to take effect, you | |
1258 should execute @code{(vip-update-alphanumeric-class)} right after changing | |
1259 | |
1260 The above discussion of the meaning of Viper's words concerns only Viper's | |
1261 movement commands. In regular expressions, words remain the same as in | |
1262 Emacs. That is, the expressions @code{\w}, @code{\>}, @code{\<}, etc., use | |
1263 Emacs' idea of what is a word, and they don't look into the value of | |
1264 variable @code{vip-syntax-preference}. This is because Viper doesn't change | |
1265 syntax tables in fear of upsetting the various major modes that set these | |
1266 tables. | |
1267 | |
1268 @cindex textmarkers | |
1269 | |
1270 Textmarkers in Viper remember the file and the position, so that you can | |
1271 switch files by simply doing @kbd{'a}. If you set up a regimen for using | |
1272 Textmarkers, this is very useful. Contents of textmarkers can be viewed | |
1273 by @kbd{[marker}. (Contents of registers can be viewed by @kbd{]register}). | |
1274 | |
1275 @node New Commands, Useful Packages, Movement and Markers, Improvements over Vi | |
1276 @section New Commands | |
1277 | |
1278 These commands have no Vi analogs. | |
1279 | |
1280 @table @kbd | |
1281 @item C-x, C-c | |
1282 @kindex @kbd{C-x} | |
1283 @kindex @kbd{C-c} | |
1284 @kbd{C-x} will exit from Vi state and return to Emacs state | |
1285 @emph{temporarily}. If | |
1286 you hit one of these keys, Emacs will believe | |
1287 that you hit that key in Emacs state. For example, if you hit @kbd{C-x} | |
1288 followed by @kbd{2}, then the current window will be split into 2 and you | |
1289 will be in Vi state again. Except for novice users, @kbd{C-c} is also set | |
1290 to temporarily escape to Emacs and execute a command from the current | |
1291 major mode. | |
1292 @kbd{ESC} will do the same, if | |
1293 you configure @key{ESC} as Meta by setting @code{vip-no-multiple-ESC} to nil | |
1294 in @file{.vip}. @xref{Customization}. @kbd{C-z} | |
1295 in Insert state will make Emacs think @kbd{Meta} has been hit.@refill | |
1296 @item \ | |
1297 @kindex @kbd{\} | |
1298 Escape to Emacs to execute a single Emacs command. For instance, @kbd{\ | |
1299 ESC} will act like a Meta key. | |
1300 @item Q | |
1301 @kindex @kbd{Q} | |
1302 @cindex query replace | |
1303 @kbd{Q} is for query replace. By default, | |
1304 each string to be replaced is treated as a regular expression. You can use | |
1305 @code{(setq vip-re-query-replace nil)} in your @file{.emacs} file to | |
1306 turn this off. (For normal searches, @kbd{:se nomagic} will work. Note | |
1307 that @kbd{:se nomagic} turns Regexps off completely, unlike Vi). | |
1308 @item v | |
1309 @itemx V | |
1310 @itemx C-v | |
1311 @kindex @kbd{v} | |
1312 @kindex @kbd{V} | |
1313 @kindex @kbd{C-v} | |
1314 These keys are used to visit files. @kbd{v} will switch to a buffer | |
1315 visiting file whose name can be entered in the Minibuffer. @kbd{V} is | |
1316 similar, but will use a window different from the current window. | |
1317 @kbd{C-v} is like @kbd{V}, except that a new frame (X window) will be used | |
1318 instead of a new Emacs window. | |
1319 @item # | |
1320 @kindex @kbd{#} | |
1321 If followed by a certain character @var{ch}, it becomes an operator whose | |
1322 argument is the region determined by the motion command that follows | |
1323 (indicated as <move>). | |
1324 Currently, @var{ch} can be one of @kbd{c}, @kbd{C}, @kbd{g}, @kbd{q}, and | |
1325 @kbd{s}. For instance, @kbd{#qr} will prompt you for a string and then | |
1326 prepend this string to each line in the buffer.@refill | |
1327 @item # c | |
1328 @kindex @kbd{#c<move>} | |
1329 @cindex changing case | |
1330 Change upper case characters in the region to lower case | |
1331 (@code{downcase-region}). | |
1332 Emacs command @kbd{M-l} does the same for words. | |
1333 @item # C | |
1334 @kindex @kbd{#C<move>} | |
1335 Change lower case characters in the region to upper case. For instance, | |
1336 @kbd{# C 3 w} will capitalize 3 words from the current point | |
1337 (@code{upcase-region}). | |
1338 Emacs command @kbd{M-u} does the same for words. | |
1339 @item # g | |
1340 @kindex @kbd{#g<move>} | |
1341 Execute last keyboard macro for each line in the region | |
1342 (@code{vip-global-execute}).@refill | |
1343 @item # q | |
1344 @kindex @kbd{#q<move>} | |
1345 Insert specified string at the beginning of each line in the region | |
1346 (@code{vip-quote-region}). | |
1347 @item # s | |
1348 @kindex @kbd{#s<move>} | |
1349 Check spelling of words in the region (@code{spell-region}). | |
1350 The function used for spelling is determined from the variable | |
1351 @code{vip-spell-function}. | |
1352 @vindex @code{vip-spell-function} | |
1353 @item * | |
1354 @kindex @kbd{*} | |
1355 Call last keyboard macro. | |
1356 @item m . | |
1357 Set mark at point and push old mark off the ring | |
1358 @item m< | |
1359 @item m> | |
1360 Set mark at beginning and end of buffer, respectively. | |
1361 @item m, | |
1362 Jump to mark and pop mark off the ring. @xref{Mark,,Mark,emacs,The GNU | |
1363 Emacs Manual}, for more info. | |
1364 @item ] register | |
1365 @kindex @kbd{]<a-z>} | |
1366 View contents of register | |
1367 @item [ textmarker | |
1368 @kindex @kbd{[<a-z>} | |
1369 View filename and position of textmarker | |
1370 @item @@# | |
1371 @item @@register | |
1372 @item @@! | |
1373 @kindex @kbd{@@#} | |
1374 @kindex @kbd{@@<a-z>} | |
1375 @kindex @kbd{@@!} | |
1376 @cindex keyboard macros | |
1377 @cindex register execution | |
1378 | |
1379 Begin/end keyboard macro. @@register has a different meaning when used after | |
1380 a @kbd{@@#}. @xref{Macros and Registers}, for details | |
1381 @item [] | |
1382 @kindex @kbd{[]} | |
1383 Go to end of heading. | |
1384 @item g <@emph{movement command}> | |
1385 Search buffer for text delimited by movement command. The canonical | |
1386 example is @kbd{gw} to search for the word under the cursor. | |
1387 @xref{Improved Search}, for details.@refill | |
1388 @item _ | |
1389 @kindex @kbd{_} | |
1390 Meta key when in Vi state.@xref{Vi State}, for an explanation. | |
1391 @item C-g and C-] | |
1392 @kindex @kbd{C-g} | |
1393 @kindex @kbd{C-]} | |
1394 Quit and Abort Recursive edit. These may be necessary on occasion. | |
1395 @xref{Vi State}, for a reason. | |
1396 @item C-c g | |
1397 @kindex @kbd{C-c g} | |
1398 Hitting @kbd{C-c} followed by @kbd{g} will display the information on the | |
1399 current buffer. This is the same as hitting @kbd{C-g} in Vi, but, as | |
1400 explained above, @kbd{C-g} is needed for other purposes in Emacs. | |
1401 @item C-c / | |
1402 @kindex @kbd{C-c /} | |
1403 Without a prefix argument, this command toggles | |
1404 case-sensitive/case-insensitive search modes and plain vanilla/regular | |
1405 expression search. With the prefix argument 1, i.e., | |
1406 @kbd{1 C-c /}, this toggles case-sensitivity; with the prefix argument 2, | |
1407 toggles plain vanilla search and search using | |
1408 regular expressions. @xref{Viper Specials}, for alternative ways to invoke | |
1409 this function. | |
1410 @cindex vanilla search | |
1411 @cindex case-sensitive search | |
1412 @cindex case-insensitive search | |
1413 | |
1414 @item M-p and M-n | |
1415 @kindex @kbd{M-p} | |
1416 @kindex @kbd{M-n} | |
1417 In the Minibuffer, these commands navigate through the minibuffer | |
1418 histories, such as the history of search strings, Ex commands, etc. | |
1419 | |
1420 @item C-c M-p and C-c M-n | |
1421 @kindex @kbd{C-c M-p} | |
1422 @kindex @kbd{C-c M-n} | |
1423 @cindex Insertion history | |
1424 @cindex Insertion ring | |
1425 @cindex Command history | |
1426 @cindex Command ring | |
1427 | |
1428 In Insert or Replace state, these commands let the user | |
1429 peruse the history of insertion strings used in previous insert or replace | |
1430 commands. Try to hit @kbd{C-c M-p} or @kbd{C-c M-n} repeatedly and see what | |
1431 happens. @xref{Viper Specials}, for more. | |
1432 | |
1433 In Vi state, these commands let the user peruse the history of Vi-style | |
1434 destructive commands, such as @kbd{dw}, @kbd{J}, @kbd{a}, etc. | |
1435 By repeatedly typing @kbd{C-c M-p} or @kbd{C-c M-n} you will cycle Viper | |
1436 through the recent history of Vi commands, displaying the commands one by | |
1437 one. Once | |
1438 an appropriate command is found, it can be executed by typing `@kbd{.}'. | |
1439 | |
1440 Since typing @kbd{C-c M-p} is tedious, it is more convenient to bind an | |
1441 appropriate function to a function key on the keyboard and use that key. | |
1442 @xref{Viper Specials}, for details. | |
1443 | |
1444 @item Ex commands | |
1445 @findex @kbd{:args} | |
1446 @findex @kbd{:n} | |
1447 @findex @kbd{:pwd} | |
1448 @findex @kbd{:pre} | |
1449 The commands @kbd{:args}, @kbd{:next}, @kbd{:pre} behave | |
1450 differently. @kbd{:pwd} exists to get current directory. | |
1451 The commands @kbd{:b} and @kbd{:B} switch buffers around. @xref{File and | |
1452 Buffer Handling}, for details. | |
1453 There are also the new commands @kbd{:RelatedFile} and | |
1454 @kbd{PreviousRelatedFile} (which abbreviate to @kbd{R} and @kbd{P}, | |
1455 respectively. @xref{Viper Specials}, for details. | |
1456 @findex @kbd{:RelatedFile} | |
1457 @findex @kbd{:PreviousRelatedFile} | |
1458 @end table | |
1459 | |
1460 Apart from the new commands, many old commands have been enhanced. Most | |
1461 notably, Vi style macros are much more powerful in Viper than in Vi. @xref{Vi | |
1462 Macros}, for details. | |
1463 | |
1464 @node Useful Packages, ,New Commands, Improvements over Vi | |
1465 @section Useful Packages | |
1466 | |
1467 Some Emacs packages are mentioned here as an aid to the new Viper user, to | |
1468 indicate what Viper is capable of. | |
1469 A vast number comes with the standard Emacs distribution, and many more exist | |
1470 on the net and on the archives. | |
1471 | |
1472 This manual also mentions some Emacs features a new user | |
1473 should know about. The details of these are found in the GNU Emacs | |
1474 Manual. | |
1475 | |
1476 The features first. For details, look up the Emacs Manual. | |
1477 | |
1478 @table @samp | |
1479 @item Make | |
1480 @cindex make | |
1481 @cindex compiling | |
1482 | |
1483 Makes and Compiles can be done from the editor. Error messages will be | |
1484 parsed and you can move to the error lines. | |
1485 @item Shell | |
1486 @cindex shell | |
1487 @cindex interactive shell | |
1488 You can talk to Shells from inside the editor. Your entire shell session | |
1489 can be treated as a file. | |
1490 @item Mail | |
1491 @cindex email | |
1492 @cindex mail | |
1493 Mail can be read from and sent within the editor. Several sophisticated | |
1494 packages exist. | |
1495 @item Language Sensitive Editing | |
1496 Editing modes are written for most computer languages in existence. By | |
1497 controlling indentation, they catch punctuation errors. | |
1498 @end table | |
1499 | |
1500 The packages, below, represents a drop in the sea of special-purpose | |
1501 packages that come with standard distribution of Emacs 19. | |
1502 | |
1503 @table @samp | |
1504 @item Transparent FTP | |
1505 @cindex transparent ftp | |
1506 @pindex ange-ftp.el | |
1507 @code{ange-ftp.el} can ftp from the editor to files on other machines | |
1508 transparent to the user. | |
1509 @item RCS Interfaces | |
1510 @cindex version maintenance | |
1511 @cindex RCS | |
1512 @pindex vc.el | |
1513 @code{vc.el} for doing RCS commands from inside the editor | |
1514 @item Directory Editor | |
1515 @cindex dired | |
1516 @pindex dired.el | |
1517 @code{dired.el} for editing contents of directories and for navigating in | |
1518 the file system. | |
1519 @item Syntactic Highlighting | |
1520 @cindex hilit19 | |
1521 @pindex hilit19.el | |
1522 @cindex font-lock | |
1523 @pindex font-lock.el | |
1524 @code{hilit19.el} and @code{font-lock.el} for automatic highlighting | |
1525 various parts of a buffer | |
1526 using different fonts and colors. | |
1527 @item Saving Emacs Configuration | |
1528 @cindex desktop | |
1529 @pindex desktop.el | |
1530 @code{desktop.el} for saving/restoring configuration on Emacs exit/startup. | |
1531 @item Spell Checker | |
1532 @cindex ispell | |
1533 @pindex ispell.el | |
1534 @code{ispell.el} for spell checking the buffer, words, regions, etc. | |
1535 @item File and Buffer Comparison | |
1536 @cindex ediff | |
1537 @pindex ediff.el | |
1538 @code{ediff.el} for finding differences between files and for applying | |
1539 patches. | |
1540 @end table | |
1541 | |
1542 @noindent | |
1543 Emacs Lisp archives exist on | |
1544 @samp{archive.cis.ohio-state.edu} | |
1545 and @samp{wuarchive.wustl.edu}@refill | |
1546 | |
1547 | |
1548 @node Customization,Commands,Improvements over Vi,Top | |
1549 @chapter Customization | |
1550 | |
1551 @cindex customization | |
1552 | |
1553 Customization can be done in 2 ways. | |
1554 | |
1555 @itemize @bullet | |
1556 @item | |
1557 @cindex initialization | |
1558 @cindex .vip | |
1559 Elisp code in a @file{.vip} file in your home directory. Viper | |
1560 loads @file{.vip} just before it does the binding for mode | |
1561 hooks. This is the recommended method. | |
1562 @item | |
1563 @cindex .emacs | |
1564 Elisp code in your @file{.emacs} file before and after the | |
1565 @code{(require 'viper)} line. This method is not recommended, unless you | |
1566 are know what you are doing.@refill | |
1567 @end itemize | |
1568 | |
1569 @noindent | |
1570 Emacs customization is done in Emacs Lisp. For the common cases, | |
1571 examples are provided that you can use directly. | |
1572 | |
1573 @menu | |
1574 * Rudimentary Changes:: Simple constant definitions. | |
1575 * Keybindings:: Enabling Emacs Keys, Rebinding keys, etc. | |
1576 * Packages that Change Keymaps:: How to deal with such beasts. | |
1577 * Viper Specials:: Special Viper commands. | |
1578 * Vi Macros:: How to do Vi style macros. | |
1579 @end menu | |
1580 | |
1581 @node Rudimentary Changes,Keybindings,Customization,Customization | |
1582 @section Rudimentary Changes | |
1583 | |
1584 @cindex setting variables | |
1585 @cindex variables for customization | |
1586 @findex @kbd{:set} | |
1587 | |
1588 An easy way to customize Viper is to change the values of constants used in | |
1589 Viper. Here is the list of the constants used in Viper and their default | |
1590 values. The corresponding :se command is also indicated. (The symbols | |
1591 @code{t} and @code{nil} represent ``true'' and ``false'' in Lisp). | |
1592 | |
1593 Viper supports both the abbreviated Vi variable names and their full | |
1594 names. Variable completion is done on full names only. @kbd{TAB} and | |
1595 @kbd{SPC} complete | |
1596 variable names. Typing `=' will complete the name and then will prompt for | |
1597 a value, if applicable. For instance, @kbd{:se auSPC} will complete the | |
1598 command to @kbd{:set autoindent}; @kbd{:se taSPC} will complete the command | |
1599 and prompt further like this: @kbd{:set tabstop = }. | |
1600 However, typing @kbd{:se tsSPC} will produce a ``No match'' message | |
1601 because @kbd{ts} is an abbreviation for @kbd{tabstop} and Viper supports | |
1602 completion on full names only. However, you can still hit @kbd{RET} | |
1603 or @kbd{=}, which will complete the command like this: @kbd{:set ts = } and | |
1604 Viper will be waiting for you to type a value for the tabstop variable. | |
1605 To get the full list of Vi variables, type @kbd{:se SPC TAB}. | |
1606 | |
1607 @table @code | |
1608 @item vip-auto-indent nil | |
1609 @itemx :se ai (:se autoindent) | |
1610 @itemx :se gai (:se global-autoindent) | |
1611 If @code{t}, enable auto indentation. | |
1612 by @kbd{RET}, @kbd{o} or @kbd{O} command. | |
1613 | |
1614 @code{vip-auto-indent} is a local variable. To change the value globally, use | |
1615 @code{setq-default}. It may be useful for certain major modes to have their | |
1616 own values of @code{vip-auto-indent}. This can be achieved by using | |
1617 @code{setq} to change the local value of this variable in the hooks to the | |
1618 appropriate major modes. | |
1619 | |
1620 @kbd{:se ai} changes the value of @code{vip-auto-indent} in the current | |
1621 buffer only; @kbd{:se gai} does the same globally. | |
1622 @item vip-electric-mode t | |
1623 If @code{t}, auto-indentation becomes electric, which means that @kbd{RET}, | |
1624 @kbd{O}, and @kbd{o} indent cursor according to the current major mode. In | |
1625 the future, this variable may control additional electric features. | |
1626 | |
1627 This is a local variable: @code{setq} changes the value of this variable | |
1628 in the current buffer only. Use @code{setq-default} to change the value in | |
1629 all buffers. | |
1630 @item vip-case-fold-search nil | |
1631 @itemx :se ic (:se ignorecase) | |
1632 If @code{t}, search ignores cases. | |
1633 This can also be toggled by quickly hitting @kbd{/} twice. | |
1634 @item vip-re-search nil | |
1635 @itemx :se magic | |
1636 If @code{t} then search is reg-exp search, if @code{nil} then vanilla | |
1637 search. | |
1638 This behavior can also be toggled by quickly hitting @kbd{/} trice. | |
1639 @item buffer-read-only | |
1640 @itemx :se ro (:se readonly) | |
1641 Set current buffer to read only. To change globally put | |
1642 @code{(setq-default buffer-read-only t)} in your @file{.emacs} file. | |
1643 @item blink-matching-paren t | |
1644 @itemx :se sm (:se showmatch) | |
1645 Show matching parens by blinking cursor. | |
1646 @item tab-width t (default setting via @code{setq-default}) | |
1647 @itemx :se ts=value (:se tabstop=value) | |
1648 @itemx :se gts=value (:se global-tabstop=value) | |
1649 @code{tab-width} is a local variable that controls the width of the tab stops. | |
1650 To change the value globally, use @code{setq-default}; for local settings, | |
1651 use @code{setq}. | |
1652 | |
1653 The command @kbd{:se ts} | |
1654 sets the tab width in the current | |
1655 buffer only; it has no effect on other buffers. | |
1656 | |
1657 The command @kbd{:se gts} sets tab width globally, | |
1658 for all buffers where the tab is not yet set locally, | |
1659 including the new buffers. | |
1660 | |
1661 Note that typing @kbd{TAB} normally | |
1662 doesn't insert the tab, since this key is usually bound to | |
1663 a text-formatting function, @code{indent-for-tab-command} (which facilitates | |
1664 programming and document writing). Instead, the tab is inserted via the | |
1665 command @code{vip-insert-tab}, which is bound to @kbd{S-tab} (shift + tab). | |
1666 | |
1667 On some non-windowing terminals, Shift doesn't modify the @kbd{TAB} key, so | |
1668 @kbd{S-tab} behaves as if it were @kbd{TAB}. In such a case, you will have | |
1669 to bind @code{vip-insert-tab} to some other convenient key. | |
1670 | |
1671 @item vip-shift-width 8 | |
1672 @itemx :se sw=value (:se shiftwidth=value) | |
1673 The number of columns shifted by @kbd{>} and @kbd{<} commands. | |
1674 @item vip-search-wrap-around t | |
1675 @itemx :se ws (:se wrapscan) | |
1676 If @code{t}, search wraps around the end/beginning of buffer. | |
1677 @item vip-tags-file-name "TAGS" | |
1678 The name of the file used as the tag table. | |
1679 @item vip-re-query-replace nil | |
1680 If @code{t}, use reg-exp replace in query replace. | |
1681 @item vip-want-ctl-h-help nil | |
1682 If @code{t}, @kbd{C-h} is bound to @code{help-command}; | |
1683 if @code{nil}, it is bound to @code{delete-backward-char}. | |
1684 @item vip-vi-style-in-minibuffer t | |
1685 If @code{t}, Viper provides a high degree of compatibility with Vi insert mode | |
1686 when you type text in the Minibuffer; if @code{nil}, typing in the | |
1687 Minibuffer feels like plain Emacs. | |
1688 @item vip-no-multiple-ESC t | |
1689 If you set this to @code{nil}, you can use @kbd{ESC} as Meta in Vi state. | |
1690 Normally, this is not necessary, since graphical displays have separate | |
1691 Meta keys (usually on each side of the space bar). On a dumb terminal, Viper | |
1692 sets this variable to @code{twice}, which is almost like @code{nil}, except | |
1693 that double @kbd{ESC} beeps. This, too, lets ESC to be used as a Meta. | |
1694 @item vip-keysequence-delay 140 | |
1695 Escape sequences separated by this much delay are interpreted as command, | |
1696 ignoring the special meaning of ESC in VI. The default is suitable for most | |
1697 terminals. However, if your terminal is extremely slow, you | |
1698 might want to increase this slightly. You will know if your terminal is | |
1699 slow if the ESC key sequences emitted by the arrow keys are interpreted as | |
1700 separately typed characters (and thus the arrow keys won't work). | |
1701 Making this value too large will slow you down, so exercise restraint. | |
1702 @item vip-ex-style-motion t | |
1703 Set this to @code{nil}, if you want @kbd{l,h} to cross | |
1704 lines, etc. @xref{Movement and Markers}, for more info. | |
1705 @item vip-ex-style-editing-in-insert t | |
1706 Set this to to @code{nil}, if you want @kbd{ESC} to not move back and | |
1707 @kbd{C-h} to not stop | |
1708 at the beginning of a line in Insert state. | |
1709 @item vip-always t | |
1710 Leave it to Viper to decide when a buffer must be brought up in Vi state, | |
1711 Insert state, or Emacs state. This heuristics works well in virtually all | |
1712 cases. | |
1713 This option must be | |
1714 set before Viper is loaded or in the @file{.vip} file. | |
1715 @item vip-custom-file-name "~/.vip" | |
1716 Change this if you want. Must be set in @file{.emacs} (not @file{.vip}!) | |
1717 before Viper is loaded. Note that you | |
1718 have to set it as a string inside double quotes. | |
1719 @item vip-spell-function 'ispell-region | |
1720 Function used by the command @kbd{#c<move>} to spell. | |
1721 @item ex-nontrivial-find-file-function | |
1722 The value of this variable is the function used to find all files that | |
1723 match a wildcard. This is usually done when the user types @kbd{:e} and | |
1724 specifies a wildcard in the file name (or if the file name contains unusual | |
1725 symbols (e.g., a space). Viper provides two functions for this: one for | |
1726 Unix-like systems (@code{vip-ex-nontrivial-find-file-unix}) and one for | |
1727 DOS, W95, and NT (@code{vip-ex-nontrivial-find-file-ms}). If the default | |
1728 function doesn't quite do what you expect or if you prefer to use ``fancy'' | |
1729 shells, you may have to write your own version of this function and make it | |
1730 into the value of @code{ex-nontrivial-find-file-function}. Use | |
1731 @code{vip-ex-nontrivial-find-file-unix} and | |
1732 @code{vip-ex-nontrivial-find-file-ms} as examples. | |
1733 @vindex @code{ex-nontrivial-find-file-function}. | |
1734 @findex @code{vip-ex-nontrivial-find-file-ms} | |
1735 @findex @code{vip-ex-nontrivial-find-file-unix} | |
1736 @item ex-cycle-other-window t | |
1737 If @code{t}, @kbd{:n} and @kbd{:b} will cycle through files in another | |
1738 window, if one exists. | |
1739 @item ex-cycle-through-non-files nil | |
1740 @kbd{:n} does not normally cycle through buffers. Set this to get | |
1741 buffers also. | |
1742 @item vip-automatic-iso-accents nil | |
1743 If @kbd{t}, ISO accents will be turned on in insert/replace Viper states | |
1744 and turned off in Vi state. This is useful for editing text in European | |
1745 languages. This variable is buffer-local. If used, it should be set in the | |
1746 hooks to the appropriate major modes (usually setting it in | |
1747 @code{text-mode-hook} is enough). | |
1748 @item vip-want-emacs-keys-in-insert | |
1749 This is set to @code{nil} for user levels 1 and 2 and to @code{t} for user | |
1750 levels 3 and 4. Users who specify level 5 are allowed to set this variable | |
1751 as they please (the default for this level is @code{t}). If set to | |
1752 @code{nil}, complete Vi compatibility is provided in Insert state. This is | |
1753 really not recommended, as this precludes you from using language-specific | |
1754 features provided by the major modes. | |
1755 @item vip-want-emacs-keys-in-vi | |
1756 This is set to @code{nil} for user | |
1757 level 1 and to @code{t} for user levels 2--4. | |
1758 At level 5, users are allowed to set this variable as they please (the | |
1759 default for this level is @code{t}). | |
1760 If set to @code{nil}, complete Vi compatibility is provided | |
1761 in Vi command state. Setting this to @code{nil} is really a bad idea, | |
1762 unless you are a novice, as this precludes the use | |
1763 of language-specific features provided by the major modes. | |
1764 @item vip-keep-point-on-repeat t | |
1765 If @code{t}, point is not moved when the user repeats the previous command | |
1766 by typing `.' This is very useful for doing repeated changes with the | |
1767 @kbd{.} key. | |
1768 @item vip-repeat-from-history-key 'f12 | |
1769 Prefix key used to invoke the macros @kbd{f12 1} and @kbd{f12 2} that repeat | |
1770 the second-last and the third-last destructive command. | |
1771 Both these macros are bound (as Viper macros) to | |
1772 @code{vip-repeat-from-history}, | |
1773 which checks the second key by which it is invoked to see which of the | |
1774 previous commands to invoke. Viper binds @kbd{f12 1} and @kbd{f12 2} only, | |
1775 but the user can bind more in @file{~/.vip}. @xref{Vi Macros}, for how to do | |
1776 this. | |
1777 @item vip-keep-point-on-undo nil | |
1778 If @code{t}, Viper tries to not move point when undoing commands. | |
1779 Instead, it will briefly move the cursor to the place where change has | |
1780 taken place. However, if the undone piece of text is not seen in window, | |
1781 then point will be moved to the place where the change took place. | |
1782 Set it to @code{t} and see if you like it better. | |
1783 @item vip-delete-backwards-in-replace nil | |
1784 If @code{t}, DEL key will delete characters while moving the cursor backwards. | |
1785 If @code{nil}, the cursor will move backwards without deleting anything. | |
1786 @item vip-replace-overlay-face 'vip-replace-overlay-face | |
1787 On a graphical display, Viper highlights replacement regions instead of | |
1788 putting a @samp{$} at the end. This variable controls the so called | |
1789 @dfn{face} used to highlight the region. | |
1790 | |
1791 By default, @code{vip-replace-overlay-face} underlines the replacement | |
1792 on monochrome displays and highlights it with color on color displays. | |
1793 If you know something about Emacs | |
1794 faces and don't like how Viper highlights replacement regions, you can change | |
1795 this variable to specify a new face name. (Emacs faces are described in the | |
1796 Emacs Lisp reference.) | |
1797 On a color display, the following customization method is usually | |
1798 most effective: | |
1799 @example | |
1800 (set-face-foreground vip-replace-overlay-face "DarkSlateBlue") | |
1801 (set-face-background vip-replace-overlay-face "yellow") | |
1802 @end example | |
1803 For a complete list of colors available to you, evaluate the | |
1804 expression @code{(x-defined-colors)}. (Type it in the buffer @code{*scratch*} | |
1805 and then hit the @kbd{C-j} key. | |
1806 @item vip-replace-overlay-cursor-color "Red" | |
1807 Cursor color when it is inside the replacement region. | |
1808 This has effect only on color displays and only when Emacs runs as an X | |
1809 application. | |
1810 @item vip-replace-region-end-delimiter "$" | |
1811 A string used to mark the end of replacement regions. It is used only with | |
1812 TTYs or if @code{vip-use-replace-region-delimiters} is non-nil. | |
1813 @item vip-replace-region-start-delimiter "" | |
1814 A string used to mark the beginning of replacement regions. It is used | |
1815 only with TTYs or if @code{vip-use-replace-region-delimiters} is non-nil. | |
1816 @item vip-use-replace-region-delimiters | |
1817 If non-nil, Viper will always use @code{vip-replace-region-end-delimiter} and | |
1818 @code{vip-replace-region-start-delimiter} to delimit replacement regions, | |
1819 even on color displays (where this is unnecessary). By default, this | |
1820 variable is non-nil only on TTYs or monochrome displays. | |
1821 @item vip-toggle-key "\C-z" | |
1822 Specifies the key used to switch from Emacs to Vi and back. | |
1823 Must be set in @file{.vip} or prior to loading Viper. This variable can't be | |
1824 changed interactively after Viper is loaded. | |
1825 @item vip-ESC-key "\e" | |
1826 Specifies the key used to escape from Insert/Replace states to Vi. | |
1827 Must be set in @file{.vip} or prior to loading Viper. This variable cannot be | |
1828 changed interactively after Viper is loaded. | |
1829 @item vip-buffer-search-char nil | |
1830 Key used for buffer search. @xref{Viper Specials}, for details. | |
1831 @item vip-surrounding-word-function 'vip-surrounding-word | |
1832 The value of this variable is a function name that is used to determine | |
1833 what constitutes a word clicked upon by the mouse. This is used by mouse | |
1834 search and insert. | |
1835 @item vip-search-face 'vip-search-face | |
1836 Variable that controls how search patterns are highlighted when they are | |
1837 found. | |
1838 @item vip-vi-state-hook nil | |
1839 List of parameterless functions to be run just after entering the Vi | |
1840 command state. | |
1841 @item vip-insert-state-hook nil | |
1842 Same for Insert state. This hook is also run after entering Replace state. | |
1843 @item vip-replace-state-hook nil | |
1844 List of (parameterless) functions called just after entering Replace state | |
1845 (and after all @code{vip-insert-state-hook}). | |
1846 @item vip-emacs-state-hook nil | |
1847 List of (parameterless) functions called just after switching from Vi state | |
1848 to Emacs state. | |
1849 @item vip-load-hook nil | |
1850 List of (parameterless) functions called just after loading Viper. This is | |
1851 the last chance to do customization before Viper is up and running. | |
1852 @end table | |
1853 @noindent | |
1854 You can reset some of these constants in Viper with the Ex command @kbd{:set} | |
1855 (when so indicated in the table). Or you | |
1856 can include a line like this in your @file{.vip} file: | |
1857 @example | |
1858 (setq vip-case-fold-search t) | |
1859 @end example | |
1860 @vindex @code{vip-auto-indent} | |
1861 @vindex @code{vip-electric-mode} | |
1862 @vindex @code{vip-case-fold-search} | |
1863 @vindex @code{vip-re-search} | |
1864 @vindex @code{vip-shift-width} | |
1865 @vindex @code{buffer-read-only} | |
1866 @vindex @code{vip-search-wrap-around} | |
1867 @vindex @code{vip-search-face} | |
1868 @vindex @code{vip-tags-file-name} | |
1869 @vindex @code{vip-re-query-replace} | |
1870 @vindex @code{vip-want-ctl-h-help} | |
1871 @vindex @code{vip-vi-style-in-minibuffer} | |
1872 @vindex @code{vip-no-multiple-ESC} | |
1873 @vindex @code{vip-always} | |
1874 @vindex @code{vip-keysequence-delay} | |
1875 @vindex @code{vip-ex-style-motion} | |
1876 @vindex @code{vip-ex-style-editing-in-insert} | |
1877 @vindex @code{vip-custom-file-name} | |
1878 @vindex @code{vip-spell-function} | |
1879 @vindex @code{ex-cycle-other-window} | |
1880 @vindex @code{ex-cycle-through-non-files} | |
1881 @vindex @code{vip-automatic-iso-accents} | |
1882 @vindex @code{vip-want-emacs-keys-in-insert} | |
1883 @vindex @code{vip-want-emacs-keys-in-vi} | |
1884 @vindex @code{vip-keep-point-on-repeat} | |
1885 @vindex @code{vip-keep-point-on-undo} | |
1886 @vindex @code{vip-delete-backwards-in-replace} | |
1887 @vindex @code{vip-replace-overlay-face} | |
1888 @vindex @code{vip-replace-region-end-symbol} | |
1889 @vindex @code{vip-replace-region-start-symbol} | |
1890 @vindex @code{vip-toggle-key} | |
1891 @vindex @code{vip-ESC-key} | |
1892 @vindex @code{vip-buffer-search-char} | |
1893 @vindex @code{vip-surrounding-word-function} | |
1894 @vindex @code{vip-vi-state-hook} | |
1895 @vindex @code{vip-insert-state-hook} | |
1896 @vindex @code{vip-replace-state-hook} | |
1897 @vindex @code{vip-emacs-state-hook} | |
1898 | |
1899 @node Keybindings, Packages that Change Keymaps, Rudimentary Changes,Customization | |
1900 @section Keybindings | |
1901 | |
1902 @cindex keybindings | |
1903 @cindex keymaps | |
1904 | |
1905 Viper lets you define hot keys, i.e., you can associate keyboard keys | |
1906 such as F1, Help, PgDn, etc., with Emacs Lisp functions (that may already | |
1907 exist or that you will write). Each key has a "preferred form" in | |
1908 Emacs. For instance, the Up key's preferred form is [up], the Help key's | |
1909 preferred form is [help], and the Undo key has the preferred form [f14]. | |
1910 You can find out the preferred form of a key by typing @kbd{M-x | |
1911 describe-key-briefly} and then typing the key you want to know about. | |
1912 | |
1913 Under X Windows, every keyboard key emits its preferred form, so you can | |
1914 just type | |
1915 | |
1916 @lisp | |
1917 (global-set-key [f11] 'calendar) ; L1, Stop | |
1918 (global-set-key [f14] 'undo) ; L4, Undo | |
1919 @end lisp | |
1920 | |
1921 @noindent | |
1922 to bind L1 so it will invoke the Emacs Calendar and to bind L4 so it will | |
1923 undo changes. | |
1924 However, on a dumb terminal or in an Xterm window, even the standard arrow | |
1925 keys may | |
1926 not emit the right signals for Emacs to understand. To let Emacs know about | |
1927 those keys, you will have to find out which key sequences they emit | |
1928 by typing @kbd{C-q} and then the key (you should switch to Emacs state | |
1929 first). Then you can bind those sequences to their preferred forms using | |
1930 @code{function-key-map} as follows: | |
1931 | |
1932 @lisp | |
1933 (cond ((string= (getenv "TERM") "xterm") | |
1934 (define-key function-key-map "\e[192z" [f11]) ; L1 | |
1935 (define-key function-key-map "\e[195z" [f14]) ; L4, Undo | |
1936 @end lisp | |
1937 | |
1938 The above illustrates how to do this for Xterm. On VT100, you would have to | |
1939 replace "xterm" with "vt100" and also change the key sequences (the same | |
1940 key may emit different sequences on different types of terminals). | |
1941 | |
1942 The above keys are global, so they are overwritten by the local maps | |
1943 defined by the major modes and by Viper itself. Therefore, if you wish to | |
1944 change a binding set by a major mode or by Viper, read this. | |
1945 | |
1946 Viper users who wish to specify their own key bindings should be concerned | |
1947 only with the following three keymaps: | |
1948 @code{vip-vi-global-user-map} for Vi state commands, | |
1949 @code{vip-insert-global-user-map} for Insert state commands, | |
1950 and @code{vip-emacs-global-user-map} for Emacs state commands (note: | |
1951 customized bindings for Emacs state made to @code{vip-emacs-global-user-map} | |
1952 are @emph{not} inherited by Insert state). | |
1953 | |
1954 For more information on Viper keymaps, see the header of the file | |
1955 @file{viper.el}. | |
1956 If you wish to change a Viper binding, you can use the | |
1957 @code{define-key} command, to modify @code{vip-vi-global-user-map}, | |
1958 @code{vip-insert-global-user-map}, and @code{vip-emacs-global-user-map}, as | |
1959 explained below. Each of these key maps affects the corresponding Viper state. | |
1960 The keymap @code{vip-vi-global-user-map} also affects Viper's Replace state. | |
1961 | |
1962 @noindent | |
1963 If you want to | |
1964 bind a key, say @kbd{C-v}, to the function that scrolls | |
1965 page down and to make @kbd{0} display information on the current buffer, | |
1966 putting this in @file{.vip} will do the trick in Vi state: | |
1967 @example | |
1968 (define-key vip-vi-global-user-map "\C-v" 'scroll-down) | |
1969 @end example | |
1970 @noindent | |
1971 To set a key globally, | |
1972 @example | |
1973 (define-key vip-emacs-global-user-map "\C-c m" 'smail) | |
1974 (define-key vip-vi-global-user-map "0" 'vip-info-on-file) | |
1975 @end example | |
1976 @noindent | |
1977 Note, however, that this binding may be overwritten by other keymaps, since | |
1978 the global keymap has the lowest priority. | |
1979 To make sure that nothing will override a binding in Emacs state, you | |
1980 can write this: | |
1981 @example | |
1982 (define-key vip-emacs-global-user-map "\C-c m" 'smail) | |
1983 @end example | |
1984 @noindent | |
1985 To customize the binding for @kbd{C-h} in Insert state: | |
1986 @example | |
1987 (define-key vip-insert-global-user-map "\C-h" 'my-del-backwards-function) | |
1988 @end example | |
1989 @noindent | |
1990 | |
1991 Each Emacs command key calls some lisp function. If you have enabled the | |
1992 Help, (@xref{Rudimentary Changes}) @kbd{C-h k} will show you the function | |
1993 for each specific key; @kbd{C-h b} will show all bindings, and @kbd{C-h m} | |
1994 will provide information on the major mode in effect. If Help is not | |
1995 enabled, you can still get help in Vi state by prefixing the above commands | |
1996 with @kbd{\}, e.g., @kbd{\ C-h k} (or you can use the Help menu in the | |
1997 menu bar, if Emacs runs under X Windows). | |
1998 | |
1999 Viper users can also change bindings on a per major mode basis. As with | |
2000 global bindings, this can be done separately for each of the three main Viper | |
2001 states. To this end, Viper provides the function | |
2002 @code{vip-modify-major-mode}. | |
2003 @findex @code{vip-modify-major-mode} | |
2004 | |
2005 To modify keys in Emacs state for @code{my-favorite-major-mode}, the user | |
2006 needs to create a sparse keymap, say, @code{my-fancy-map}, bind whatever | |
2007 keys necessary in that keymap, and put | |
2008 | |
2009 @example | |
2010 (vip-modify-major-mode 'dired-mode 'emacs-state my-fancy-map) | |
2011 @end example | |
2012 | |
2013 @noindent | |
2014 in @file{~/.vip}. To do the same in Vi and Insert states, one should use | |
2015 @code{vi-state} and @code{insert-state}. Changes in Insert state are also | |
2016 in effect in Replace state. For instance, suppose that the user wants to | |
2017 use @kbd{dd} in Vi state under Dired mode to delete files, @kbd{u} to unmark | |
2018 files, etc. The following code in @file{~/.vip} will then do the job: | |
2019 | |
2020 @example | |
2021 (setq my-dired-modifier-map (make-sparse-keymap)) | |
2022 (define-key my-dired-modifier-map "dd" 'dired-flag-file-deletion) | |
2023 (define-key my-dired-modifier-map "u" 'dired-unmark) | |
2024 (vip-modify-major-mode 'dired-mode 'vi-state my-dired-modifier-map) | |
2025 @end example | |
2026 | |
2027 A Vi purist may want to modify Emacs state under Dired mode so that | |
2028 @kbd{k}, @kbd{l}, etc., will move around in directory buffers, as in | |
2029 Vi. Although this is not recommended, as these keys are bound to useful | |
2030 Dired functions, the trick can be accomplished via the following code: | |
2031 | |
2032 @example | |
2033 (setq my-dired-vi-purist-map (make-sparse-keymap)) | |
2034 (define-key my-dired-vi-purist-map "k" 'vip-previous-line) | |
2035 (define-key my-dired-vi-purist-map "l" 'vip-forward-char) | |
2036 (vip-modify-major-mode 'dired-mode 'emacs-state my-dired-vi-purist-map) | |
2037 @end example | |
2038 | |
2039 Similar effect can be achieved by defining Vi keyboard macros using the | |
2040 Ex commands @kbd{:map} and @kbd{:map!}. The difference is that multi-key | |
2041 Vi macros do not override the keys they are bound to, unless these keys are | |
2042 typed in quick succession. So, with macros, one can use the normal keys | |
2043 alongside with the macros. If per-mode modifications are needed, the user | |
2044 can try both ways and see which one is more convenient. | |
2045 @findex @kbd{:map} | |
2046 @xref{Vi Macros}, for details. | |
2047 | |
2048 Note: in major modes that come up in @emph{Emacs state} by default, the | |
2049 aforesaid modifications may not take place immediately (but only after the | |
2050 buffer switches to some other Viper state and then back to Emacs state). To | |
2051 avoid this, one should add @code{vip-change-state-to-emacs} to an | |
2052 appropriate hook of that major mode. (Check the function | |
2053 @code{vip-set-hooks} in @file{viper.el} for examples.) However, if you | |
2054 have set @code{vip-always} to @code{t}, chances are that you won't need to | |
2055 perform the above procedure, because Viper will take care of most useful | |
2056 defaults. | |
2057 | |
2058 | |
2059 Finally, Viper has a facility that lets the user define per-buffer | |
2060 bindings, i.e., bindings that are in effect in some specific buffers | |
2061 only. Unlike per-mode bindings described above, per-buffer bindings can be | |
2062 defined based on considerations other than the major mode. This is done | |
2063 via the function @code{vip-add-local-keys}, which lets one specify bindings | |
2064 that should be in effect in the current buffer only and for a specific Viper | |
2065 state. For instance, | |
2066 @lisp | |
2067 (vip-add-local-keys 'vi-state '(("ZZ" . TeX-command-master) | |
2068 ("ZQ" . vip-save-kill-buffer))) | |
2069 @end lisp | |
2070 @noindent | |
2071 redefines @kbd{ZZ} to invoke @code{TeX-command-master} in @code{vi-state} | |
2072 and @kbd{ZQ} to save-then-kill the current buffer. These bindings take | |
2073 effect only in the buffer where this command is executed. The typical use | |
2074 of this function is to execute the above expression from within a function | |
2075 that is included in a hook to some major mode. For instance, the above | |
2076 expression | |
2077 could be called from a function, @code{my-tex-init}, which may be added to | |
2078 @code{tex-mode-hook} as follows: | |
2079 @lisp | |
2080 (add-hook 'tex-mode-hook 'my-tex-init) | |
2081 @end lisp | |
2082 @noindent | |
2083 When TeX mode starts, the hook is executed and the above Lisp expression is | |
2084 evaluated. Then, the bindings for @kbd{ZZ} and @kbd{ZQ} are changed in Vi | |
2085 command mode for all buffers in TeX mode. | |
2086 | |
2087 Another useful application is to bind @kbd{ZZ} to @code{send-mail} | |
2088 in the Mail mode buffers (the specifics of this depend on which mail | |
2089 package you are using, @code{rmail}, @code{mh-e}, @code{vm}, etc. | |
2090 For instance, here is how to do this for @code{mh-e}, the Emacs interface | |
2091 to MH: | |
2092 @lisp | |
2093 (defun mh-add-vi-keys () | |
2094 "Set up ZZ for MH-e and XMH." | |
2095 (vip-add-local-keys 'vi-state '(("ZZ" . mh-send-letter)))) | |
2096 (add-hook 'mh-letter-mode-hook 'mh-add-vi-keys) | |
2097 @end lisp | |
2098 | |
2099 You can also use @code{vip-add-local-keys} to set per buffer | |
2100 bindings in Insert state and Emacs state by passing as a parameter the | |
2101 symbols @code{'insert-state} and @code{'emacs-state}, respectively. | |
2102 As with global bindings, customized local bindings done to Emacs state | |
2103 are not inherited by Insert state. | |
2104 | |
2105 On rare occasions, local keys may be added by mistake. Usually this is done | |
2106 indirectly, by invoking a major mode that adds local keys (e.g., | |
2107 @code{shell-mode} redefines @kbd{RET}). In such a case, exiting the wrong | |
2108 major mode won't rid you from unwanted local keys, since these keys are | |
2109 local to Viper state and the current buffer, not to the major mode. | |
2110 In such situations, the remedy is to type @kbd{M-x vip-zap-local-keys}. | |
2111 | |
2112 So much about Viper-specific bindings. | |
2113 @xref{Customization,,Customization,emacs,The GNU Emacs | |
2114 Manual}, and the Emacs quick reference card for the general info on key | |
2115 bindings in Emacs. | |
2116 | |
2117 @vindex @code{function-key-map} | |
2118 @vindex @code{vip-vi-global-user-map} | |
2119 @vindex @code{vip-insert-global-user-map} | |
2120 @vindex @code{vip-emacs-global-user-map} | |
2121 @findex @code{vip-add-local-keys} | |
2122 @findex @code{vip-zap-local-keys} | |
2123 | |
2124 @node Packages that Change Keymaps,Viper Specials,Keybindings,Customization | |
2125 @subsection Packages that Change Keymaps | |
2126 @cindex C-c and Viper | |
2127 @cindex Viper and C-c | |
2128 | |
2129 Viper is designed to coexist with all major and minor modes of Emacs. This | |
2130 means that bindings set by those modes are generally available with Viper | |
2131 (unless you explicitly prohibit them by setting | |
2132 @code{vip-want-emacs-keys-in-vi} and @code{vip-want-emacs-keys-in-insert} to | |
2133 @code{nil}). | |
2134 If @code{vip-always} is set to @code{t}, Viper will try to bring each buffer | |
2135 in the a Viper state that is most appropriate for that buffer. | |
2136 Usually, this would be the Vi state, but sometimes it could be the Insert | |
2137 state or the Emacs state. | |
2138 | |
2139 Some major mode bindings will necessarily be overwritten by Viper. Indeed, in | |
2140 Vi state, most of the 1-character keys are used for Vi-style editing. This | |
2141 usually causes no problems because most packages designed for editing files | |
2142 typically do not bind such keys. Instead, they use key sequences that start | |
2143 with @kbd{C-x} and @kbd{C-c}. This is why it was so important for us to | |
2144 free up @kbd{C-x} and @kbd{C-c}. | |
2145 It is common for language-specific major modes to bind @kbd{TAB} and | |
2146 @kbd{LFD} (the line feed) keys to various formatting functions. This is | |
2147 extremely useful, but may require some getting used to for a Vi user. If you | |
2148 decide that this feature is not for you, you can re-bind these keys as | |
2149 explained earlier (@xref{Customization}). | |
2150 | |
2151 Binding for @kbd{TAB} is one of the most unusual aspects of Viper for many | |
2152 novice users. In Emacs, @kbd{TAB} is used to format text and programs, and | |
2153 is extremely useful. For instance, hitting @kbd{TAB} causes the current | |
2154 line to be re-indented in accordance with the context. In programming, | |
2155 this is very important, since improper automatic indentation would | |
2156 immediately alert the programmer to a possible error. For instance, if a | |
2157 @kbd{)} or a @kbd{"} is missing somewhere above the current | |
2158 line, @kbd{TAB} is likely to mis-indent the line. | |
2159 | |
2160 For this reason, Viper doesn't change the standard Emacs binding of | |
2161 @kbd{TAB}, thereby sacrificing Vi compatibility | |
2162 (except for users at level 1). Instead, in Viper, the key | |
2163 @kbd{S-tab} (shift+ tab) is chosen to emulate Vi's @kbd{TAB}. | |
2164 | |
2165 We should note that on some non-windowing terminals, Shift doesn't modify | |
2166 the @kbd{TAB} key, so @kbd{S-tab} behaves as if it were @kbd{TAB}. In such | |
2167 a case, you will have to bind @code{vip-insert-tab} to some other | |
2168 convenient key. | |
2169 | |
2170 Some packages, notably Dired, Gnus, Info, etc., attach special meaning | |
2171 to common keys like @kbd{SPC}, @kbd{x}, @kbd{d}, @kbd{v}, and others. This | |
2172 means that Vi command state is inappropriate for working with these | |
2173 packages. Fortunately, these modes operate on read-only buffers and are | |
2174 designed not for editing files, but for special-purpose browsing, reading | |
2175 news, mail, etc., and Vi commands are meaningless in these situations. For | |
2176 this reason, Viper doesn't force Vi state on such major modes. Rather, it | |
2177 brings them in Emacs state. You can switch to Vi state by typing @kbd{C-z} | |
2178 if, for instance, you want to do Vi-style search in a buffer (although, | |
2179 usually, incremental search, which is bound to @kbd{C-s}, is sufficient in | |
2180 these situations). But you should then switch back to Emacs state if you | |
2181 plan to continue using these major modes productively. You can also switch | |
2182 to Vi temporarily, to execute one 1-character command. This is done by | |
2183 typing @kbd{M-C-z} (or @kbd{ESC C-z}). | |
2184 This facility cannot execute several complex Vi commands, such as @kbd{dw}, | |
2185 @kbd{de}, etc. | |
2186 | |
2187 It is also possible to harness some major modes, even though they may bind | |
2188 common keys to specialized commands. Harnessing can make sense for modes | |
2189 that bind only a small number of common keys. For instance, if | |
2190 @code{vip-always} is set to @code{t} in your @file{~/.vip} file, Viper will | |
2191 harness the Shell mode by changing the bindings for @kbd{C-m} and @kbd{C-d} | |
2192 using @code{vip-add-local-keys} described in section on customization | |
2193 (@xref{Customization}). In general, there is no single recipe for | |
2194 harnessing modes. It can be as simple as adding the function | |
2195 @code{viper-mode} to a hook associated with the mode, or it can be more | |
2196 complex, as in the case of Shell mode and Emerge. Take a look at | |
2197 @code{vip-set-hooks} function for some examples. | |
2198 | |
2199 Conversely, it may be the case that most of the major modes harnessed | |
2200 by @code{vip-set-hooks} function fit your working style, except one or two | |
2201 cases. In this case, you may still be able to set @code{vip-always} to | |
2202 @code{t} and then remove a hook that forces Vi command state. For instance, | |
2203 to unharness @code{lisp-interaction-mode}, you can put the following line | |
2204 in your @file{.emacs} (not @code{.vip}!) file after @code{(require 'viper)}: | |
2205 @lisp | |
2206 (remove-hook 'lisp-interaction-mode-hook 'viper-mode) | |
2207 @end lisp | |
2208 | |
2209 In some rare cases, some minor modes may override certain essential | |
2210 bindings in Vi command state. This is not really catastrophic because this | |
2211 may happen only in the beginning, when the minor mode kicks in. Typing | |
2212 @code{M-x viper-mode} will correct the situation. Viper knows about | |
2213 several such minor modes and takes care of them, so that the above trick | |
2214 is usually not necessary. If you find that some minor mode, e.g., | |
2215 @code{nasty-mode.el} interferes with Viper, putting the following in | |
2216 @file{.vip} should fix the problem: | |
2217 @lisp | |
2218 (vip-harness-minor-mode "nasty-mode") | |
2219 @end lisp | |
2220 @noindent | |
2221 The argument to @code{vip-harness-minor-mode} is the name of the file for the | |
2222 offending minor mode with the suffixes @file{.el} and @file{.elc} removed. | |
2223 | |
2224 It may be tricky, however, to find out which minor mode is at fault. The | |
2225 only guidance here is to look into the file that defines the minor mode you | |
2226 are suspecting, say @code{nasty-mode.el}, and see if it has a variable | |
2227 called @code{nasty-mode-map}. Then check if there is a statement of the form | |
2228 @lisp | |
2229 (define-key nasty-mode-map key function) | |
2230 @end lisp | |
2231 @noindent | |
2232 that binds the misbehaving | |
2233 keys. If so, use the above line to harness @code{nasty-mode}. If your | |
2234 suspicion is wrong, no harm is done if you harness a minor mode that | |
2235 doesn't need to be harnessed. | |
2236 | |
2237 @vindex @code{vip-want-emacs-keys-in-vi} | |
2238 @vindex @code{vip-want-emacs-keys-in-insert} | |
2239 @vindex @code{vip-always} | |
2240 @findex @code{vip-set-hooks} | |
2241 @findex @code{viper-mode} | |
2242 @findex @code{vip-harness-minor-mode} | |
2243 @findex @code{remove-hook} | |
2244 @findex @code{add-hook} | |
2245 | |
2246 @node Viper Specials,Vi Macros,Packages that Change Keymaps,Customization | |
2247 @section Viper Specials | |
2248 | |
2249 Viper extends Vi with a number of useful features. This includes various | |
2250 search functions, histories of search strings, Ex commands, insertions, and | |
2251 Vi's destructive commands. In addition, Viper supports file name completion | |
2252 and history, completion of Ex commands and variables, and many other | |
2253 features. Some of these features are explained in detail elsewhere in this | |
2254 document. Other features are explained here. | |
2255 | |
2256 @table @code | |
2257 @item (vip-buffer-search-enable) | |
2258 @item vip-buffer-search-char nil | |
2259 Enable buffer search. Explicit call to @code{vip-buffer-search-enable} | |
2260 sets @code{vip-buffer-search-char} to @kbd{g}. Alternatively, the user can | |
2261 set @code{vip-buffer-search-char} in @file{.vip} to a key sequence | |
2262 to be used for buffer search. There is no need to call | |
2263 @code{vip-buffer-search-enable} in that case. | |
2264 @findex @code{vip-buffer-search-enable} | |
2265 @vindex @code{vip-buffer-search-char} | |
2266 @item vip-toggle-search-style | |
2267 This function, bound to @kbd{C-c /}, lets one toggle case-sensitive and | |
2268 case-insensitive search, and also switch between plain vanilla search and | |
2269 search via regular expressions. Without the prefix argument, the user is | |
2270 asked which mode to toggle. With prefix argument 1, this toggles | |
2271 case-sensitivity. With prefix argument 2, regular expression/vanilla search | |
2272 will be toggled. | |
2273 | |
2274 However, we found that the most convenient way to toggle | |
2275 these options is to bind a Vi macro to | |
2276 bind @kbd{//} to toggles case sensitivity and to @kbd{///} to toggles | |
2277 vanilla search. Thus, quickly hitting @kbd{/} twice will switch Viper from | |
2278 case sensitive search to case-insensitive. Repeating this once again will | |
2279 restore the original state. Likewise, quickly hitting @kbd{/} three times | |
2280 will switch you from vanilla-style search to search via regular expressions. | |
2281 If you hit something other than @kbd{/} after the first @kbd{/} or if the | |
2282 second @kbd{/} doesn't follow quickly enough, then Viper will issue the | |
2283 usual prompt @kbd{/} and will wait for input, as usual in Vi. | |
2284 If you don't like this behavior, you can ``unrecord'' these macros in your | |
2285 @file{~/.vip} file. For instance, if u don't like the above feature, put | |
2286 this in @file{~/.vip}: | |
2287 @example | |
2288 (vip-unrecord-kbd-macro "//" 'vi-state) | |
2289 (vip-unrecord-kbd-macro "///" 'vi-state) | |
2290 @end example | |
2291 @findex @code{vip-unrecord-kbd-macro} | |
2292 | |
2293 @xref{Vi Macros}, for more information on Vi macros. | |
2294 @item vip-heading-start | |
2295 @item vip-heading-end | |
2296 @cindex headings | |
2297 @cindex sections | |
2298 @cindex paragraphs | |
2299 @cindex sentences | |
2300 Regular Expressions for @kbd{[[} and @kbd{]]}. Note that Emacs defines | |
2301 Regexps for paragraphs and sentences. @xref{Paragraphs,,Paragraphs and | |
2302 Sentences,emacs,The GNU Emacs Manual}, for details. | |
2303 @item M-x vip-set-expert-level | |
2304 @findex @code{vip-set-expert-level} | |
2305 Change your user level interactively. | |
2306 @item vip-smart-suffix-list '("" "tex" "c" "cc" "el" "p") | |
2307 @vindex @code{vip-smart-suffix-list} | |
2308 Viper supports Emacs-style file completion when it prompts the user for a | |
2309 file name. However, in many cases, the same directory may contain files | |
2310 with identical prefix but different suffixes, e.g., prog.c, prog.o, | |
2311 paper.tex, paper.dvi. In such cases, completion will stop at the `.'. | |
2312 If the above variable is a list of strings representing suffixes, Viper will | |
2313 try these suffixes | |
2314 in the order listed and will check if the corresponding file exists. | |
2315 | |
2316 For instance, if completion stopped at `paper.' and the user typed RET, | |
2317 then Viper will check if the files `paper.', `paper.tex', `paper.c', etc., exist. | |
2318 It will take the first such file. If no file exists, Viper will give a chance | |
2319 to complete the file name by typing the appropriate suffix. If `paper.' was | |
2320 the intended file name, hitting return will accept it. | |
2321 | |
2322 To turn this feature off, set the above variable to @code{nil}. | |
2323 | |
2324 @item vip-insertion-ring-size 14 | |
2325 @vindex @code{vip-insertion-ring-size} | |
2326 @cindex Insertion ring | |
2327 Viper remembers what was previously inserted in Insert and Replace states. | |
2328 Several such recent insertions are kept in a special ring of strings of size | |
2329 @code{vip-insertion-ring-size}. | |
2330 If you enter Insert or Replace state you can reinsert strings from this | |
2331 ring by typing @kbd{C-c M-p} or @kbd{C-c M-n}. The former will search the | |
2332 ring in | |
2333 the direction of older insertions, and the latter will search in | |
2334 the direction of newer insertions. Hitting @kbd{C-c M-p} or @kbd{C-c M-n} | |
2335 in succession | |
2336 will undo the previous insertion from the ring and insert the next item on | |
2337 the ring. If a larger ring size is needed, change the value of the above | |
2338 variable in the @file{~/.vip} file. | |
2339 | |
2340 Since typing these sequences of keys may be tedious, it is suggested that the | |
2341 user should bind a function key, such as @kbd{f31}, as follows: | |
2342 @example | |
2343 (define-key vip-insert-global-user-map [f31] | |
2344 'vip-insert-prev-from-insertion-ring) | |
2345 @end example | |
2346 This binds @kbd{f31} (which is usually @kbd{R11} on a Sun workstation) | |
2347 to the function that inserts the previous string in the insertion history. | |
2348 To rotate the history in the opposite | |
2349 direction, you can either bind an unused key to | |
2350 @code{vip-insert-next-from-insertion-ring} or hit any digit (1 to 9) then | |
2351 @kbd{f31}. | |
2352 | |
2353 One should not bind the above functions to @kbd{M-p} or @kbd{M-n}, since | |
2354 this will interfere with the Minibuffer histories and, possibly, other | |
2355 major modes. | |
2356 | |
2357 @item vip-command-ring-size 14 | |
2358 @vindex @code{vip-command-ring-size} | |
2359 @cindex Destructive command ring | |
2360 @cindex Destructive command history | |
2361 Viper keeps track of the recent history of destructive | |
2362 commands, such as @kbd{dw}, @kbd{i}, etc. | |
2363 In Vi state, | |
2364 the most recent command can be re-executed by hitting `@kbd{.}', as in Vi. | |
2365 However, repeated typing @kbd{C-c M-p} will cause Viper to show the | |
2366 previous destructive commands in the minibuffer. Subsequent hitting `@kbd{.}' | |
2367 will execute the command that was displayed last. | |
2368 The key @kbd{C-c M-n} will cycle through the command history in the | |
2369 opposite direction. | |
2370 Since typing @kbd{C-c M-p} may be tedious, it is more convenient to bind an | |
2371 appropriate function to an unused function key on the keyboard and use that | |
2372 key. For instance, the following | |
2373 @example | |
2374 (define-key vip-vi-global-user-map [f31] | |
2375 'vip-prev-destructive-command) | |
2376 @end example | |
2377 binds the key @kbd{f31} (which is usually @kbd{R11} on a Sun workstation) | |
2378 to the function that searches the command history in the direction of older | |
2379 commands. To search in the opposite | |
2380 direction, you can either bind an unused key to | |
2381 @code{vip-next-destructive-command} or hit any digit (1 to 9) then @kbd{f31}. | |
2382 | |
2383 One should not bind the above functions to @kbd{M-p} or @kbd{M-n}, since | |
2384 this will interfere with the Minibuffer histories and, possibly, other | |
2385 major modes. | |
2386 | |
2387 @item vip-minibuffer-vi-face 'vip-minibuffer-vi-face | |
2388 @item vip-minibuffer-insert-face 'vip-minibuffer-insert-face | |
2389 @item vip-minibuffer-emacs-face 'vip-minibuffer-emacs-face | |
2390 These faces control the appearance of the minibuffer text in the | |
2391 corresponding Viper states. For heavy-duty customization, consult | |
2392 the Lisp Reference to Emacs. You can also take a look how these faces are | |
2393 defined in @file{viper.el}. | |
2394 | |
2395 However, on a color workstation, the following method usually suffices: | |
2396 @example | |
2397 (set-face-foreground vip-minibuffer-vi-face "blue") | |
2398 (set-face-background vip-minibuffer-emacs-face "orchid") | |
2399 @end example | |
2400 This will make a blue foreground in the Minibuffer when it is in Vi | |
2401 state; its background will turn to orchid when it switches to Emacs state. | |
2402 | |
2403 Note that only the text you type in is affected by the above faces. | |
2404 Prompts and Minibuffer messages are not affected. | |
2405 | |
2406 Purists who do not like adornments in the minibuffer can always zap them by | |
2407 putting | |
2408 @example | |
2409 (copy-face 'default 'vip-minibuffer-vi-face) | |
2410 (copy-face 'default 'vip-minibuffer-insert-face) | |
2411 (copy-face 'default 'vip-minibuffer-emacs-face) | |
2412 @end example | |
2413 in the @file{~/.vip} file. However, in that case, the user will not have any | |
2414 indication of the current Viper state in the minibuffer. (This is important | |
2415 if the user accidentally switches to another Viper state by typing @kbd{ESC} or | |
2416 @kbd{C-z}. | |
2417 @end table | |
2418 | |
2419 @cindex Multifile documents and programs | |
2420 | |
2421 Viper provides some support for multi-file documents and programs. | |
2422 If a document consists of several files we can designate one of them as a | |
2423 master and put the following at the end of that file: | |
2424 @lisp | |
2425 ;;; Local Variables: | |
2426 ;;; eval: (vip-setup-master-buffer "file1" "file2" "file3" "file5" "file5") | |
2427 ;;; End: | |
2428 @end lisp | |
2429 @noindent | |
2430 where @code{file1} to @code{file5} are names of files related to the master | |
2431 file. Next time, when the master file is visited, the command | |
2432 @code{vip-setup-master-buffer} will be evaluated and the above files will | |
2433 be associated with the master file. Then, the new Ex command | |
2434 @kbd{:RelatedFile} (abbr. @kbd{:R}) will display files 1 to 5 one after | |
2435 another, so you can edit them. If a file is not in any Emacs buffer, it | |
2436 will be visited. The command @kbd{PreviousRelatedFile} (abbr., @kbd{:P}) | |
2437 goes through the file list in the opposite direction. | |
2438 @findex @kbd{:RelatedFile} | |
2439 @findex @kbd{:PreviousRelatedFile} | |
2440 | |
2441 These commands are akin to @kbd{:n} and @kbd{:N}, but they allow the user to | |
2442 focus on relevant files only. | |
2443 | |
2444 Note that only the master file needs to have the aforementioned block of | |
2445 commands. Also, ";;;" above can be replaced by some other | |
2446 markers. Semicolon is good for Lisp programs, since it is considered a | |
2447 comment designator there. For LaTeX, this could be "%%%", and for C the | |
2448 above block should be commented out. | |
2449 | |
2450 Even though these commands are sometimes useful, they are no substitute for | |
2451 the powerful @emph{tag table} facility of Emacs. Viper's @kbd{:tag} command | |
2452 in a primitive interface to Emacs tags. @xref{Tags,Tags,Tags,emacs, | |
2453 The Gnu Emacs Manual}, for more information on tags. | |
2454 | |
2455 The following two commands are normally bound to a mouse click and are part | |
2456 of Viper. They work only if Emacs runs as an application under X | |
2457 Windows (or under some other window system for which a port of GNU Emacs 19 | |
2458 is available). Clicking the mouse when Emacs is invoked in an Xterm window | |
2459 (using @code{emacs -nw}) will do no good. | |
2460 | |
2461 @table @code | |
2462 @cindex mouse | |
2463 @item M-S-mouse-1 (Emacs) | |
2464 @item meta shift button1up (XEmacs) | |
2465 Holding Meta and Shift while clicking mouse button 1 | |
2466 will initiate search for a region under the | |
2467 mouse pointer (defined below). This command can take a prefix argument, | |
2468 which indicates the occurrence of the pattern to search for. | |
2469 | |
2470 Note: Viper binds this mouse action only if it is not already bound to | |
2471 something else. If you want to use this feature and @kbd{M-S-mouse-1} | |
2472 is already used for something else, you can rebind mouse-search as, for | |
2473 example, in the following example: | |
2474 @lisp | |
2475 (global-set-key [M-mouse-1] 'vip-mouse-click-search-word) | |
2476 (global-set-key [M-down-mouse-1] 'vip-mouse-catch-frame-switch) | |
2477 @end lisp | |
2478 This would bind mouse search to the action invoked by pressing the | |
2479 Meta key and clicking mouse button 1. Note: if | |
2480 @code{vip-mouse-click-search-word} is bound to an action, then | |
2481 @code{vip-mouse-catch-frame-switch} must be bound to a down-action, as | |
2482 shown in the above example. | |
2483 | |
2484 In XEmacs, you can change bindings as follows: | |
2485 @lisp | |
2486 (global-set-key [(meta control button1up)] | |
2487 'vip-mouse-click-search-word) | |
2488 (global-set-key [(meta control button1)] | |
2489 'vip-mouse-catch-frame-switch) | |
2490 @end lisp | |
2491 if, say, you prefer to hold both meta and control while clicking. | |
2492 | |
2493 Like in Emacs, there are special rules for binding these functions: the | |
2494 first must be bound to a button-up event while the second must be bound to | |
2495 a button-event (which is XEmacs' equivalent of a down-mouse event). Also, | |
2496 in Emacs, the double-click and triple-click actions for the same button | |
2497 (@code{double-S-mouse-1}, etc., if the above default binding is used) | |
2498 should not be bound (or it should be bound to the same function, | |
2499 @code{vip-mouse-click-search-word}). | |
2500 | |
2501 The region that is chosen as a pattern to search for is determined as | |
2502 follows. If search is invoked via a single click, Viper chooses the region | |
2503 that lies between the beginning of the ``word'' under the pointer (``word'' | |
2504 is understood in Vi sense) and the end of that word. The only difference | |
2505 with Vi's words is that in Lisp major modes `-' is considered an | |
2506 alphanumeric symbol. This is done for the convenience of working with Lisp | |
2507 symbols, which often have an `-' in them. Also, if you click on a | |
2508 non-alphanumeric character that is not a word separator (in Vi sense) then | |
2509 this character will also be considered alphanumeric, provided that it is | |
2510 adjacent (from either side) to an alphanumeric character. This useful | |
2511 feature gives added control over the patterns selected by the mouse click. | |
2512 | |
2513 On a double-click, the region is determined by the beginning of the current | |
2514 Vi's ``Word'' (i.e., the largest non-separator chunk of text) and the End | |
2515 of that ``Word'' (as determined by the @kbd{E} command). | |
2516 | |
2517 On a triple-click, the region consists of the entire line where the click | |
2518 occurred with all leading and trailing spaces and tabs removed. | |
2519 | |
2520 @item M-S-mouse-2 (Emacs) | |
2521 @item meta shift button2up (XEmacs) | |
2522 Holding Meta and Shift while clicking mouse button 2 | |
2523 will insert the region surrounding the | |
2524 mouse pointer. The rules defining this region are the same as for | |
2525 mouse-search. This command takes an optional prefix argument, which | |
2526 indicates how many such regions to snarf from the buffer and insert. (In | |
2527 case of a triple-click, the prefix argument is ignored.) | |
2528 | |
2529 Note: Viper binds this mouse action only if it not already bound to | |
2530 something else. If you want to use this feature and @kbd{S-mouse-2} | |
2531 is already used for something else, you can rebind mouse-insert as follows: | |
2532 @lisp | |
2533 (global-set-key [M-mouse-2] 'vip-mouse-click-insert-word) | |
2534 (global-set-key [M-down-mouse-2] 'vip-mouse-catch-frame-switch) | |
2535 @end lisp | |
2536 In XEmacs, you can change the bindings as follows: | |
2537 @lisp | |
2538 (global-set-key [(meta control button2up)] | |
2539 'vip-mouse-click-insert-word) | |
2540 (global-set-key [(meta control button2)] | |
2541 'vip-mouse-catch-frame-switch) | |
2542 @end lisp | |
2543 | |
2544 @item vip-multiclick-timeout | |
2545 This variable controls the rate at which double-clicking must occur for the | |
2546 purpose of mouse search and mouse insert. By default, this is set to | |
2547 @code{double-click-time} in Emacs and to | |
2548 @code{mouse-track-multi-click-time} milliseconds in XEmacs. | |
2549 @end table | |
2550 @kindex @kbd{S-mouse-1} | |
2551 @kindex @kbd{S-mouse-2} | |
2552 @kindex @kbd{meta shift button1up} | |
2553 @kindex @kbd{meta shift button2up} | |
2554 @vindex @code{vip-multiclick-timeout} | |
2555 @findex @code{vip-mouse-click-insert-word} | |
2556 @findex @code{vip-mouse-click-search-word} | |
2557 | |
2558 Note: The above functions search and insert in the selected window of | |
2559 the latest active frame. This means that you can click in another window or | |
2560 another frame and have search or insertion done in the frame and window you | |
2561 just left. This lets one use these functions in a multi-frame | |
2562 configuration. However, this may require some getting used to. For | |
2563 instance, if you are typing in a frame, A, and then move the mouse to frame | |
2564 B and click to invoke mouse search, search (or insertion) will be performed | |
2565 in frame A. To perform search/insertion in frame B, you will first have to | |
2566 shift focus there, which doesn't happen until you type a character or | |
2567 perform some other action in frame B---mouse search doesn't shift focus (in | |
2568 XEmacs, to shift focus to frame B, you will have to select this frame with | |
2569 a mouse, by clicking. | |
2570 | |
2571 If you decide that you don't like the above feature and always want | |
2572 search/insertion be performed in the frame where the click occurs, don't | |
2573 bind (and unbind, if necessary) @code{vip-mouse-catch-frame-switch} from | |
2574 the mouse event it is bound to. | |
2575 | |
2576 Mouse search is integrated with Vi-style search, so you can | |
2577 repeat it with @kbd{n} and @kbd{N}. It should be also noted that, while | |
2578 case-sensitivity of search in Viper is controlled by the variable | |
2579 @code{vip-case-fold-search}, the case of mouse search is | |
2580 controlled by the Emacs variable @code{case-fold-search}, which may be set | |
2581 differently from @code{vip-case-fold-search}. Therefore, case-sensitivity | |
2582 of mouse search may be different from that of the usual Vi-style search. | |
2583 | |
2584 Finally, if the way Viper determines the word to be searched for or to be | |
2585 inserted is not what you want, there is a variable, | |
2586 @code{vip-surrounding-word-function}, which can be changed to indicate | |
2587 another function for snarfing words out of the buffer. The catch is that | |
2588 you will then have to write such a function and make it known to your | |
2589 Emacs. The function @code{vip-surrounding-word} in @file{viper.el} can be | |
2590 used as a guiding example. | |
2591 | |
2592 @node Vi Macros, ,Viper Specials,Customization | |
2593 @section Vi Macros | |
2594 | |
2595 @cindex Vi macros | |
2596 | |
2597 Viper supports much enhanced Vi-style macros and also facilitates the use | |
2598 of Emacs-style macros. To define a temporary macro, it is generally more | |
2599 convenient to use Emacs keyboard macro facility. Emacs keyboard macros are | |
2600 usually defined anonymously, and the latest macro can be executed by typing | |
2601 @kbd{C-x e} (or @kbd{*}, if Viper is in Vi state). If you need to use several | |
2602 temporary macros, Viper lets you save them to a | |
2603 register (a lowercase letter); such macros can then be executed by typing | |
2604 @kbd{@@a} in Vi state (if a macro was previously saved in register | |
2605 @kbd{a}). | |
2606 @xref{Macros and Registers}, for details. | |
2607 | |
2608 If, however, you need to use a macro regularly, it must be given a | |
2609 permanent name and saved. Emacs manual explains how to do this, but | |
2610 invocation of named Emacs macros is quite different from Vi's. First, | |
2611 invocation of permanent Emacs macros takes time because of the extra keys. | |
2612 Second, binding such macros to function keys, for | |
2613 fast access, hogs valuable real estate on the keyboard. | |
2614 | |
2615 Vi-style macros are better in that respect, since Vi lets the user overload | |
2616 the meaning of key sequences: keys typed in fast succession are treated | |
2617 specially, if this key sequence is bound to a macro. | |
2618 | |
2619 Viper provides keyboard macros through the usual Ex commands, @kbd{:map} and | |
2620 @kbd{:map!}. Vi-style macros are much more powerful in Viper than | |
2621 they are in the original Vi and in other emulators. This is because Viper | |
2622 implements an enhanced vi-style | |
2623 interface to the powerful Emacs keyboard macro facility. | |
2624 | |
2625 First, any Emacs | |
2626 command can be executed while defining a macro, not just the Vi | |
2627 commands. In particular, the user can invoke Emacs commands via @kbd{M-x | |
2628 command-name} or by pressing various function keys on the keyboard. One | |
2629 can even use the mouse, although this is usually not useful and is not | |
2630 recommended (and macros defined with the use of the mouse cannot be saved in | |
2631 command history and in the startup file, for future use). | |
2632 | |
2633 Macros defined by mixing Vi and Emacs commands are represented as | |
2634 vectors. So, don't be confused when you see one (usually through the | |
2635 history of Ex commands). For instance, if @kbd{gg} is defined by typing | |
2636 @kbd{l}, the up-arrow key and @kbd{M-x next-line}, its definition will look | |
2637 as follows in Emacs (in XEmacs, it looks slightly different, see below): | |
2638 | |
2639 @example | |
2640 [l up (meta x) n e x t - l i n e return] | |
2641 @end example | |
2642 | |
2643 Second, Viper macros are defined in a WYSIWYG style. This means that | |
2644 commands are executed as you type them, so you can see precisely what is | |
2645 being defined. Third, macros can be bound to arbitrary sequences of keys, | |
2646 not just to printable keys. For instance, one can define a macro that will | |
2647 be invoked by hitting @kbd{f3} then @kbd{f2} function keys. (The keys | |
2648 @kbd{delete} and @kbd{backspace} are excluded; also, a macro invocation | |
2649 sequence can't start with ESC. Some other keys, such as @kbd{f1} and | |
2650 @kbd{help}, can't be bound to macros under Emacs (not XEmacs), since they | |
2651 are bound in @code{key-translation-map}, which overrides any other binding | |
2652 the user gives to keys. In general, keys that have a binding in | |
2653 @code{key-translation-map} can't be bound to a macro.) | |
2654 | |
2655 Fourth, in Viper, one can define macros that are specific to a given | |
2656 buffer, a given major mode, or macros that are defined for all buffers. In | |
2657 fact, the same macro name can have several different definitions: one | |
2658 global, several definitions for various major modes, and | |
2659 definitions for various specific buffers. Buffer-specific definitions | |
2660 override mode-specific definitions, which, in turn, override global | |
2661 definitions. | |
2662 | |
2663 As if all that is not enough, Viper (through its interface to Emacs | |
2664 macros) lets the user define keyboard macros that ask for confirmation or | |
2665 even prompt the user for input and then continue. To do this, one should | |
2666 type @kbd{C-x q} (for confirmation) or @kbd{C-u C-x q} (for prompt). | |
2667 For details, @pxref{Kbd Macro Query,,Customization,emacs,The GNU Emacs | |
2668 Manual} @refill | |
2669 | |
2670 When the user finishes defining a macro (which is done by typing @kbd{C-x)} --- | |
2671 a departure from Vi), you will be asked whether you want this | |
2672 macro to be global, mode-specific, or buffer-specific. You will also be | |
2673 given a chance to save the macro in your @file{~/.vip} file. | |
2674 This is the easiest way to save a macro and make | |
2675 it permanently available. If you work your startup files with bare hands, | |
2676 here is how Viper saves the above macro so that it will be | |
2677 available in Viper's Insert state (and Replace state) in buffer @code{my-buf} | |
2678 only: | |
2679 | |
2680 @example | |
2681 (vip-record-kbd-macro "gg" 'insert-state | |
2682 [l up (meta x) n e x t - l i n e return] | |
2683 "my-buf") | |
2684 @end example | |
2685 | |
2686 @noindent | |
2687 To do the same for Vi state and all buffers with the major mode | |
2688 @code{cc-mode}, use: | |
2689 | |
2690 @example | |
2691 (vip-record-kbd-macro "gg" 'vi-state | |
2692 [l up (meta x) n e x t - l i n e return] | |
2693 'cc-mode) | |
2694 @end example | |
2695 | |
2696 @noindent | |
2697 Both macro names and macro definitions are vectors of symbols that denote | |
2698 keys on the keyboard. Some keys, like @kbd{\}, @kbd{ }, or digit-keys must | |
2699 be escaped with a backslash. Modified keys are represented as lists. For | |
2700 instance, holding Meta and Control and pressing @kbd{f4} is represented as | |
2701 @kbd{(control meta f4)}. | |
2702 If all members of a vectors are printable characters (or sequences, such as | |
2703 @kbd{\e}, @kbd{\t}, for ESC and TAB), then they can also be represented as | |
2704 strings: | |
2705 | |
2706 @example | |
2707 (vip-record-kbd-macro "aa" 'vi-state "aaa\e" "my-buffer") | |
2708 @end example | |
2709 | |
2710 @noindent | |
2711 Thus, typing @kbd{aa} fast in Vi state will switch Viper to Insert state | |
2712 (due to the first @kbd{a}), insert @kbd{aa}, and then it will switch back to Vi | |
2713 state. All this will take effect only in the buffer named @code{my-buffer}. | |
2714 | |
2715 Note that the last argument to @code{vip-record-kbd-macro} must be either a | |
2716 string (a buffer name), a symbol representing a major mode, or @code{t}; | |
2717 the latter says that the macro is to be defined for all buffers | |
2718 (which is how macros are defined in original Vi). | |
2719 | |
2720 For convenience, Viper also lets you define Vi-style macros in its Emacs | |
2721 state. There is no Ex command, like @kbd{:map} and @kbd{:map!} for doing | |
2722 this, but the user can include such a macro in the @file{~/.vip} file. The | |
2723 only thing is that the @code{vip-record-kbd-macro} command should specify | |
2724 @code{'emacs-state} instead of @code{'vi-state} or @code{'insert-state}. | |
2725 | |
2726 The user can get rid of a macro either by using the Ex commands @kbd{:unmap} | |
2727 and @kbd{:unmap!} or by issuing a call to @code{vip-unrecord-kbd-macro}. | |
2728 The latter is more powerful, since it can delete macros even in | |
2729 @code{'emacs-state}. However, @code{vip-unrecord-kbd-macro} is usually | |
2730 needed only when the user needs to get rid of the macros that are already | |
2731 predefined in Viper. | |
2732 The syntax is: | |
2733 @findex @code{vip-unrecord-kbd-macro} | |
2734 @example | |
2735 (vip-unrecord-kbd-macro macro state) | |
2736 @end example | |
2737 @noindent | |
2738 The second argument must be @code{'vi-state}, @code{'insert-state}, or | |
2739 @code{'emacs-state}. The first argument is a name of a macro. To avoid | |
2740 mistakes in specifying names of existing macros, type @kbd{M-x | |
2741 vip-describe-kbd-macros} and use a name from the list displayed by this | |
2742 command. | |
2743 | |
2744 If an error occurs during macro definition, Emacs | |
2745 aborts the process, and it must be repeated. This is analogous to Vi, | |
2746 except that in Vi the user doesn't know there is an error until the macro is | |
2747 actually run. All that means that in order for a definition to be | |
2748 successful, the user must do some simple planning of the process in | |
2749 advance, to avoid errors. For instance, if you want to map @kbd{gg} to | |
2750 @kbd{llll} in Vi state, you must make sure that there is enough room on the | |
2751 current line. Since @kbd{l} moves the cursor forward, it may signal an | |
2752 error on reaching the end of line, which will abort the definition. | |
2753 | |
2754 These precautions are necessary only when defining macros; they will help | |
2755 avoid the need to redo the job. When macros are actually run, an error | |
2756 during the execution will simply terminate the current execution | |
2757 (but the macro will remain mapped). | |
2758 | |
2759 A macro name can be a string of characters or a vector of keys. | |
2760 The latter makes it possible to define macros bound to, say, double-hits | |
2761 on a function key, such as @kbd{up} or @kbd{f13}. | |
2762 This is very useful if you run out of function keys on your keyboard; it | |
2763 makes Viper macro facility a @emph{keyboard doubler}, so to speak. | |
2764 | |
2765 Elsewhere (@xref{Keybindings}, for details), we review | |
2766 the standard Emacs mechanism for binding function keys to commands. | |
2767 For instance, | |
2768 | |
2769 @example | |
2770 (global-set-key [f13] 'repeat-complex-command) | |
2771 @end example | |
2772 | |
2773 @noindent | |
2774 binds the key f13 to the Emacs function that repeats the last minibuffer | |
2775 command. Under Viper, however, you may still use this key for additional | |
2776 purposes, if you bind, say, a double-hitting action for that key to some | |
2777 other function. Emacs doesn't allow the user to do that, but Viper does | |
2778 this through its keyboard macro facility. To do this, type @kbd{:map } | |
2779 first. When you are asked to enter a macro name, hit f13 twice, followed by | |
2780 RET or SPC. | |
2781 | |
2782 Emacs will now start the mapping process by actually executing | |
2783 Vi and Emacs commands, so that you could see what will happen each time the | |
2784 macro is executed. Suppose now we wanted to bind the key sequence | |
2785 @kbd{f13 f13} to the command @code{eval-last-sexp}. To accomplish this, we | |
2786 can type @kbd{M-x eval-last-sexp} followed by @kbd{C-x )}. | |
2787 If you answer positively to Viper's offer to save this macro in @file{~/.vip} | |
2788 for future uses, the following will be inserted in that file: | |
2789 | |
2790 @example | |
2791 (vip-record-kbd-macro [f16 f16] 'vi-state | |
2792 [(meta x) e v a l - l a s t - s e x p] | |
2793 'lisp-interaction-mode) | |
2794 @end example | |
2795 | |
2796 To illustrate the above point, Viper provides two canned macros, which, by | |
2797 default, are bound to @kbd{[f12 \1]} and @kbd{[f12 \2]} (invoked by typing | |
2798 @kbd{f12} then @kbd{1} and @kbd{2}, respectively). These macros are useful | |
2799 shortcuts to Viper's command ring history. The first macro will execute the | |
2800 second-last destructive command (the last one is executed by @kbd{.}, as | |
2801 usual). The second macro executes the third-last command. | |
2802 | |
2803 If you need to go deeper into the command history, you will have to use | |
2804 other commands, as described earlier in this section; or you can bind, | |
2805 say, @kbd{f12 \3} like this: | |
2806 | |
2807 @example | |
2808 (vip-record-kbd-macro [f12 \3] 'vi-state | |
2809 [(meta x) r e p e a t - f r o m - h i s t o r y] | |
2810 t) | |
2811 @end example | |
2812 | |
2813 | |
2814 Note that even though the macro uses the function key @kbd{f12}, the key is | |
2815 actually free and can still be bound to some Emacs function via | |
2816 @code{define-key} or @code{global-set-key}. | |
2817 | |
2818 | |
2819 Viper allows the user to define macro names that are prefixes of other macros. | |
2820 For instance, one can define @kbd{[[} and @kbd{[[[[} to be macros. | |
2821 If you type the exact sequence of such keys and then pause, Viper will | |
2822 execute the right macro. However, if you don't pause and, say, type | |
2823 @kbd{[[[[text} then the conflict is resolved as follows. If only one of the | |
2824 key sequences, @kbd{[[} or @kbd{[[[[} has a definition applicable to the | |
2825 current buffer, then, in fact, there is no conflict and the right macro | |
2826 will be chosen. If both have applicable definitions, then the first one | |
2827 found will be executed. Usually this is the macro with a shorter name. So, | |
2828 in our case, @kbd{[[[[text} will cause the macro @kbd{[[} to be executed | |
2829 twice and then the remaining keys, @kbd{t e x t}, will be processed. | |
2830 | |
2831 When defining macros using @kbd{:map} or @kbd{:map!}, the user enters the | |
2832 actually keys to be used to invoke the macro. For instance, you should hit | |
2833 the actual key @kbd{f6} if it is to be part of a macro name; you do | |
2834 @emph{not} write `f 6'. When entering keys, Viper displays them as strings or | |
2835 vectors (e.g., "abc" or [f6 f7 a]). The same holds for unmapping. Hitting | |
2836 TAB while typing a macro name in the @kbd{:unmap} or @kbd{:unmap!} command | |
2837 will cause name completion. Completions are displayed as strings or vectors. | |
2838 However, as before, you don't actually type ``"'', ``['', or ``]'' that | |
2839 appear in the completions. These are meta-symbols that indicate whether | |
2840 the corresponding macro name is a vector or a string. | |
2841 | |
2842 One last difference from Vi: Vi-style keyboard macros cannot be defined in | |
2843 terms of other Vi-style keyboard macros (but named Emacs macros are OK). | |
2844 More precisely, while defining or executing a macro, the special meaning | |
2845 of key sequences (as Vi macros) is ignored. | |
2846 This is because it is all too easy to create an infinite loop in this way. | |
2847 Since Viper macros are much more powerful than Vi's it is impossible to | |
2848 detect such loops. In practice, this is not really a limitation but, | |
2849 rather, a feature. | |
2850 | |
2851 We should also note that Vi macros are disabled in the Minibuffer, which | |
2852 helps keep some potential troubles away. | |
2853 | |
2854 The rate at which the user must type keys in order for them to be | |
2855 recognized as a timeout macro is controlled by the variable | |
2856 @code{vip-fast-keyseq-timeout}, which defaults to 200 milliseconds. | |
2857 @vindex @code{vip-fast-keyseq-timeout} | |
2858 | |
2859 For the most part, Viper macros defined in @file{~/.vip} can be shared | |
2860 between Emacs, XEmacs, and X and TTY modes. However, macros defined via | |
2861 function keys may need separate definitions when XEmacs and Emacs have | |
2862 different names for the same keyboard key. For instance, the `Page Up' key | |
2863 may be known in Emacs as @kbd{prior} and in XEmacs as @kbd{pgup}. | |
2864 The problem with TTY may be that the function keys there generate sequences | |
2865 of events instead of a single event (as under a window system). | |
2866 Both Emacs and XEmacs mape some of these sequences back to the logical keys | |
2867 (e.g., the sequences generated by the arrow keys are mapped to @kbd{up}, | |
2868 @kbd{left}, etc.). However, not all function keys are mapped in this way. | |
2869 Macros that are bound to key sequences that contain such unmapped function | |
2870 keys have to be redefined for TTY's (and possibly for every type of TTY you | |
2871 may be using). To do this, start Emacs on an appropriate TTY device and | |
2872 define the macro using @kbd{:map}, as usual. | |
2873 | |
2874 @findex @code{vip-describe-kbd-macros} | |
2875 Finally, Viper provides a function that conveniently displays all macros | |
2876 currently defined. To see all macros along with their definitions, type | |
2877 @kbd{M-x vip-describe-kbd-macros}. | |
2878 | |
2879 @include viper-cmd.texi | |
2880 | |
2881 @node Acknowledgments,,,Top | |
2882 @comment node-name, next, previous, up | |
2883 @unnumbered Acknowledgments | |
2884 | |
2885 Viper, formerly known as VIP-19, was written by Michael Kifer. Viper is | |
2886 based on the original VIP package by Masahiko Sato and on its enhancement, | |
2887 VIP 4.4, by Aamod Sane. This manual is an adaptation of the manual for VIP | |
2888 4.4, which, in turn, was based on Sato's manual for VIP 3.5. | |
2889 | |
2890 Many contributors on the net pointed out bugs and suggested a number of | |
2891 useful features. Here is a (hopefully) complete list of contributors: | |
2892 | |
2893 @example | |
2894 jjm@@hplb.hpl.hp.com (Jean-Jacques Moreau), jl@@cse.ogi.edu (John | |
2895 Launchbury), rxga@@ulysses.att.com, jamesm@@bga.com (D.J. Miller II), | |
2896 ascott@@fws214.intel.com (Andy Scott), toma@@convex.convex.com, | |
2897 dave@@hellgate.utah.edu, cook@@biostat.wisc.edu | |
2898 (Tom Cook), lindstro@@biostat.wisc.edu (Mary Lindstrom), | |
2899 edmonds@@edmonds.home.cs.ubc.ca (Brian Edmonds), mveiga@@dit.upm.es | |
2900 (Marcelino Veiga Tuimil), dwight@@toolucky.llnl.gov (Dwight Shih), | |
2901 phil_brooks@@MENTORG.COM (Phil Brooks), kin@@isi.com (Kin Cho), | |
2902 ahg@@panix.com (Al Gelders), dwallach@@cs.princeton.edu (Dan Wallach), | |
2903 hpz@@ibmhpz.aug.ipp-garching.mpg.de (Hans-Peter Zehrfeld), | |
2904 simonb@@prl.philips.co.uk (Simon Blanchard), Mark.Bordas@@East.Sun.COM | |
2905 (Mark Bordas), gviswana@@cs.wisc.edu (Guhan Viswanathan), | |
2906 meyering@@comco.com (Jim Meyering), pfister@@cs.sunysb.edu (Hanspeter | |
2907 Pfister), amade@@diagram.fr (Paul-Bernard Amade), | |
2908 jackr@@dblues.engr.sgi.com (Jack Repenning), | |
2909 pogrell@@informatik.hu-berlin.de (Lutz Pogrell), | |
2910 csdayton@@midway.uchicago.edu (Soren Dayton), | |
2911 pradyut@@cs.uchicago.edu (Pradyut Shah), | |
2912 vrenjak@@sun1.racal.com (Milan Vrenjak), | |
2913 gvr@@halcyon.com (George V. Reilly), | |
2914 whicken@@dragon.parasoft.com (Wendell Hicken), | |
2915 terra@@diku.dk (Morten Welinder), | |
2916 kanze@@gabi-soft.fr (James Kanze), | |
2917 hatazaki@@bach.convex.com (Takao Hatazaki), | |
2918 sawdey@@lcse.umn.edu (Aaron Sawdey), | |
2919 jobrien@@hchp.org (John O'Brien), | |
2920 mrb@@Eng.Sun.COM (Martin Buchholz) | |
2921 @end example | |
2922 | |
2923 | |
2924 @node Key Index,Function Index,,Top | |
2925 @comment node-name, next, previous, up | |
2926 @unnumbered Key Index | |
2927 | |
2928 @printindex ky | |
2929 | |
2930 @node Function Index,Variable Index,Key Index,Top | |
2931 @comment node-name, next, previous, up | |
2932 @unnumbered Function Index | |
2933 | |
2934 @printindex fn | |
2935 | |
2936 @node Variable Index,Package Index,Function Index,Top | |
2937 @comment node-name, next, previous, up | |
2938 @unnumbered Variable Index | |
2939 | |
2940 @printindex vr | |
2941 | |
2942 @node Package Index,Concept Index,Variable Index,Top | |
2943 @comment node-name, next, previous, up | |
2944 @unnumbered Package Index | |
2945 | |
2946 @printindex pg | |
2947 | |
2948 @node Concept Index,,Package Index,Top | |
2949 @comment node-name, next, previous, up | |
2950 @unnumbered Concept Index | |
2951 | |
2952 @printindex cp | |
2953 | |
2954 @contents | |
2955 @bye |