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