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