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