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