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