]> code.delx.au - gnu-emacs/blob - doc/misc/vip.texi
Merge from emacs-24; up to 2014-06-02T11:35:40Z!michael.albinus@gmx.de
[gnu-emacs] / doc / misc / vip.texi
1 \input texinfo
2 @setfilename ../../info/vip
3 @settitle VIP
4
5 @documentencoding UTF-8
6
7 @copying
8 Copyright @copyright{} 1987, 2001--2014 Free Software Foundation, Inc.
9
10 @quotation
11 Permission is granted to copy, distribute and/or modify this document
12 under the terms of the GNU Free Documentation License, Version 1.3 or
13 any later version published by the Free Software Foundation; with no
14 Invariant Sections, with the Front-Cover Texts being ``A GNU Manual'',
15 and with the Back-Cover Texts as in (a) below. A copy of the license
16 is included in the section entitled ``GNU Free Documentation License''.
17
18 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
19 modify this GNU manual.''
20 @end quotation
21 @end copying
22
23 @titlepage
24 @sp 10
25 @center @titlefont{VIP}
26 @sp 1
27 @center A Vi Package for GNU Emacs
28 @center (Version 3.5, September 15, 1987)
29 @sp 2
30 @center Masahiko Sato
31 @page
32 @vskip 0pt plus1filll
33 @insertcopying
34 @end titlepage
35
36 @finalout
37 @contents
38
39 @dircategory Emacs misc features
40 @direntry
41 * VIP: (vip). An obsolete VI-emulation for Emacs.
42 @end direntry
43
44 @ifnottex
45 @node Top
46 @top VIP
47
48 VIP is a Vi emulating package written in Emacs Lisp. VIP implements most
49 Vi commands including Ex commands. It is therefore hoped that this package
50 will enable you to do Vi style editing under the powerful GNU Emacs
51 environment. This info file describes the usage of VIP assuming that you
52 are fairly accustomed to Vi but not so much with Emacs. Also we will
53 concentrate mainly on differences from Vi, especially features unique to
54 VIP.
55
56 VIP is obsolete since Emacs 24.5---consider using Viper instead.
57 @xref{Top, Viper,, viper, The Viper VI-emulation mode for Emacs}.
58
59 It is recommended that you read nodes on survey and on customization before
60 you start using VIP@. Other nodes may be visited as needed.
61
62 Comments and bug reports are welcome. Please send messages to
63 @code{ms@@Sail.Stanford.Edu} if you are outside of Japan and to
64 @code{masahiko@@sato.riec.tohoku.junet} if you are in Japan.
65
66 @insertcopying
67
68 @end ifnottex
69
70 @menu
71 * Survey:: A survey of VIP.
72 * Vi Commands:: Details of Vi commands.
73 * Ex Commands:: Details of Ex commands.
74 * Customization:: How to customize VIP.
75 * GNU Free Documentation License:: The license for this documentation.
76
77 @end menu
78 @iftex
79 @unnumbered Introduction
80
81 VIP is a Vi emulating package written in Emacs Lisp. VIP implements most
82 Vi commands including Ex commands. It is therefore hoped that this package
83 will enable you to do Vi style editing under the powerful GNU Emacs
84 environment. This manual describes the usage of VIP assuming that you are
85 fairly accustomed to Vi but not so much with Emacs. Also we will
86 concentrate mainly on differences from Vi, especially features unique to
87 VIP.
88
89 VIP is obsolete since Emacs 24.5---consider using Viper instead.
90 @xref{Top, Viper,, viper, The Viper VI-emulation mode for Emacs}.
91
92 It is recommended that you read chapters on survey and on customization
93 before you start using VIP@. Other chapters may be used as future
94 references.
95
96 Comments and bug reports are welcome. Please send messages to
97 @code{ms@@Sail.Stanford.Edu} if you are outside of Japan and to
98 @code{masahiko@@unsun.riec.tohoku.junet} if you are in Japan.
99 @end iftex
100
101 @node Survey
102 @chapter A Survey of VIP
103
104 In this chapter we describe basics of VIP with emphasis on the features not
105 found in Vi and on how to use VIP under GNU Emacs.
106
107 @menu
108 * Basic Concepts:: Basic concepts in Emacs.
109 * Loading VIP:: How to load VIP automatically.
110 * Modes in VIP:: VIP has three modes, which are orthogonal to modes
111 in Emacs.
112 * Differences from Vi:: Differences of VIP from Vi is explained.
113 @end menu
114
115 @node Basic Concepts
116 @section Basic Concepts
117
118 We begin by explaining some basic concepts of Emacs. These concepts are
119 explained in more detail in the GNU Emacs Manual.
120
121 @cindex buffer
122 @cindex point
123 @cindex mark
124 @cindex text
125 @cindex looking at
126 @cindex end (of buffer)
127 @cindex region
128
129 Conceptually, a @dfn{buffer} is just a string of @acronym{ASCII} characters and two
130 special characters @key{PNT} (@dfn{point}) and @key{MRK} (@dfn{mark}) such
131 that the character @key{PNT} occurs exactly once and @key{MRK} occurs at
132 most once. The @dfn{text} of a buffer is obtained by deleting the
133 occurrences of @key{PNT} and @key{MRK}. If, in a buffer, there is a
134 character following @key{PNT} then we say that point is @dfn{looking at}
135 the character; otherwise we say that point is @dfn{at the end of buffer}.
136 @key{PNT} and @key{MRK} are used
137 to indicate positions in a buffer and they are not part of the text of the
138 buffer. If a buffer contains a @key{MRK} then the text between @key{MRK}
139 and @key{PNT} is called the @dfn{region} of the buffer.
140
141 @cindex window
142
143 Emacs provides (multiple) @dfn{windows} on the screen, and you can see the
144 content of a buffer through the window associated with the buffer. The
145 cursor of the screen is always positioned on the character after @key{PNT}.
146
147 @cindex mode
148 @cindex keymap
149 @cindex local keymap
150 @cindex global keymap
151
152 A @dfn{keymap} is a table that records the bindings between characters and
153 command functions. There is the @dfn{global keymap} common to all the
154 buffers. Each buffer has its @dfn{local keymap} that determines the
155 @dfn{mode} of the buffer. Local keymap overrides global keymap, so that if
156 a function is bound to some key in the local keymap then that function will
157 be executed when you type the key. If no function is bound to a key in the
158 local map, however, the function bound to the key in the global map becomes
159 in effect.
160
161 @node Loading VIP
162 @section Loading VIP
163
164 The recommended way to load VIP automatically is to include the line:
165 @example
166 (load "vip")
167 @end example
168 @noindent
169 in your @file{.emacs} file. The @file{.emacs} file is placed in your home
170 directory and it will be executed every time you invoke Emacs. If you wish
171 to be in vi mode whenever Emacs starts up, you can include the following
172 line in your @file{.emacs} file instead of the above line:
173 @example
174 (add-hook 'emacs-startup-hook 'vip-mode)
175 @end example
176 @noindent
177 (@xref{Vi Mode}, for the explanation of vi mode.)
178
179 Even if your @file{.emacs} file does not contain any of the above lines,
180 you can load VIP and enter vi mode by typing the following from within
181 Emacs.
182 @example
183 M-x vip-mode
184 @end example
185 @noindent
186
187 @node Modes in VIP
188 @section Modes in VIP
189
190 @kindex 032 @kbd{C-z} (@code{vip-change-mode-to-vi})
191 @kindex 0301 @kbd{C-x C-z} (@code{suspend-emacs})
192
193 Loading VIP has the effect of globally binding @kbd{C-z} (@kbd{Control-z})
194 to the function @code{vip-change-mode-to-vi}. The default binding of @kbd{C-z}
195 in GNU Emacs is @code{suspend-emacs}, but, you can also call
196 @code{suspend-emacs} by typing @kbd{C-x C-z}. Other than this, all the
197 key bindings of Emacs remain the same after loading VIP.
198
199 @cindex vi mode
200
201 Now, if you hit @kbd{C-z}, the function @code{vip-change-mode-to-vi} will be
202 called and you will be in @dfn{vi mode}. (Some major modes may locally bind
203 @kbd{C-z} to some special functions. In such cases, you can call
204 @code{vip-change-mode-to-vi} by @code{execute-extended-command} which is
205 invoked by @kbd{M-x}. Here @kbd{M-x} means @kbd{Meta-x}, and if your
206 terminal does not have a @key{META} key you can enter it by typing
207 @kbd{@key{ESC} x}. The same effect can also be achieve by typing
208 @kbd{M-x vip-mode}.)
209
210 @cindex mode line
211
212 You can observe the change of mode by looking at the @dfn{mode line}. For
213 instance, if the mode line is:
214 @example
215 -----Emacs: *scratch* (Lisp Interaction)----All------------
216 @end example
217 @noindent
218 then it will change to:
219 @example
220 -----Vi: *scratch* (Lisp Interaction)----All------------
221 @end example
222 @noindent
223 Thus the word @samp{Emacs} in the mode line will change to @samp{Vi}.
224
225 @cindex insert mode
226 @cindex emacs mode
227
228 You can go back to the original @dfn{emacs mode} by typing @kbd{C-z} in
229 vi mode. Thus @kbd{C-z} toggles between these two modes.
230
231 Note that modes in VIP exist orthogonally to modes in Emacs. This means
232 that you can be in vi mode and at the same time, say, shell mode.
233
234 Vi mode corresponds to Vi's command mode. From vi mode you can enter
235 @dfn{insert mode} (which corresponds to Vi's insert mode) by usual Vi command
236 keys like @kbd{i}, @kbd{a}, @kbd{o} @dots{} etc.
237
238 In insert mode, the mode line will look like this:
239 @example
240 -----Insert *scratch* (Lisp Interaction)----All------------
241 @end example
242 @noindent
243 You can exit from insert mode by hitting @key{ESC} key as you do in Vi.
244
245 That VIP has three modes may seem very complicated, but in fact it is not
246 so. VIP is implemented so that you can do most editing remaining only
247 in the two modes for Vi (that is vi mode and insert mode).
248
249 @ifinfo
250 The figure below shows the transition of three modes in VIP.
251 @display
252
253
254 === C-z ==> == i,o ... ==>
255 emacs mode vi mode insert mode
256 <== X-z === <=== ESC ====
257 @end display
258 @end ifinfo
259
260 @menu
261 * Emacs Mode:: This is the mode you should know better.
262 * Vi Mode:: Vi commands are executed in this mode.
263 * Insert Mode:: You can enter text, and also can do editing if you
264 know enough Emacs commands.
265 @end menu
266
267 @node Emacs Mode
268 @subsection Emacs Mode
269
270 @kindex 032 @kbd{C-z} (@code{vip-change-mode-to-vi})
271
272 You will be in this mode just after you loaded VIP@. You can do all
273 normal Emacs editing in this mode. Note that the key @kbd{C-z} is globally
274 bound to @code{vip-change-mode-to-vi}. So, if you type @kbd{C-z} in this mode
275 then you will be in vi mode.
276
277 @node Vi Mode
278 @subsection Vi Mode
279
280 This mode corresponds to Vi's command mode. Most Vi commands work as they
281 do in Vi. You can go back to emacs mode by typing @kbd{C-z}. You can
282 enter insert mode, just as in Vi, by typing @kbd{i}, @kbd{a} etc.
283
284 @node Insert Mode
285 @subsection Insert Mode
286
287 The key bindings in this mode is the same as in the emacs mode except for
288 the following 4 keys. So, you can move around in the buffer and change
289 its content while you are in insert mode.
290
291 @table @kbd
292 @item @key{ESC}
293 @kindex 033 @kbd{ESC} (@code{vip-change-mode-to-vi}) (insert mode)
294 This key will take you back to vi mode.
295 @item C-h
296 @kindex 010 @kbd{C-h} (@code{vip-delete-backward-char}) (insert mode)
297 Delete previous character.
298 @item C-w
299 @kindex 027 @kbd{C-w} (@code{vip-delete-backward-word}) (insert mode)
300 Delete previous word.
301 @item C-z
302 @kindex 032 @kbd{C-z} (@code{vip-ESC}) (insert mode)
303 Typing this key has the same effect as typing @key{ESC} in emacs mode.
304 Thus typing @kbd{C-z x} in insert mode will have the same effect as typing
305 @kbd{ESC x} in emacs mode.
306 @end table
307
308 @node Differences from Vi
309 @section Differences from Vi
310
311 The major differences from Vi are explained below.
312
313 @menu
314 * Undoing:: You can undo more in VIP.
315 * Changing:: Commands for changing the text.
316 * Searching:: Search commands.
317 * z Command:: You can now use zH, zM and zL as well as z- etc.
318 * Counts:: Some Vi commands which do not accept a count now
319 accept one.
320 * Marking:: You can now mark the current point, beginning of
321 the buffer etc.
322 * Region Commands:: You can now give a region as an argument for delete
323 commands etc.
324 * New Commands:: Some new commands not available in Vi are added.
325 * New Bindings:: Bindings of some keys are changed for the
326 convenience of editing under Emacs.
327 * Window Commands:: Commands for moving among windows etc.
328 * Buffer Commands:: Commands for selecting buffers etc.
329 * File Commands:: Commands for visiting files etc.
330 * Misc Commands:: Other useful commands.
331 @end menu
332
333 @node Undoing
334 @subsection Undoing
335
336 @kindex 165 @kbd{u} (@code{vip-undo})
337 @kindex 056 @kbd{.} (@code{vip-repeat})
338
339 You can repeat undoing by the @kbd{.} key. So, @kbd{u} will undo
340 a single change, while @kbd{u .@: .@: .@:}, for instance, will undo 4 previous
341 changes. Undo is undoable as in Vi. So the content of the buffer will
342 be the same before and after @kbd{u u}.
343
344 @node Changing
345 @subsection Changing
346
347 Some commands which change a small number of characters are executed
348 slightly differently. Thus, if point is at the beginning of a word
349 @samp{foo} and you wished to change it to @samp{bar} by typing @w{@kbd{c w}},
350 then VIP will prompt you for a new word in the minibuffer by the prompt
351 @samp{foo => }. You can then enter @samp{bar} followed by @key{RET} or
352 @key{ESC} to complete the command. Before you enter @key{RET} or
353 @key{ESC} you can abort the command by typing @kbd{C-g}. In general,
354 @kindex 007 @kbd{C-g} (@code{vip-keyboard-quit})
355 you can abort a partially formed command by typing @kbd{C-g}.
356
357 @node Searching
358 @subsection Searching
359
360 @kindex 057 @kbd{/} (@code{vip-search-forward})
361 @kindex 077 @kbd{?} (@code{vip-search-backward})
362
363 As in Vi, searching is done by @kbd{/} and @kbd{?}. The string will be
364 searched literally by default. To invoke a regular expression search,
365 first execute the search command @kbd{/} (or @kbd{?}) with empty search
366 string. (I.e., type @kbd{/} followed by @key{RET}.)
367 A search for empty string will toggle the search mode between vanilla
368 search and regular expression search. You cannot give an offset to the
369 search string. (It is a limitation.) By default, search will wrap around
370 the buffer as in Vi. You can change this by rebinding the variable
371 @code{vip-search-wrap-around}. @xref{Customization}, for how to do this.
372
373 @node z Command
374 @subsection z Command
375
376 @kindex 1723 @kbd{z H} (@code{vip-line-to-top})
377 @kindex 1721 @kbd{z RET} (@code{vip-line-to-top})
378 @kindex 1723 @kbd{z M} (@code{vip-line-to-middle})
379 @kindex 1722 @kbd{z .} (@code{vip-line-to-middle})
380 @kindex 1723 @kbd{z L} (@code{vip-line-to-bottom})
381 @kindex 1722 @kbd{z -} (@code{vip-line-to-bottom})
382
383 For those of you who cannot remember which of @kbd{z} followed by @key{RET},
384 @kbd{.}@: and @kbd{-} do what. You can also use @kbd{z} followed by @kbd{H},
385 @kbd{M} and @kbd{L} to place the current line in the Home (Middle, and
386 Last) line of the window.
387
388 @node Counts
389 @subsection Counts
390
391 Some Vi commands which do not accept a count now accept one
392
393 @table @kbd
394 @item p
395 @itemx P
396 @kindex 160 @kbd{p} (@code{vip-put-back})
397 @kindex 120 @kbd{P} (@code{vip-Put-back})
398 Given counts, text will be yanked (in Vi's sense) that many times. Thus
399 @kbd{3 p} is the same as @kbd{p p p}.
400 @item o
401 @itemx O
402 @kindex 157 @kbd{o} (@code{vip-open-line})
403 @kindex 117 @kbd{O} (@code{vip-Open-line})
404 Given counts, that many copies of text will be inserted. Thus
405 @kbd{o a b c @key{ESC}} will insert 3 lines of @samp{abc} below the current
406 line.
407 @item /
408 @itemx ?
409 @kindex 057 @kbd{/} (@code{vip-search-forward})
410 @kindex 077 @kbd{?} (@code{vip-search-backward})
411 Given a count @var{n}, @var{n}-th occurrence will be searched.
412 @end table
413
414 @node Marking
415 @subsection Marking
416
417 Typing an @kbd{m} followed by a lower-case character @var{ch} marks the
418 point to the register named @var{ch} as in Vi. In addition to these, we
419 have following key bindings for marking.
420
421 @kindex 155 @kbd{m} (@code{vip-mark-point})
422
423 @table @kbd
424 @item m <
425 Set mark at the beginning of buffer.
426 @item m >
427 Set mark at the end of buffer.
428 @item m .
429 Set mark at point (and push old mark on mark ring).
430 @item m ,
431 Jump to mark (and pop mark off the mark ring).
432 @end table
433
434 @node Region Commands
435 @subsection Region Commands
436
437 @cindex region
438
439 Vi operators like @kbd{d}, @kbd{c} etc. are usually used in combination
440 with motion commands. It is now possible to use current region as the
441 argument to these operators. (A @dfn{region} is a part of buffer
442 delimited by point and mark.) The key @kbd{r} is used for this purpose.
443 Thus @kbd{d r} will delete the current region. If @kbd{R} is used instead
444 of @kbd{r} the region will first be enlarged so that it will become the
445 smallest region containing the original region and consisting of whole
446 lines. Thus @kbd{m .@: d R} will have the same effect as @kbd{d d}.
447
448 @node New Commands
449 @subsection Some New Commands
450
451 Note that the keys below (except for @kbd{R}) are not used in Vi.
452
453 @table @kbd
454 @item C-a
455 @kindex 001 @kbd{C-a} (@code{vip-beginning-of-line})
456 Move point to the beginning of line.
457 @item C-n
458 @kindex 016 @kbd{C-n} (@code{vip-next-window})
459 If you have two or more windows in the screen, this key will move point to
460 the next window.
461 @item C-o
462 @kindex 017 @kbd{C-o} (@code{vip-open-line-at-point})
463 Insert a newline and leave point before it, and then enter insert mode.
464 @item C-r
465 @kindex 022 @kbd{C-r} (@code{isearch-backward})
466 Backward incremental search.
467 @item C-s
468 @kindex 023 @kbd{C-s} (@code{isearch-forward})
469 Forward incremental search.
470 @item C-c
471 @itemx C-x
472 @itemx @key{ESC}
473 @kindex 003 @kbd{C-c} (@code{vip-ctl-c})
474 @kindex 0300 @kbd{C-x} (@code{vip-ctl-x})
475 @kindex 033 @kbd{ESC} (@code{vip-ESC})
476 These keys will exit from vi mode and return to emacs mode temporarily. If
477 you hit one of these keys, Emacs will be in emacs mode and will believe
478 that you hit that key in emacs mode. For example, if you hit @kbd{C-x}
479 followed by @kbd{2}, then the current window will be split into 2 and you
480 will be in vi mode again.
481 @item \
482 @kindex 134 @kbd{\} (@code{vip-escape-to-emacs})
483 Escape to emacs mode. Hitting @kbd{\} will take you to emacs mode, and you
484 can execute a single Emacs command. After executing the Emacs command you
485 will be in vi mode again. You can give a count before typing @kbd{\}.
486 Thus @kbd{5 \ *}, as well as @kbd{\ C-u 5 *}, will insert @samp{*****}
487 before point. Similarly @kbd{1 0 \ C-p} will move the point 10 lines above
488 the current line.
489 @item K
490 @kindex 113 @kbd{K} (@code{vip-kill-buffer})
491 Kill current buffer if it is not modified. Useful when you selected a
492 buffer which you did not want.
493 @item Q
494 @itemx R
495 @kindex 121 @kbd{Q} (@code{vip-query-replace})
496 @kindex 122 @kbd{R} (@code{vip-replace-string})
497 @kbd{Q} is for query replace and @kbd{R} is for replace. By default,
498 string to be replaced are treated literally. If you wish to do a regular
499 expression replace, first do replace with empty string as the string to be
500 replaced. In this way, you can toggle between vanilla and regular
501 expression replacement.
502 @item v
503 @itemx V
504 @kindex 166 @kbd{v} (@code{vip-find-file})
505 @kindex 126 @kbd{V} (@code{vip-find-file-other-window})
506 These keys are used to Visit files. @kbd{v} will switch to a buffer
507 visiting file whose name can be entered in the minibuffer. @kbd{V} is
508 similar, but will use window different from the current window.
509 @item #
510 @kindex 0430 @kbd{#} (@code{vip-command-argument})
511 If followed by a certain character @var{ch}, it becomes an operator whose
512 argument is the region determined by the motion command that follows.
513 Currently, @var{ch} can be one of @kbd{c}, @kbd{C}, @kbd{g}, @kbd{q} and
514 @kbd{s}.
515 @item # c
516 @kindex 0432 @kbd{# c} (@code{downcase-region})
517 Change upper-case characters in the region to lower case
518 (@code{downcase-region}).
519 @item # C
520 @kindex 0431 @kbd{# C} (@code{upcase-region})
521 Change lower-case characters in the region to upper case. For instance,
522 @kbd{# C 3 w} will capitalize 3 words from the current point
523 (@code{upcase-region}).
524 @item # g
525 @kindex 0432 @kbd{# g} (@code{vip-global-execute})
526 Execute last keyboard macro for each line in the region
527 (@code{vip-global-execute}).
528 @item # q
529 @kindex 0432 @kbd{# q} (@code{vip-quote-region})
530 Insert specified string at the beginning of each line in the region
531 (@code{vip-quote-region}).
532 @item # s
533 @kindex 0432 @kbd{# s} (@code{spell-region})
534 Check spelling of words in the region (@code{spell-region}).
535 @item *
536 @kindex 052 @kbd{*} (@code{vip-call-last-kbd-macro})
537 Call last keyboard macro.
538 @end table
539
540 @node New Bindings
541 @subsection New Key Bindings
542
543 In VIP the meanings of some keys are entirely different from Vi. These key
544 bindings are done deliberately in the hope that editing under Emacs will
545 become easier. It is however possible to rebind these keys to functions
546 which behave similarly as in Vi. @xref{Customizing Key Bindings}, for
547 details.
548
549 @table @kbd
550 @item C-g
551 @itemx g
552 @kindex 007 @kbd{C-g} (@code{vip-keyboard-quit})
553 @kindex 147 @kbd{g} (@code{vip-info-on-file})
554 In Vi, @kbd{C-g} is used to get information about the file associated to
555 the current buffer. Here, @kbd{g} will do that, and @kbd{C-g} is
556 used to abort a command (this is for compatibility with emacs mode.)
557 @item SPC
558 @itemx @key{RET}
559 @kindex 040 @kbd{SPC} (@code{vip-scroll})
560 @kindex 015 @kbd{RET} (@code{vip-scroll-back})
561 Now these keys will scroll up and down the text of current window.
562 Convenient for viewing the text.
563 @item s
564 @itemx S
565 @kindex 163 @kbd{s} (@code{vip-switch-to-buffer})
566 @kindex 123 @kbd{S} (@code{vip-switch-to-buffer-other-window})
567 They are used to switch to a specified buffer. Useful for switching to
568 already existing buffer since buffer name completion is provided. Also
569 a default buffer will be given as part of the prompt, to which you can
570 switch by just typing @key{RET} key. @kbd{s} is used to select buffer
571 in the current window, while @kbd{S} selects buffer in another window.
572 @item C
573 @itemx X
574 @kindex 103 @kbd{C} (@code{vip-ctl-c-equivalent})
575 @kindex 1300 @kbd{X} (@code{vip-ctl-x-equivalent})
576 These keys will exit from vi mode and return to emacs mode temporarily.
577 If you type @kbd{C} (@kbd{X}), Emacs will be in emacs mode and will believe
578 that you have typed @kbd{C-c} (@kbd{C-x}) in emacs mode. Moreover,
579 if the following character you type is an upper-case letter, then Emacs
580 will believe that you have typed the corresponding control character.
581 You will be in vi mode again after the command is executed. For example,
582 typing @kbd{X S} in vi mode is the same as typing @kbd{C-x C-s} in emacs
583 mode. You get the same effect by typing @kbd{C-x C-s} in vi mode, but
584 the idea here is that you can execute useful Emacs commands without typing
585 control characters. For example, if you hit @kbd{X} (or @kbd{C-x}) followed
586 by @kbd{2}, then the current window will be split into 2 and you will be in
587 vi mode again.
588 @end table
589
590 In addition to these, @code{ctl-x-map} is slightly modified:
591
592 @kindex 1301 @kbd{X 3} (@code{vip-buffer-in-two-windows})
593
594 @table @kbd
595 @item X 3
596 @itemx C-x 3
597 This is equivalent to @kbd{C-x 1 C-x 2} (1 + 2 = 3).
598 @end table
599
600 @node Window Commands
601 @subsection Window Commands
602
603 In this and following subsections, we give a summary of key bindings for
604 basic functions related to windows, buffers and files.
605
606 @table @kbd
607 @item C-n
608 @kindex 016 @kbd{C-n} (@code{vip-next-window})
609 Switch to next window.
610 @item X 1
611 @itemx C-x 1
612 @kindex 1301 @kbd{X 1} (@code{delete-other-windows})
613 Delete other windows.
614 @item X 2
615 @itemx C-x 2
616 @kindex 1301 @kbd{X 2} (@code{split-window-vertically})
617 Split current window into two windows.
618 @item X 3
619 @itemx C-x 3
620 @kindex 1301 @kbd{X 3} (@code{vip-buffer-in-two-windows})
621 Show current buffer in two windows.
622 @end table
623
624 @node Buffer Commands
625 @subsection Buffer Commands
626
627 @table @kbd
628 @item s
629 @kindex 163 @kbd{s} (@code{vip-switch-to-buffer})
630 Switch to the specified buffer in the current window
631 (@code{vip-switch-to-buffer}).
632 @item S
633 @kindex 123 @kbd{S} (@code{vip-switch-to-buffer-other-window})
634 Switch to the specified buffer in another window
635 (@code{vip-switch-to-buffer-other-window}).
636 @item K
637 @kindex 113 @kbd{K} (@code{vip-kill-buffer})
638 Kill the current buffer if it is not modified.
639 @item X S
640 @itemx C-x C-s
641 @kindex 1302 @kbd{X S} (@code{save-buffer})
642 Save the current buffer in the file associated to the buffer.
643 @end table
644
645 @node File Commands
646 @subsection File Commands
647
648 @table @kbd
649 @item v
650 @kindex 166 @kbd{v} (@code{vip-find-file})
651 Visit specified file in the current window.
652 @item V
653 @kindex 126 @kbd{V} (@code{vip-find-file-other-window})
654 Visit specified file in another window.
655 @item X W
656 @itemx C-x C-w
657 @kindex 1302 @kbd{X W} (@code{write-file})
658 Write current buffer into the specified file.
659 @item X I
660 @itemx C-x C-i
661 @kindex 1302 @kbd{X I} (@code{insert-file})
662
663 Insert specified file at point.
664 @end table
665
666 @node Misc Commands
667 @subsection Miscellaneous Commands
668
669 @table @kbd
670 @item X (
671 @itemx C-x (
672 @kindex 1301 @kbd{X (} (@code{start-kbd-macro})
673 Start remembering keyboard macro.
674 @item X )
675 @itemx C-x )
676 @kindex 1301 @kbd{X )} (@code{end-kbd-macro})
677 Finish remembering keyboard macro.
678 @item *
679 @kindex 052 @kbd{*} (@code{vip-call-last-kbd-macro})
680 Call last remembered keyboard macro.
681 @item X Z
682 @itemx C-x C-z
683 @kindex 1302 @kbd{X Z} (@code{suspend-emacs})
684 Suspend Emacs.
685 @item Z Z
686 Exit Emacs.
687 @item Q
688 Query replace.
689 @item R
690 Replace.
691 @end table
692
693 @node Vi Commands
694 @chapter Vi Commands
695
696 This chapter describes Vi commands other than Ex commands implemented in
697 VIP@. Except for the last section which discusses insert mode, all the
698 commands described in this chapter are to be used in vi mode.
699
700 @menu
701 * Numeric Arguments:: Many commands accept numeric arguments
702 * Important Keys:: Some very important keys.
703 * Buffers and Windows:: Commands for handling buffers and windows.
704 * Files:: Commands for handling files.
705 * Viewing the Buffer:: How you can view the current buffer.
706 * Mark Commands:: Marking positions in a buffer.
707 * Motion Commands:: Commands for moving point.
708 * Searching and Replacing:: Commands for searching and replacing.
709 * Modifying Commands:: Commands for modifying the buffer.
710 * Other Vi Commands:: Miscellaneous Commands.
711 * Commands in Insert Mode:: Commands for entering insert mode.
712 @end menu
713
714 @node Numeric Arguments
715 @section Numeric Arguments
716
717 @cindex numeric arguments
718 @cindex count
719 @kindex 061 @kbd{1} (numeric argument)
720 @kindex 062 @kbd{2} (numeric argument)
721 @kindex 063 @kbd{3} (numeric argument)
722 @kindex 064 @kbd{4} (numeric argument)
723 @kindex 065 @kbd{5} (numeric argument)
724 @kindex 066 @kbd{6} (numeric argument)
725 @kindex 067 @kbd{7} (numeric argument)
726 @kindex 068 @kbd{8} (numeric argument)
727 @kindex 069 @kbd{9} (numeric argument)
728
729 Most Vi commands accept a @dfn{numeric argument} which can be supplied as
730 a prefix to the commands. A numeric argument is also called a @dfn{count}.
731 In many cases, if a count is given, the command is executed that many times.
732 For instance, @kbd{5 d d} deletes 5 lines while simple @kbd{d d} deletes a
733 line. In this manual the metavariable @var{n} will denote a count.
734
735 @node Important Keys
736 @section Important Keys
737
738 The keys @kbd{C-g} and @kbd{C-l} are unique in that their associated
739 functions are the same in any of emacs, vi and insert mode.
740
741 @table @kbd
742 @item C-g
743 @kindex 007 @kbd{C-g} (@code{vip-keyboard-quit})
744 Quit. Cancel running or partially typed command (@code{keyboard-quit}).
745 @item C-l
746 @kindex 014 @kbd{C-l} (@code{recenter})
747 Clear the screen and reprint everything (@code{recenter}).
748 @end table
749
750 In Emacs many commands are bound to the key strokes that start with
751 @kbd{C-x}, @kbd{C-c} and @key{ESC}. These commands can be
752 accessed from vi mode as easily as from emacs mode.
753
754 @table @kbd
755 @item C-x
756 @itemx C-c
757 @itemx @key{ESC}
758 @kindex 003 @kbd{C-c} (@code{vip-ctl-c})
759 @kindex 0300 @kbd{C-x} (@code{vip-ctl-x})
760 @kindex 033 @kbd{ESC} (@code{vip-ESC})
761 Typing one of these keys have the same effect as typing it in emacs mode.
762 Appropriate command will be executed according as the keys you type after
763 it. You will be in vi mode again after the execution of the command.
764 For instance, if you type @kbd{@key{ESC} <} (in vi mode) then the cursor will
765 move to the beginning of the buffer and you will still be in vi mode.
766 @item C
767 @itemx X
768 @kindex 103 @kbd{C} (@code{vip-ctl-c-equivalent})
769 @kindex 1300 @kbd{X} (@code{vip-ctl-x-equivalent})
770 Typing one of these keys have the effect of typing the corresponding
771 control character in emacs mode. Moreover, if you type an upper-case
772 character following it, that character will also be translated to the
773 corresponding control character. Thus typing @kbd{X W} in vi mode is the
774 same as typing @kbd{C-x C-w} in emacs mode. You will be in vi mode again
775 after the execution of a command.
776 @item \
777 @kindex 134 @kbd{\} (@code{vip-escape-to-emacs})
778 Escape to emacs mode. Hitting the @kbd{\} key will take you to emacs mode,
779 and you can execute a single Emacs command. After executing the
780 Emacs command you will be in vi mode again. You can give a count before
781 typing @kbd{\}. Thus @kbd{5 \ +}, as well as @kbd{\ C-u 5 +}, will insert
782 @samp{+++++} before point.
783 @end table
784
785 @node Buffers and Windows
786 @section Buffers and Windows
787
788 @cindex buffer
789 @cindex selected buffer
790 @cindex current buffer
791
792 In Emacs the text you edit is stored in a @dfn{buffer}.
793 See GNU Emacs Manual, for details. There is always one @dfn{current}
794 buffer, also called the @dfn{selected buffer}.
795
796 @cindex window
797 @cindex modified (buffer)
798
799 You can see the contents of buffers through @dfn{windows} created by Emacs.
800 When you have multiple windows on the screen only one of them is selected.
801 Each buffer has a unique name, and each window has a mode line which shows
802 the name of the buffer associated with the window and other information
803 about the status of the buffer. You can change the format of the mode
804 line, but normally if you see @samp{**} at the beginning of a mode line it
805 means that the buffer is @dfn{modified}. If you write out the content of
806 the buffer to a file, then the buffer will become not modified. Also if
807 you see @samp{%%} at the beginning of the mode line, it means that the file
808 associated with the buffer is write protected.
809
810 We have the following commands related to windows and buffers.
811
812 @table @kbd
813 @item C-n
814 @kindex 016 @kbd{C-n} (@code{vip-next-window})
815 Move cursor to the next-window (@code{vip-next-window}).
816 @item X 1
817 @kindex 1301 @kbd{X 1} (@code{delete-other-windows})
818 Delete other windows and make the selected window fill the screen
819 @*(@code{delete-other-windows}).
820 @item X 2
821 @kindex 1301 @kbd{X 2} (@code{split-window-vertically})
822 Split current window into two windows (@code{split-window-vertically}).
823 @item X 3
824 @kindex 1301 @kbd{X 3} (@code{vip-buffer-in-two-windows})
825 Show current buffer in two windows.
826 @item s @var{buffer} @key{RET}
827 @kindex 163 @kbd{s} (@code{vip-switch-to-buffer})
828 Select or create a buffer named @var{buffer} (@code{vip-switch-to-buffer}).
829 @item S @var{buffer} @key{RET}
830 @kindex 123 @kbd{S} (@code{vip-switch-to-buffer-other-window})
831 Similar but select a buffer named @var{buffer} in another window
832 @*(@code{vip-switch-to-buffer-other-window}).
833 @item K
834 @kindex 113 @kbd{K} (@code{vip-kill-buffer})
835 Kill the current buffer if it is not modified or if it is not associated
836 with a file @*(@code{vip-kill-buffer}).
837 @item X B
838 @kindex 1302 @kbd{X B} (@code{list-buffers})
839 List the existing buffers (@code{list-buffers}).
840 @end table
841
842 @cindex buffer name completion
843
844 As @dfn{buffer name completion} is provided, you have only to type in
845 initial substring of the buffer name which is sufficient to identify it
846 among names of existing buffers. After that, if you hit @key{TAB} the rest
847 of the buffer name will be supplied by the system, and you can confirm it
848 by @key{RET}. The default buffer name to switch to will also be prompted,
849 and you can select it by giving a simple @key{RET}. See GNU Emacs Manual
850 for details of completion.
851
852 @node Files
853 @section Files
854
855 We have the following commands related to files. They are used to visit,
856 save and insert files.
857
858 @table @kbd
859 @item v @var{file} @key{RET}
860 @kindex 166 @kbd{v} (@code{vip-find-file})
861 Visit specified file in the current window (@code{vip-find-file}).
862 @item V @var{file} @key{RET}
863 @kindex 126 @kbd{V} (@code{vip-find-file-other-window})
864 Visit specified file in another window (@code{vip-find-file-other-window}).
865 @item X S
866 @kindex 1302 @kbd{X S} (@code{save-buffer})
867 Save current buffer to the file associated with the buffer. If no file is
868 associated with the buffer, the name of the file to write out the content
869 of the buffer will be asked in the minibuffer.
870 @item X W @var{file} @key{RET}
871 @kindex 1302 @kbd{X W} (@code{write-file})
872 Write current buffer into a specified file.
873 @item X I @var{file} @key{RET}
874 @kindex 1302 @kbd{X I} (@code{insert-file})
875 Insert a specified file at point.
876 @item g
877 @kindex 147 @kbd{g} (@code{vip-info-on-file})
878 Give information on the file associated with the current buffer. Tell you
879 the name of the file associated with the buffer, the line number of the
880 current point and total line numbers in the buffer. If no file is
881 associated with the buffer, this fact will be indicated by the null file
882 name @samp{""}.
883 @end table
884
885 @cindex visiting (a file)
886 @cindex default directory
887
888 In Emacs, you can edit a file by @dfn{visiting} it. If you wish to visit a
889 file in the current window, you can just type @kbd{v}. Emacs maintains the
890 @dfn{default directory} which is specific to each buffer. Suppose, for
891 instance, that the default directory of the current buffer is
892 @file{/usr/masahiko/lisp/}. Then you will get the following prompt in the
893 minibuffer.
894 @example
895 visit file: /usr/masahiko/lisp/
896 @end example
897 @noindent
898 @cindex file name completion
899 If you wish to visit, say, @file{vip.el} in this directory, then you can
900 just type @samp{vip.el} followed by @key{RET}. If the file @file{vip.el}
901 already exists in the directory, Emacs will visit that file, and if not,
902 the file will be created. Emacs will use the file name (@file{vip.el}, in
903 this case) as the name of the buffer visiting the file. In order to make
904 the buffer name unique, Emacs may add a suffix (@pxref{Uniquify,,,
905 emacs, The GNU Emacs Manual}). As @dfn{file name completion} is provided here, you
906 can sometimes save typing. For instance, suppose there is only one file in the
907 default directory whose name starts with @samp{v}, that is @samp{vip.el}.
908 Then if you just type @kbd{v @key{TAB}} then it will be completed to
909 @samp{vip.el}. Thus, in this case, you just have to type @kbd{v v @key{TAB}
910 @key{RET}} to visit @file{/usr/masahiko/lisp/vip.el}. Continuing the
911 example, let us now suppose that you wished to visit the file
912 @file{/usr/masahiko/man/vip.texinfo}. Then to the same prompt which you get
913 after you typed @kbd{v}, you can enter @samp{/usr/masahiko/man/vip.texinfo} or
914 @samp{../man/vip.texinfo} followed by @key{RET}.
915
916 Use @kbd{V} instead of @kbd{v}, if you wish to visit a file in another
917 window.
918
919 You can verify which file you are editing by typing @kbd{g}. (You can also
920 type @kbd{X B} to get information on other buffers too.) If you type
921 @kbd{g} you will get an information like below in the echo area:
922 @example
923 "/usr/masahiko/man/vip.texinfo" line 921 of 1949
924 @end example
925
926 After you edited the buffer (@samp{vip.texinfo}, in our example) for a while,
927 you may wish to save it in a file. If you wish to save it in the file
928 associated with the buffer (@file{/usr/masahiko/man/vip.texinfo}, in this
929 case), you can just say @kbd{X S}. If you wish to save it in another file,
930 you can type @kbd{X W}. You will then get a similar prompt as you get for
931 @kbd{v}, to which you can enter the file name.
932
933 @node Viewing the Buffer
934 @section Viewing the Buffer
935
936 In this and next section we discuss commands for moving around in the
937 buffer. These command do not change the content of the buffer. The
938 following commands are useful for viewing the content of the current
939 buffer.
940
941 @table @kbd
942 @item @key{SPC}
943 @itemx C-f
944 @kindex 040 @kbd{SPC} (@code{vip-scroll})
945 @kindex 006 @kbd{C-f} (@code{vip-scroll-back})
946 Scroll text of current window upward almost full screen. You can go
947 @i{forward} in the buffer by this command (@code{vip-scroll}).
948 @item @key{RET}
949 @itemx C-b
950 @kindex 015 @kbd{RET} (@code{vip-scroll-back})
951 @kindex 002 @kbd{C-b} (@code{vip-scroll-back})
952 Scroll text of current window downward almost full screen. You can go
953 @i{backward} in the buffer by this command (@code{vip-scroll-back}).
954 @item C-d
955 @kindex 004 @kbd{C-d} (@code{vip-scroll-up})
956 Scroll text of current window upward half screen. You can go
957 @i{down} in the buffer by this command (@code{vip-scroll-down}).
958 @item C-u
959 @kindex 025 @kbd{C-u} (@code{vip-scroll-down})
960 Scroll text of current window downward half screen. You can go
961 @i{up} in the buffer by this command (@code{vip-scroll-up}).
962 @item C-y
963 @kindex 031 @kbd{C-y} (@code{vip-scroll-down-one})
964 Scroll text of current window upward by one line (@code{vip-scroll-down-one}).
965 @item C-e
966 @kindex 005 @kbd{C-e} (@code{vip-scroll-up-one})
967 Scroll text of current window downward by one line (@code{vip-scroll-up-one}).
968 @end table
969 @noindent
970 You can repeat these commands by giving a count. Thus, @kbd{2 @key{SPC}}
971 has the same effect as @kbd{@key{SPC} @key{SPC}}.
972
973 The following commands reposition point in the window.
974
975 @table @kbd
976 @item z H
977 @itemx z @key{RET}
978 @kindex 1723 @kbd{z H} (@code{vip-line-to-top})
979 @kindex 1721 @kbd{z RET} (@code{vip-line-to-top})
980 Put point on the top (@i{home}) line in the window. So the current line
981 becomes the top line in the window. Given a count @var{n}, point will be
982 placed in the @var{n}-th line from top (@code{vip-line-to-top}).
983 @item z M
984 @itemx z .
985 @kindex 1723 @kbd{z M} (@code{vip-line-to-middle})
986 @kindex 1722 @kbd{z .} (@code{vip-line-to-middle})
987 Put point on the @i{middle} line in the window. Given a count @var{n},
988 point will be placed in the @var{n}-th line from the middle line
989 (@code{vip-line-to-middle}).
990 @item z L
991 @itemx z -
992 @kindex 1723 @kbd{z L} (@code{vip-line-to-bottom})
993 @kindex 1722 @kbd{z -} (@code{vip-line-to-bottom})
994 Put point on the @i{bottom} line in the window. Given a count @var{n},
995 point will be placed in the @var{n}-th line from bottom
996 (@code{vip-line-to-bottom}).
997 @item C-l
998 Center point in window and redisplay screen (@code{recenter}).
999 @end table
1000
1001 @node Mark Commands
1002 @section Mark Commands
1003
1004 The following commands are used to mark positions in the buffer.
1005
1006 @table @kbd
1007 @item m @var{ch}
1008 @kindex 155 @kbd{m} (@code{vip-mark-point})
1009 Store current point in the register @var{ch}. @var{ch} must be a
1010 lower-case @acronym{ASCII} letter.
1011 @item m <
1012 Set mark at the beginning of current buffer.
1013 @item m >
1014 Set mark at the end of current buffer.
1015 @item m .
1016 Set mark at point.
1017 @item m ,
1018 Jump to mark (and pop mark off the mark ring).
1019 @end table
1020
1021 @cindex mark ring
1022
1023 Emacs uses the @dfn{mark ring} to store marked positions. The commands
1024 @kbd{m <}, @kbd{m >} and @kbd{m .}@: not only set mark but also add it as the
1025 latest element of the mark ring (replacing the oldest one). By repeating
1026 the command `@kbd{m ,}' you can visit older and older marked positions. You
1027 will eventually be in a loop as the mark ring is a ring.
1028
1029 @node Motion Commands
1030 @section Motion Commands
1031
1032 Commands for moving around in the current buffer are collected here. These
1033 commands are used as an `argument' for the delete, change and yank commands
1034 to be described in the next section.
1035
1036 @table @kbd
1037 @item h
1038 @kindex 150 @kbd{h} (@code{vip-backward-char})
1039 Move point backward by one character. Signal error if point is at the
1040 beginning of buffer, but (unlike Vi) do not complain otherwise
1041 (@code{vip-backward-char}).
1042 @item l
1043 @kindex 154 @kbd{l} (@code{vip-forward-char})
1044 Move point backward by one character. Signal error if point is at the
1045 end of buffer, but (unlike Vi) do not complain otherwise
1046 (@code{vip-forward-char}).
1047 @item j
1048 @kindex 152 @kbd{j} (@code{vip-next-line})
1049 Move point to the next line keeping the current column. If point is on the
1050 last line of the buffer, a new line will be created and point will move to
1051 that line (@code{vip-next-line}).
1052 @item k
1053 @kindex 153 @kbd{k} (@code{vip-previous-line})
1054 Move point to the previous line keeping the current column
1055 (@code{vip-next-line}).
1056 @item +
1057 @kindex 053 @kbd{+} (@code{vip-next-line-at-bol})
1058 Move point to the next line at the first non-white character. If point is
1059 on the last line of the buffer, a new line will be created and point will
1060 move to the beginning of that line (@code{vip-next-line-at-bol}).
1061 @item -
1062 @kindex 055 @kbd{-} (@code{vip-previous-line-at-bol})
1063 Move point to the previous line at the first non-white character
1064 (@code{vip-previous-line-at-bol}).
1065 @end table
1066 @noindent
1067 If a count is given to these commands, the commands will be repeated that
1068 many times.
1069
1070 @table @kbd
1071 @item 0
1072 @kindex 060 @kbd{0} (@code{vip-beginning-of-line})
1073 Move point to the beginning of line (@code{vip-beginning-of-line}).
1074 @item ^
1075 @kindex 136 @kbd{^} (@code{vip-bol-and-skip-white})
1076 Move point to the first non-white character on the line
1077 (@code{vip-bol-and-skip-white}).
1078 @item $
1079 @kindex 044 @kbd{$} (@code{vip-goto-eol})
1080 Move point to the end of line (@code{vip-goto-eol}).
1081 @item @var{n} |
1082 @kindex 174 @kbd{|} (@code{vip-goto-col})
1083 Move point to the @var{n}-th column on the line (@code{vip-goto-col}).
1084 @end table
1085 @noindent
1086 Except for the @kbd{|} command, these commands neglect a count.
1087
1088 @cindex word
1089
1090 @table @kbd
1091 @item w
1092 @kindex 167 @kbd{w} (@code{vip-forward-word})
1093 Move point forward to the beginning of the next word
1094 (@code{vip-forward-word}).
1095 @item W
1096 @kindex 127 @kbd{W} (@code{vip-forward-Word})
1097 Move point forward to the beginning of the next word, where a @dfn{word} is
1098 considered as a sequence of non-white characters (@code{vip-forward-Word}).
1099 @item b
1100 @kindex 142 @kbd{b} (@code{vip-backward-word})
1101 Move point backward to the beginning of a word (@code{vip-backward-word}).
1102 @item B
1103 @kindex 102 @kbd{B} (@code{vip-backward-Word})
1104 Move point backward to the beginning of a word, where a @i{word} is
1105 considered as a sequence of non-white characters (@code{vip-forward-Word}).
1106 @item e
1107 @kindex 145 @kbd{e} (@code{vip-end-of-word})
1108 Move point forward to the end of a word (@code{vip-end-of-word}).
1109 @item E
1110 @kindex 105 @kbd{E} (@code{vip-end-of-Word})
1111 Move point forward to the end of a word, where a @i{word} is
1112 considered as a sequence of non-white characters (@code{vip-end-of-Word}).
1113 @end table
1114 @noindent
1115 @cindex syntax table
1116 Here the meaning of the word `word' for the @kbd{w}, @kbd{b} and @kbd{e}
1117 commands is determined by the @dfn{syntax table} effective in the current
1118 buffer. Each major mode has its syntax mode, and therefore the meaning of
1119 a word also changes as the major mode changes. See GNU Emacs Manual for
1120 details of syntax table.
1121
1122 @table @kbd
1123 @item H
1124 @kindex 110 @kbd{H} (@code{vip-window-top})
1125 Move point to the beginning of the @i{home} (top) line of the window.
1126 Given a count @var{n}, go to the @var{n}-th line from top
1127 (@code{vip-window-top}).
1128 @item M
1129 @kindex 115 @kbd{M} (@code{vip-window-middle})
1130 Move point to the beginning of the @i{middle} line of the window. Given
1131 a count @var{n}, go to the @var{n}-th line from the middle line
1132 (@code{vip-window-middle}).
1133 @item L
1134 @kindex 114 @kbd{L} (@code{vip-window-bottom})
1135 Move point to the beginning of the @i{lowest} (bottom) line of the
1136 window. Given count, go to the @var{n}-th line from bottom
1137 (@code{vip-window-bottom}).
1138 @end table
1139 @noindent
1140 These commands can be used to go to the desired line visible on the screen.
1141
1142 @table @kbd
1143 @item (
1144 @kindex 050 @kbd{(} (@code{vip-backward-sentence})
1145 Move point backward to the beginning of the sentence
1146 (@code{vip-backward-sentence}).
1147 @item )
1148 @kindex 051 @kbd{)} (@code{vip-forward-sentence})
1149 Move point forward to the end of the sentence
1150 (@code{vip-forward-sentence}).
1151 @item @{
1152 @kindex 173 @kbd{@{} (@code{vip-backward-paragraph})
1153 Move point backward to the beginning of the paragraph
1154 (@code{vip-backward-paragraph}).
1155 @item @}
1156 @kindex 175 @kbd{@}} (@code{vip-forward-paragraph})
1157 Move point forward to the end of the paragraph
1158 (@code{vip-forward-paragraph}).
1159 @end table
1160 @noindent
1161 A count repeats the effect for these commands.
1162
1163 @table @kbd
1164 @item G
1165 @kindex 107 @kbd{G} (@code{vip-goto-line})
1166 Given a count @var{n}, move point to the @var{n}-th line in the buffer on
1167 the first non-white character. Without a count, go to the end of the buffer
1168 (@code{vip-goto-line}).
1169 @item ` `
1170 @kindex 140 @kbd{`} (@code{vip-goto-mark})
1171 Exchange point and mark (@code{vip-goto-mark}).
1172 @item ` @var{ch}
1173 Move point to the position stored in the register @var{ch}. @var{ch} must
1174 be a lower-case letter.
1175 @item ' '
1176 @kindex 047 @kbd{'} (@code{vip-goto-mark-and-skip-white})
1177 Exchange point and mark, and then move point to the first non-white
1178 character on the line (@code{vip-goto-mark-and-skip-white}).
1179 @item ' @var{ch}
1180 Move point to the position stored in the register @var{ch} and skip to the
1181 first non-white character on the line. @var{ch} must be a lower-case letter.
1182 @item %
1183 @kindex 045 @kbd{%} (@code{vip-paren-match})
1184 Move point to the matching parenthesis if point is looking at @kbd{(},
1185 @kbd{)}, @kbd{@{}, @kbd{@}}, @kbd{[} or @kbd{]}
1186 @*(@code{vip-paren-match}).
1187 @end table
1188 @noindent
1189 The command @kbd{G} mark point before move, so that you can return to the
1190 original point by @kbd{` `}. The original point will also be stored in
1191 the mark ring.
1192
1193 The following commands are useful for moving points on the line. A count
1194 will repeat the effect.
1195
1196 @table @kbd
1197 @item f @var{ch}
1198 @kindex 146 @kbd{f} (@code{vip-find-char-forward})
1199 Move point forward to the character @var{ch} on the line. Signal error if
1200 @var{ch} could not be found (@code{vip-find-char-forward}).
1201 @item F @var{ch}
1202 @kindex 106 @kbd{F} (@code{vip-find-char-backward})
1203 Move point backward to the character @var{ch} on the line. Signal error if
1204 @var{ch} could not be found (@code{vip-find-char-backward}).
1205 @item t @var{ch}
1206 @kindex 164 @kbd{t} (@code{vip-goto-char-forward})
1207 Move point forward upto the character @var{ch} on the line. Signal error if
1208 @var{ch} could not be found (@code{vip-goto-char-forward}).
1209 @item T @var{ch}
1210 @kindex 124 @kbd{T} (@code{vip-goto-char-backward})
1211 Move point backward upto the character @var{ch} on the line. Signal error if
1212 @var{ch} could not be found (@code{vip-goto-char-backward}).
1213 @item ;
1214 @kindex 073 @kbd{;} (@code{vip-repeat-find})
1215 Repeat previous @kbd{f}, @kbd{t}, @kbd{F} or @kbd{T} command
1216 (@code{vip-repeat-find}).
1217 @item ,
1218 @kindex 054 @kbd{,} (@code{vip-repeat-find-opposite})
1219 Repeat previous @kbd{f}, @kbd{t}, @kbd{F} or @kbd{T} command, in the
1220 opposite direction (@code{vip-repeat-find-opposite}).
1221 @end table
1222
1223 @node Searching and Replacing
1224 @section Searching and Replacing
1225
1226 Following commands are available for searching and replacing.
1227
1228 @cindex regular expression (search)
1229
1230 @table @kbd
1231 @item / @var{string} @key{RET}
1232 @kindex 057 @kbd{/} (@code{vip-search-forward})
1233 Search the first occurrence of the string @var{string} forward starting
1234 from point. Given a count @var{n}, the @var{n}-th occurrence of
1235 @var{string} will be searched. If the variable @code{vip-re-search} has value
1236 @code{t} then @dfn{regular expression} search is done and the string
1237 matching the regular expression @var{string} is found. If you give an
1238 empty string as @var{string} then the search mode will change from vanilla
1239 search to regular expression search and vice versa
1240 (@code{vip-search-forward}).
1241 @item ? @var{string} @key{RET}
1242 @kindex 077 @kbd{?} (@code{vip-search-backward})
1243 Same as @kbd{/}, except that search is done backward
1244 (@code{vip-search-backward}).
1245 @item n
1246 @kindex 156 @kbd{n} (@code{vip-search-next})
1247 Search the previous search pattern in the same direction as before
1248 (@code{vip-search-next}).
1249 @item N
1250 @kindex 116 @kbd{N} (@code{vip-search-Next})
1251 Search the previous search pattern in the opposite direction
1252 (@code{vip-search-Next}).
1253 @item C-s
1254 @kindex 023 @kbd{C-s} (@code{isearch-forward})
1255 Search forward incrementally. See GNU Emacs Manual for details
1256 (@code{isearch-forward}).
1257 @item C-r
1258 @kindex 022 @kbd{C-r} (@code{isearch-backward})
1259 Search backward incrementally (@code{isearch-backward}).
1260 @cindex vanilla (replacement)
1261 @cindex regular expression (replacement)
1262 @item R @var{string} RET @var{newstring}
1263 @kindex 122 @kbd{R} (@code{vip-replace-string})
1264 There are two modes of replacement, @dfn{vanilla} and @dfn{regular expression}.
1265 If the mode is @i{vanilla} you will get a prompt @samp{Replace string:},
1266 and if the mode is @i{regular expression} you will ge a prompt
1267 @samp{Replace regexp:}. The mode is initially @i{vanilla}, but you can
1268 toggle these modes by giving a null string as @var{string}. If the mode is
1269 vanilla, this command replaces every occurrence of @var{string} with
1270 @var{newstring}. If the mode is regular expression, @var{string} is
1271 treated as a regular expression and every string matching the regular
1272 expression is replaced with @var{newstring} (@code{vip-replace-string}).
1273 @item Q @var{string} RET @var{newstring}
1274 @kindex 121 @kbd{Q} (@code{vip-query-replace})
1275 Same as @kbd{R} except that you will be asked form confirmation before each
1276 replacement
1277 @*(@code{vip-query-replace}).
1278 @item r @var{ch}
1279 @kindex 162 @kbd{r} (@code{vip-replace-char})
1280 Replace the character point is looking at by the character @var{ch}. Give
1281 count, replace that many characters by @var{ch} (@code{vip-replace-char}).
1282 @end table
1283 @noindent
1284 The commands @kbd{/} and @kbd{?} mark point before move, so that you can
1285 return to the original point by @w{@kbd{` `}}.
1286
1287 @node Modifying Commands
1288 @section Modifying Commands
1289
1290 In this section, commands for modifying the content of a buffer are
1291 described. These commands affect the region determined by a motion command
1292 which is given to the commands as their argument.
1293
1294 @cindex point commands
1295 @cindex line commands
1296
1297 We classify motion commands into @dfn{point commands} and
1298 @dfn{line commands}. The point commands are as follows:
1299 @example
1300 @kbd{h}, @kbd{l}, @kbd{0}, @kbd{^}, @kbd{$}, @kbd{w}, @kbd{W}, @kbd{b}, @kbd{B}, @kbd{e}, @kbd{E}, @kbd{(}, @kbd{)}, @kbd{/}, @kbd{?}, @kbd{`}, @kbd{f}, @kbd{F}, @kbd{t}, @kbd{T}, @kbd{%}, @kbd{;}, @kbd{,}
1301 @end example
1302 @noindent
1303 The line commands are as follows:
1304 @example
1305 @kbd{j}, @kbd{k}, @kbd{+}, @kbd{-}, @kbd{H}, @kbd{M}, @kbd{L}, @kbd{@{}, @kbd{@}}, @kbd{G}, @kbd{'}
1306 @end example
1307 @noindent
1308 @cindex expanding (region)
1309 If a point command is given as an argument to a modifying command, the
1310 region determined by the point command will be affected by the modifying
1311 command. On the other hand, if a line command is given as an argument to a
1312 modifying command, the region determined by the line command will be
1313 enlarged so that it will become the smallest region properly containing the
1314 region and consisting of whole lines (we call this process @dfn{expanding
1315 the region}), and then the enlarged region will be affected by the modifying
1316 command.
1317
1318 @menu
1319 * Delete Commands:: Commands for deleting text.
1320 * Yank Commands:: Commands for yanking text in Vi's sense.
1321 * Put Back Commands:: Commands for putting back deleted/yanked text.
1322 * Change Commands:: Commands for changing text.
1323 * Repeating and Undoing Modifications::
1324 @end menu
1325 @node Delete Commands
1326 @subsection Delete Commands
1327
1328 @table @kbd
1329 @item d @var{motion-command}
1330 @kindex 1440 @kbd{d} (@code{vip-command-argument})
1331 Delete the region determined by the motion command @var{motion-command}.
1332 @end table
1333 @noindent
1334 For example, @kbd{d $} will delete the region between point and end of
1335 current line since @kbd{$} is a point command that moves point to end of line.
1336 @kbd{d G} will delete the region between the beginning of current line and
1337 end of the buffer, since @kbd{G} is a line command. A count given to the
1338 command above will become the count for the associated motion command.
1339 Thus, @kbd{3 d w} will delete three words.
1340
1341 @kindex 042 @kbd{"} (@code{vip-command-argument})
1342 It is also possible to save the deleted text into a register you specify.
1343 For example, you can say @kbd{" t 3 d w} to delete three words and save it
1344 to register @kbd{t}. The name of a register is a lower-case letter between
1345 @kbd{a} and @kbd{z}. If you give an upper-case letter as an argument to
1346 a delete command, then the deleted text will be appended to the content of
1347 the register having the corresponding lower-case letter as its name. So,
1348 @kbd{" T d w} will delete a word and append it to register @kbd{t}. Other
1349 modifying commands also accept a register name as their argument, and we
1350 will not repeat similar explanations.
1351
1352 We have more delete commands as below.
1353
1354 @table @kbd
1355 @item d d
1356 @kindex 1442 @kbd{d d}
1357 Delete a line. Given a count @var{n}, delete @var{n} lines.
1358 @item d r
1359 @kindex 1442 @kbd{d r}
1360 Delete current region.
1361 @item d R
1362 @kindex 1441 @kbd{d R}
1363 Expand current region and delete it.
1364 @item D
1365 @kindex 104 @kbd{D} (@code{vip-kill-line})
1366 Delete to the end of a line (@code{vip-kill-line}).
1367 @item x
1368 @kindex 170 @kbd{x} (@code{vip-delete-char})
1369 Delete a character after point. Given @var{n}, delete @var{n} characters
1370 (@code{vip-delete-char}).
1371 @item @key{DEL}
1372 @kindex 177 @kbd{DEL} (@code{vip-delete-backward-char})
1373 Delete a character before point. Given @var{n}, delete @var{n} characters
1374 (@code{vip-delete-backward-char}).
1375 @end table
1376
1377 @node Yank Commands
1378 @subsection Yank Commands
1379
1380 @cindex yank
1381
1382 Yank commands @dfn{yank} a text of buffer into a (usually anonymous) register.
1383 Here the word `yank' is used in Vi's sense. Thus yank commands do not
1384 alter the content of the buffer, and useful only in combination with
1385 commands that put back the yanked text into the buffer.
1386
1387 @table @kbd
1388 @item y @var{motion-command}
1389 @kindex 1710 @kbd{y} (@code{vip-command-argument})
1390 Yank the region determined by the motion command @var{motion-command}.
1391 @end table
1392 @noindent
1393 For example, @kbd{y $} will yank the text between point and the end of line
1394 into an anonymous register, while @kbd{"c y $} will yank the same text into
1395 register @kbd{c}.
1396
1397 Use the following command to yank consecutive lines of text.
1398
1399 @table @kbd
1400 @item y y
1401 @itemx Y
1402 @kindex 131 @kbd{Y} (@code{vip-yank-line})
1403 @kindex 1712 @kbd{y y} (@code{vip-yank-line})
1404 Yank a line. Given @var{n}, yank @var{n} lines (@code{vip-yank-line}).
1405 @item y r
1406 @kindex 1712 @kbd{y r}
1407 Yank current region.
1408 @item y R
1409 @kindex 1711 @kbd{y R}
1410 Expand current region and yank it.
1411 @end table
1412
1413 @node Put Back Commands
1414 @subsection Put Back Commands
1415 Deleted or yanked texts can be put back into the buffer by the command
1416 below.
1417
1418 @table @kbd
1419 @item p
1420 @kindex 160 @kbd{p} (@code{vip-put-back})
1421 Insert, after the character point is looking at, most recently
1422 deleted/yanked text from anonymous register. Given a register name
1423 argument, the content of the named register will be put back. Given a
1424 count, the command will be repeated that many times. This command also
1425 checks if the text to put back ends with a new line character, and if so
1426 the text will be put below the current line (@code{vip-put-back}).
1427 @item P
1428 @kindex 120 @kbd{P} (@code{vip-Put-back})
1429 Insert at point most recently deleted/yanked text from anonymous register.
1430 Given a register name argument, the content of the named register will
1431 be put back. Given a count, the command will be repeated that many times.
1432 This command also checks if the text to put back ends with a new line
1433 character, and if so the text will be put above the current line rather
1434 than at point (@code{vip-Put-back}).
1435 @end table
1436 @noindent
1437 @cindex number register
1438 Thus, @kbd{" c p} will put back the content of the register @kbd{c} into the
1439 buffer. It is also possible to specify @dfn{number register} which is a
1440 numeral between @kbd{1} and @kbd{9}. If the number register @var{n} is
1441 specified, @var{n}-th previously deleted/yanked text will be put back. It
1442 is an error to specify a number register for the delete/yank commands.
1443
1444 @node Change Commands
1445 @subsection Change Commands
1446
1447 Most commonly used change command takes the following form.
1448
1449 @table @kbd
1450 @item c @var{motion-command}
1451 @kindex 1430 @kbd{c} (@code{vip-command-argument})
1452 Replace the content of the region determined by the motion command
1453 @var{motion-command} by the text you type. If the motion command is a
1454 point command then you will type the text into minibuffer, and if the
1455 motion command is a line command then the region will be deleted first and
1456 you can insert the text in @var{insert mode}.
1457 @end table
1458 @noindent
1459 For example, if point is at the beginning of a word @samp{foo} and you
1460 wish to change it to @samp{bar}, you can type @kbd{c w}. Then, as @kbd{w}
1461 is a point command, you will get the prompt @samp{foo =>} in the
1462 minibuffer, for which you can type @kbd{b a r @key{RET}} to complete the change
1463 command.
1464
1465 @table @kbd
1466 @item c c
1467 @kindex 1432 @kbd{c c}
1468 Change a line. Given a count, that many lines are changed.
1469 @item c r
1470 @kindex 1432 @kbd{c r}
1471 Change current region.
1472 @item c R
1473 @kindex 1431 @kbd{c R}
1474 Expand current region and change it.
1475 @end table
1476
1477 @node Repeating and Undoing Modifications
1478 @subsection Repeating and Undoing Modifications
1479
1480 VIP records the previous modifying command, so that it is easy to repeat
1481 it. It is also very easy to undo changes made by modifying commands.
1482
1483 @table @kbd
1484 @item u
1485 @kindex 165 @kbd{u} (@code{vip-undo})
1486 Undo the last change. You can undo more by repeating undo by the repeat
1487 command @samp{.}. For example, you can undo 5 previous changes by typing
1488 @samp{u....}. If you type @samp{uu}, then the second @samp{u} undoes the
1489 first undo command (@code{vip-undo}).
1490 @item .
1491 @kindex 056 @kbd{.} (@code{vip-repeat})
1492 Repeat the last modifying command. Given count @var{n} it becomes the new
1493 count for the repeated command. Otherwise, the count for the last
1494 modifying command is used again (@code{vip-repeat}).
1495 @end table
1496
1497 @node Other Vi Commands
1498 @section Other Vi Commands
1499
1500 Miscellaneous Vi commands are collected here.
1501
1502 @table @kbd
1503 @item Z Z
1504 @kindex 132 @kbd{Z Z} (@code{save-buffers-kill-emacs})
1505 Exit Emacs. If modified buffers exist, you will be asked whether you wish
1506 to save them or not (@code{save-buffers-kill-emacs}).
1507 @item !@: @var{motion-command} @var{format-command}
1508 @itemx @var{n} !@: !@: @var{format-command}
1509 @kindex 041 @kbd{!} (@code{vip-command-argument})
1510 The region determined by the motion command @var{motion-command} will be
1511 given to the shell command @var{format-command} and the region will be
1512 replaced by its output. If a count is given, it will be passed to
1513 @var{motion-command}. For example, @samp{3!Gsort} will sort the region
1514 between point and the 3rd line. If @kbd{!} is used instead of
1515 @var{motion-command} then @var{n} lines will be processed by
1516 @var{format-command} (@code{vip-command-argument}).
1517 @item J
1518 @kindex 112 @kbd{J} (@code{vip-join-lines})
1519 Join two lines. Given count, join that many lines. A space will be
1520 inserted at each junction (@code{vip-join-lines}).
1521 @item < @var{motion-command}
1522 @itemx @var{n} < <
1523 @kindex 074 @kbd{<} (@code{vip-command-argument})
1524 Shift region determined by the motion command @var{motion-command} to
1525 left by @var{shift-width} (default is 8). If @kbd{<} is used instead of
1526 @var{motion-command} then shift @var{n} lines
1527 @*(@code{vip-command-argument}).
1528 @item > @var{motion-command}
1529 @itemx @var{n} > >
1530 @kindex 076 @kbd{>} (@code{vip-command-argument})
1531 Shift region determined by the motion command @var{motion-command} to
1532 right by @var{shift-width} (default is 8). If @kbd{<} is used instead of
1533 @var{motion-command} then shift @var{n} lines
1534 @*(@code{vip-command-argument}).
1535 @item = @var{motion-command}
1536 @kindex 075 @kbd{=} (@code{vip-command-argument})
1537 Indent region determined by the motion command @var{motion-command}. If
1538 @kbd{=} is used instead of @var{motion-command} then indent @var{n} lines
1539 (@code{vip-command-argument}).
1540 @item *
1541 @kindex 052 @kbd{*} (@code{vip-call-last-kbd-macro})
1542 Call last remembered keyboard macro.
1543 @item #
1544 A new vi operator. @xref{New Commands}, for more details.
1545 @end table
1546
1547 The following keys are reserved for future extensions, and currently
1548 assigned to a function that just beeps (@code{vip-nil}).
1549
1550 @kindex 046 @kbd{&} (@code{vip-nil})
1551 @kindex 100 @kbd{@@} (@code{vip-nil})
1552 @kindex 125 @kbd{U} (@code{vip-nil})
1553 @kindex 133 @kbd{[} (@code{vip-nil})
1554 @kindex 135 @kbd{]} (@code{vip-nil})
1555 @kindex 137 @kbd{_} (@code{vip-nil})
1556 @kindex 161 @kbd{q} (@code{vip-nil})
1557 @kindex 176 @kbd{~} (@code{vip-nil})
1558
1559 @example
1560 &, @@, U, [, ], _, q, ~
1561 @end example
1562
1563 VIP uses a special local keymap to interpret key strokes you enter in vi
1564 mode. The following keys are bound to @var{nil} in the keymap. Therefore,
1565 these keys are interpreted by the global keymap of Emacs. We give below a
1566 short description of the functions bound to these keys in the global
1567 keymap. See GNU Emacs Manual for details.
1568
1569 @table @kbd
1570 @item C-@@
1571 @kindex 000 @kbd{C-@@} (@code{set-mark-command})
1572 Set mark and push previous mark on mark ring (@code{set-mark-command}).
1573 @item TAB
1574 @kindex 011 TAB (@code{indent-for-tab-command})
1575 Indent line for current major mode (@code{indent-for-tab-command}).
1576 @item C-j
1577 @kindex 012 @kbd{C-j} (@code{electric-newline-and-maybe-indent})
1578 Insert a newline, and maybe indent according to mode.
1579 @item C-k
1580 @kindex 013 @kbd{C-k} (@code{kill-line})
1581 Kill the rest of the current line; before a newline, kill the newline.
1582 With a numeric argument, kill that many lines from point. Negative arguments
1583 kill lines backward (@code{kill-line}).
1584 @item C-l
1585 @kindex 014 @kbd{C-l} (@code{recenter})
1586 Clear the screen and reprint everything (@code{recenter}).
1587 @item @var{n} C-p
1588 @kindex 020 @kbd{C-p} (@code{previous-line})
1589 Move cursor vertically up @var{n} lines (@code{previous-line}).
1590 @item C-q
1591 @kindex 021 @kbd{C-q} (@code{quoted-insert})
1592 Read next input character and insert it. Useful for inserting control
1593 characters
1594 @*(@code{quoted-insert}).
1595 @item C-r
1596 @kindex 022 @kbd{C-r} (@code{isearch-backward})
1597 Search backward incrementally (@code{isearch-backward}).
1598 @item C-s
1599 @kindex 023 @kbd{C-s} (@code{isearch-forward})
1600 Search forward incrementally (@code{isearch-forward}).
1601 @item @var{n} C-t
1602 @kindex 024 @kbd{C-t} (@code{transpose-chars})
1603 Interchange characters around point, moving forward one character. With
1604 count @var{n}, take character before point and drag it forward past @var{n}
1605 other characters. If no argument and at end of line, the previous two
1606 characters are exchanged (@code{transpose-chars}).
1607 @item @var{n} C-v
1608 @kindex 026 @kbd{C-v} (@code{scroll-up})
1609 Scroll text upward @var{n} lines. If @var{n} is not given, scroll near
1610 full screen (@code{scroll-up}).
1611 @item C-w
1612 @kindex 027 @kbd{C-w} (@code{kill-region})
1613 Kill between point and mark. The text is save in the kill ring. The
1614 command @kbd{P} or @kbd{p} can retrieve it from kill ring
1615 (@code{kill-region}).
1616 @end table
1617
1618 @node Commands in Insert Mode
1619 @section Insert Mode
1620
1621 You can enter insert mode by one of the following commands. In addition to
1622 these, you will enter insert mode if you give a change command with a line
1623 command as the motion command. Insert commands are also modifying commands
1624 and you can repeat them by the repeat command @kbd{.} (@code{vip-repeat}).
1625
1626 @table @kbd
1627 @item i
1628 @kindex 151 @kbd{i} (@code{vip-insert})
1629 Enter insert mode at point (@code{vip-insert}).
1630 @item I
1631 @kindex 111 @kbd{I} (@code{vip-Insert})
1632 Enter insert mode at the first non white character on the line
1633 (@code{vip-Insert}).
1634 @item a
1635 @kindex 141 @kbd{a} (@code{vip-append})
1636 Move point forward by one character and then enter insert mode
1637 (@code{vip-append}).
1638 @item A
1639 @kindex 101 @kbd{A} (@code{vip-Append})
1640 Enter insert mode at end of line (@code{vip-Append}).
1641 @item o
1642 @kindex 157 @kbd{o} (@code{vip-open-line})
1643 Open a new line below the current line and enter insert mode
1644 (@code{vip-open-line}).
1645 @item O
1646 @kindex 117 @kbd{O} (@code{vip-Open-line})
1647 Open a new line above the current line and enter insert mode
1648 (@code{vip-Open-line}).
1649 @item C-o
1650 @kindex 017 @kbd{C-o} (@code{vip-open-line-at-point})
1651 Insert a newline and leave point before it, and then enter insert mode
1652 @*(@code{vip-open-line-at-point}).
1653 @end table
1654
1655 Insert mode is almost like emacs mode. Only the following 4 keys behave
1656 differently from emacs mode.
1657
1658 @table @kbd
1659 @item @key{ESC}
1660 @kindex 033 @kbd{ESC} (@code{vip-change-mode-to-vi}) (insert mode)
1661 This key will take you back to vi mode (@code{vip-change-mode-to-vi}).
1662 @item C-h
1663 @kindex 010 @kbd{C-h} (@code{delete-backward-char}) (insert mode)
1664 Delete previous character (@code{delete-backward-char}).
1665 @item C-w
1666 @kindex 027 @kbd{C-w} (@code{vip-delete-backward-word}) (insert mode)
1667 Delete previous word (@code{vip-delete-backward-word}).
1668 @item C-z
1669 @kindex 032 @kbd{C-z} (@code{vip-ESC}) (insert mode)
1670 This key simulates @key{ESC} key in emacs mode. For instance, typing
1671 @kbd{C-z x} in insert mode is the same as typing @kbd{ESC x} in emacs mode
1672 (@code{vip-ESC}).
1673 @end table
1674 @noindent
1675 You can also bind @kbd{C-h} to @code{help-command} if you like.
1676 (@xref{Customizing Key Bindings}, for details.) Binding @kbd{C-h} to
1677 @code{help-command} has the effect of making the meaning of @kbd{C-h}
1678 uniform among emacs, vi and insert modes.
1679
1680 When you enter insert mode, VIP records point as the start point of
1681 insertion, and when you leave insert mode the region between point and
1682 start point is saved for later use by repeat command etc. Therefore, repeat
1683 command will not really repeat insertion if you move point by emacs
1684 commands while in insert mode.
1685
1686 @node Ex Commands
1687 @chapter Ex Commands
1688
1689 @kindex 072 @kbd{:} (@code{vip-ex})
1690
1691 In vi mode, you can execute an Ex command @var{ex-command} by typing:
1692 @example
1693 @kbd{:@: @var{ex-command} @key{RET}}
1694 @end example
1695 Every Ex command follows the following pattern:
1696 @example
1697 @var{address command} @kbd{!}@: @var{parameters count flags}
1698 @end example
1699 @noindent
1700 @cindex address
1701 where all parts are optional. For the syntax of @dfn{address}, the reader
1702 is referred to the reference manual of Ex.
1703
1704 @cindex magic
1705 @cindex regular expression
1706
1707 In the current version of VIP, searching by Ex commands is always
1708 @dfn{magic}. That is, search patterns are always treated as @dfn{regular
1709 expressions}. For example, a typical forward search would be invoked by
1710 @kbd{:/@var{pat}/}. If you wish to include @samp{/} as part of
1711 @var{pat} you must preceded it by @samp{\}. VIP strips off these @kbd{\}'s
1712 before @kbd{/} and the resulting @var{pat} becomes the actual search
1713 pattern. Emacs provides a different and richer class or regular
1714 expressions than Vi/Ex, and VIP uses Emacs's regular expressions. See GNU
1715 Emacs Manual for details of regular expressions.
1716
1717 Several Ex commands can be entered in a line by separating them by a pipe
1718 character @samp{|}.
1719
1720 @menu
1721 * Ex Command Reference:: Explain all the Ex commands available in VIP.
1722 @end menu
1723 @node Ex Command Reference
1724 @section Ex Command Reference
1725 In this section we briefly explain all the Ex commands supported by VIP@.
1726 Most Ex commands expect @var{address} as their argument, and they use
1727 default addresses if they are not explicitly given. In the following, such
1728 default addresses will be shown in parentheses.
1729
1730 Most command names can and preferably be given in abbreviated forms. In
1731 the following, optional parts of command names will be enclosed in
1732 brackets. For example, @samp{co[py]} will mean that copy command can be
1733 give as @samp{co} or @samp{cop} or @samp{copy}.
1734
1735 If @var{command} is empty, point will move to the beginning of the line
1736 specified by the @var{address}. If @var{address} is also empty, point will
1737 move to the beginning of the current line.
1738
1739 @cindex flag
1740
1741 Some commands accept @dfn{flags} which are one of @kbd{p}, @kbd{l} and
1742 @kbd{#}. If @var{flags} are given, the text affected by the commands will
1743 be displayed on a temporary window, and you will be asked to hit return to
1744 continue. In this way, you can see the text affected by the commands
1745 before the commands will be executed. If you hit @kbd{C-g} instead of
1746 @key{RET} then the commands will be aborted. Note that the meaning of
1747 @var{flags} is different in VIP from that in Vi/Ex.
1748
1749 @table @kbd
1750 @item (.,.@:) co[py] @var{addr} @var{flags}
1751 @itemx (.,.@:) t @var{addr} @var{flags}
1752 Place a copy of specified lines after @var{addr}. If @var{addr} is
1753 @kbd{0}, it will be placed before the first line.
1754 @item (.,.@:) d[elete] @var{register} @var{count} @var{flags}
1755 Delete specified lines. Text will be saved in a named @var{register} if a
1756 lower-case letter is given, and appended to a register if a capital letter is
1757 given.
1758 @item e[dit] !@: +@var{addr} @var{file}
1759 @itemx e[x] !@: +@var{addr} @var{file}
1760 @itemx vi[sual] !@: +@var{addr} @var{file}
1761 Edit a new file @var{file} in the current window. The command will abort
1762 if current buffer is modified, which you can override by giving @kbd{!}.
1763 If @kbd{+}@var{addr} is given, @var{addr} becomes the current line.
1764 @item file
1765 Give information about the current file.
1766 @item (1,$) g[lobal] !@: /@var{pat}/ @var{cmds}
1767 @itemx (1,$) v /@var{pat}/ @var{cmds}
1768 Among specified lines first mark each line which matches the regular
1769 expression @var{pat}, and then execute @var{cmds} on each marked line.
1770 If @kbd{!}@: is given, @var{cmds} will be executed on each line not matching
1771 @var{pat}. @kbd{v} is same as @kbd{g!}.
1772 @item (.,.+1) j[oin] !@: @var{count} @var{flags}
1773 Join specified lines into a line. Without @kbd{!}, a space character will
1774 be inserted at each junction.
1775 @item (.@:) k @var{ch}
1776 @itemx (.@:) mar[k] @var{ch}
1777 Mark specified line by a lower-case character @var{ch}. Then the
1778 addressing form @kbd{'}@var{ch} will refer to this line. No white space is
1779 required between @kbd{k} and @var{ch}. A white space is necessary between
1780 @kbd{mark} and @var{ch}, however.
1781 @item map @var{ch} @var{rhs}
1782 Define a macro for vi mode. After this command, the character @var{ch}
1783 will be expanded to @var{rhs} in vi mode.
1784 @item (.,.@:) m[ove] @var{addr}
1785 Move specified lines after @var{addr}.
1786 @item (.@:) pu[t] @var{register}
1787 Put back previously deleted or yanked text. If @var{register} is given,
1788 the text saved in the register will be put back; otherwise, last deleted or
1789 yanked text will be put back.
1790 @item q[uit] !
1791 Quit from Emacs. If modified buffers with associated files exist, you will
1792 be asked whether you wish to save each of them. At this point, you may
1793 choose not to quit, by hitting @kbd{C-g}. If @kbd{!}@: is given, exit from
1794 Emacs without saving modified buffers.
1795 @item (.@:) r[ead] @var{file}
1796 Read in the content of the file @var{file} after the specified line.
1797 @item (.@:) r[ead] !@: @var{command}
1798 Read in the output of the shell command @var{command} after the specified
1799 line.
1800 @item se[t]
1801 Set a variable's value. @xref{Customizing Constants}, for the list of variables
1802 you can set.
1803 @item sh[ell]
1804 Run a subshell in a window.
1805 @item (.,.@:) s[ubstitute] /@var{pat}/@var{repl}/ @var{options} @var{count} @var{flags}
1806 @itemx (.,.@:) & @var{options} @var{count} @var{flags}
1807 On each specified line, the first occurrence of string matching regular
1808 expression @var{pat} is replaced by replacement pattern @var{repl}. Option
1809 characters are @kbd{g} and @kbd{c}. If global option character @kbd{g}
1810 appears as part of @var{options}, all occurrences are substituted. If
1811 confirm option character @kbd{c} appears, you will be asked to give
1812 confirmation before each substitution. If @kbd{/@var{pat}/@var{repl}/} is
1813 missing, the last substitution is repeated.
1814 @item st[op]
1815 Suspend Emacs.
1816 @item ta[g] @var{tag}
1817 @cindex tag
1818 @cindex selected tags table
1819 Find first definition of @var{tag}. If no @var{tag} is given, previously
1820 given @var{tag} is used and next alternate definition is find. By default,
1821 the file @file{TAGS} in the current directory becomes the @dfn{selected tags
1822 table}. You can select another tags table by @kbd{set} command.
1823 @xref{Customizing Constants}, for details.
1824 @item und[o]
1825 Undo the last change.
1826 @item unm[ap] @var{ch}
1827 The macro expansion associated with @var{ch} is removed.
1828 @item ve[rsion]
1829 Tell the version number of VIP.
1830 @item (1,$) w[rite] !@: @var{file}
1831 Write out specified lines into file @var{file}. If no @var{file} is given,
1832 text will be written to the file associated to the current buffer. Unless
1833 @kbd{!}@: is given, if @var{file} is different from the file associated to
1834 the current buffer and if the file @var{file} exists, the command will not
1835 be executed. Unlike Ex, @var{file} becomes the file associated to the
1836 current buffer.
1837 @item (1,$) w[rite]>> @var{file}
1838 Write out specified lines at the end of file @var{file}. @var{file}
1839 becomes the file associated to the current buffer.
1840 @item (1,$) wq !@: @var{file}
1841 Same as @kbd{write} and then @kbd{quit}. If @kbd{!}@: is given, same as
1842 @kbd{write !}@: then @kbd{quit}.
1843 @item (.,.) y[ank] @var{register} @var{count}
1844 Save specified lines into register @var{register}. If no register is
1845 specified, text will be saved in an anonymous register.
1846 @item @var{addr} !@: @var{command}
1847 Execute shell command @var{command}. The output will be shown in a new
1848 window. If @var{addr} is given, specified lines will be used as standard
1849 input to @var{command}.
1850 @item ($) =
1851 Print the line number of the addressed line.
1852 @item (.,.) > @var{count} @var{flags}
1853 Shift specified lines to the right. The variable @code{vip-shift-width}
1854 (default value is 8) determines the amount of shift.
1855 @item (.,.) < @var{count} @var{flags}
1856 Shift specified lines to the left. The variable @code{vip-shift-width}
1857 (default value is 8) determines the amount of shift.
1858 @item (.,.@:) ~ @var{options} @var{count} @var{flags}
1859 Repeat the previous @kbd{substitute} command using previous search pattern
1860 as @var{pat} for matching.
1861 @end table
1862
1863 The following Ex commands are available in Vi, but not implemented in VIP.
1864 @example
1865 @kbd{abbreviate}, @kbd{list}, @kbd{next}, @kbd{print}, @kbd{preserve}, @kbd{recover}, @kbd{rewind}, @kbd{source},
1866 @kbd{unabbreviate}, @kbd{xit}, @kbd{z}
1867 @end example
1868
1869 @node Customization
1870 @chapter Customization
1871
1872 If you have a file called @file{~/.emacs.d/vip} (or @file{~/.vip}), then it
1873 will also be loaded when VIP is loaded. This file is thus useful for
1874 customizing VIP.
1875
1876 @menu
1877 * Customizing Constants:: How to change values of constants.
1878 * Customizing Key Bindings:: How to change key bindings.
1879 @end menu
1880
1881 @node Customizing Constants
1882 @section Customizing Constants
1883 An easy way to customize VIP is to change the values of constants used
1884 in VIP@. Here is the list of the constants used in VIP and their default
1885 values.
1886
1887 @table @code
1888 @item vip-shift-width 8
1889 The number of columns shifted by @kbd{>} and @kbd{<} command.
1890 @item vip-re-replace nil
1891 If @code{t} then do regexp replace, if @code{nil} then do string replace.
1892 @item vip-search-wrap-around t
1893 If @code{t}, search wraps around the buffer.
1894 @item vip-re-search nil
1895 If @code{t} then search is reg-exp search, if @code{nil} then vanilla
1896 search.
1897 @item vip-case-fold-search nil
1898 If @code{t} search ignores cases.
1899 @item vip-re-query-replace nil
1900 If @code{t} then do reg-exp replace in query replace.
1901 @item vip-open-with-indent nil
1902 If @code{t} then indent to the previous current line when open a new line
1903 by @kbd{o} or @kbd{O} command.
1904 @item vip-tags-file-name "TAGS"
1905 The name of the file used as the tags table.
1906 @item vip-help-in-insert-mode nil
1907 If @code{t} then @key{C-h} is bound to @code{help-command} in insert mode,
1908 if @code{nil} then it sis bound to @code{delete-backward-char}.
1909 @end table
1910 @noindent
1911 You can reset these constants in VIP by the Ex command @kbd{set}. Or you
1912 can include a line like this in your @file{~/.emacs.d/vip} file:
1913 @example
1914 (setq vip-case-fold-search t)
1915 @end example
1916
1917 @node Customizing Key Bindings
1918 @section Customizing Key Bindings
1919
1920 @cindex local keymap
1921
1922 VIP uses @code{vip-command-mode-map} as the @dfn{local keymap} for vi mode.
1923 For example, in vi mode, @key{SPC} is bound to the function
1924 @code{vip-scroll}. But, if you wish to make @key{SPC} and some other keys
1925 behave like Vi, you can include the following lines in your
1926 @file{~/.emacs.d/vip} file.
1927
1928 @example
1929 (define-key vip-command-mode-map "\C-g" 'vip-info-on-file)
1930 (define-key vip-command-mode-map "\C-h" 'vip-backward-char)
1931 (define-key vip-command-mode-map "\C-m" 'vip-next-line-at-bol)
1932 (define-key vip-command-mode-map " " 'vip-forward-char)
1933 (define-key vip-command-mode-map "g" 'vip-keyboard-quit)
1934 (define-key vip-command-mode-map "s" 'vip-substitute)
1935 (define-key vip-command-mode-map "C" 'vip-change-to-eol)
1936 (define-key vip-command-mode-map "R" 'vip-change-to-eol)
1937 (define-key vip-command-mode-map "S" 'vip-substitute-line)
1938 (define-key vip-command-mode-map "X" 'vip-delete-backward-char)
1939 @end example
1940
1941 @node GNU Free Documentation License
1942 @appendix GNU Free Documentation License
1943 @include doclicense.texi
1944
1945
1946 @unnumbered Key Index
1947
1948 @printindex ky
1949
1950 @unnumbered Concept Index
1951 @printindex cp
1952
1953 @bye