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