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