comparison man/viper-cmd.texi @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
comparison
equal deleted inserted replaced
-1:000000000000 0:376386a54a3c
1 @node Commands,,Customization,Top,Top
2 @chapter Commands
3
4 This section is a semi-automatically bowdlerized version of the Vi
5 reference created by @* @samp{maart@@cs.vu.nl} and others. It can be
6 found on the Vi archives. Very little has been changed for Viper.@refill
7
8 @menu
9 * Groundwork:: Textual Conventions and Viper basics
10 * Text Handling:: Moving, Editing, Undoing.
11 * Display:: Scrolling.
12 * File and Buffer Handling:: Editing, Writing and Quitting.
13 * Mapping:: Mapping Keys, Keyboard Macros
14 * Shell Commands:: Accessing Shell Commands, Processing Text
15 * Options:: Ex options, the @kbd{:set} commands
16 * Emacs Related Commands:: Meta Keys, Windows
17 * Mouse-bound Commands:: Search and insertion of text
18 @end menu
19
20 @node Groundwork, Text Handling, Commands, Commands
21 @comment node-name, next, previous, up
22 @section Groundwork
23
24 The VI command set is based on the idea of combining motion commands
25 with other commands. The motion command is used as a text region
26 specifier for other commands.
27 We classify motion commands into @dfn{point commands} and
28 @dfn{line commands}.@refill
29
30 @cindex point commands
31
32 The point commands are:
33
34 @quotation
35 @kbd{h}, @kbd{l}, @kbd{0}, @kbd{$}, @kbd{w}, @kbd{W}, @kbd{b}, @kbd{B},
36 @kbd{e}, @kbd{E}, @kbd{(}, @kbd{)}, @kbd{/}, @kbd{?}, @kbd{`}, @kbd{f},
37 @kbd{F}, @kbd{t}, @kbd{T}, @kbd{%}, @kbd{;}, @kbd{,}, @kbd{^}
38 @end quotation
39
40 @cindex line commands
41
42 The line commands are:
43
44 @quotation
45 @kbd{j}, @kbd{k}, @kbd{+}, @kbd{-}, @kbd{H}, @kbd{M}, @kbd{L}, @kbd{@{},
46 @kbd{@}}, @kbd{G}, @kbd{'}, @kbd{[[}, @kbd{]]}, @kbd{[]}
47 @end quotation
48 @noindent
49
50 Text Deletion Commands (@xref{Deleting Text}), Change commands
51 (@xref{Changing Text}), even Shell Commands (@xref{Shell Commands})
52 use these commands to describe a region of text to operate on.
53
54 @cindex r and R region specifiers
55
56 Viper adds two region descriptors, @kbd{r} and @kbd{R}. These describe
57 the Emacs regions (@xref{Basics}), but they are not movement commands.
58
59 The command description uses angle brackets @samp{<>} to indicate
60 metasyntactic variables, since the normal conventions of using simple
61 text can be confusing with Viper where the commands themselves are
62 characters. Watch out where @kbd{<} shift commands and @kbd{<count>} are
63 mentioned together!!!
64
65 @kindex <move>
66 @kindex <a-z>
67 @kindex <address>
68 @cindex <move>
69 @cindex <a-z>
70 @cindex <address>
71 @cindex movements
72
73 @samp{<move>} refers to the above movement commands, and @samp{<a-z>}
74 refers to registers or textmarkers from @samp{a} to @samp{z}. Note
75 that the @samp{<move>} is described by full move commands, that is to
76 say they will take counts, and otherwise behave like normal move commands.
77 @cindex Ex addresses
78 @samp{<address>} refers to Ex line addresses, which include
79
80 @table @kbd
81 @item . <No address>
82 Current line
83 @item .+n .-n
84 Add or subtract for current line
85 @item number
86 Actual line number, use @kbd{.=} to get the line number
87 @item '<a-z>
88 Textmarker
89 @item $
90 Last line
91 @item x,y
92 Where x and y are one of the above
93 @item %
94 @cindex % (Ex address)
95 For the whole file, same as (1,$).
96 @item /pat/
97 @item ?pat?
98 Next or previous line with pattern pat
99 @end table
100
101 @cindex % (Current file)
102 Note that @samp{%} is used in Ex commands to mean current file. If you
103 want a @samp{%} in your command, it must be escaped as @samp{\%}.
104 @cindex # (Previous file)
105 Similarly, @samp{#} expands to the previous file. The previous file is
106 the first file in @kbd{:args} listing. This defaults to previous window
107 in the VI sense if you have one window only.
108
109 @kindex <args>
110 @kindex <cmd>
111 @cindex <args>
112 @cindex <cmd>
113 @noindent
114 Others like @samp{<args> -- arguments}, @samp{<cmd> -- command} etc.
115 should be fairly obvious.
116
117 @noindent
118 Common characters referred to include:
119
120 @table @kbd
121 @item <sp>
122 Space
123 @item <ht>
124 Tab
125 @item <lf>
126 Linefeed
127 @item <esc>
128 Escape
129 @item <cr>
130 Return, Enter
131 @end table
132 @cindex <cr>
133 @cindex <esc>
134 @cindex <lf>
135 @cindex <ht>
136 @cindex <sp>
137
138 @cindex words
139 @cindex WORDS
140 @cindex char
141 @cindex CHAR
142
143 We also use @samp{word} for alphanumeric/non-alphanumeric words, and
144 @samp{WORD} for whitespace delimited words. @samp{char} refers to any
145 ASCII character, @samp{CHAR} to non-whitespace character.
146 Brackets @samp{[]} indicate optional parameters; @samp{<count>} also
147 optional, usually defaulting to 1. Brackets are elided for
148 @samp{<count>} to eschew obfuscation.
149
150 Viper's idea of Vi's words is slightly different from Vi. First, Viper
151 words understand Emacs symbol tables. Therefore, all symbols declared to be
152 alphanumeric in a symbol table can automatically be made part of the Viper
153 word. This is useful when, for instance, editing text containing European,
154 Cyrillic, etc., letters.
155
156 Second, Viper lets you depart from Vi's idea of a word by changing the
157 value of @code{vip-syntax-preference}. By default, this variable is set to
158 @code{'strict-vi}, which means that alphanumeric symbols are exactly as
159 in Vi.
160 However, if the value is @code{'reformed-vi} then alphanumeric
161 symbols will be those specified by the current Emacs syntax table (which
162 may be different for different major modes) plus the underscore symbol
163 @code{_}. The user can also specify the value @code{'emacs}, which would
164 make Viper use exactly the Emacs notion of word. In particular, the
165 underscore may not be part of a word. Finally, if
166 @code{vip-syntax-preference} is set to @code{'extended}, Viper words would
167 consist of characters that are classified as alphanumeric @emph{or} as
168 parts of symbols. This is convenient for writing programs and in many other
169 situations.
170
171 @vindex @code{vip-syntax-preference}
172 @cindex syntax table
173
174 @code{vip-syntax-preference} is a local variable, so it can have different
175 values for different major modes. For instance, in programming modes it can
176 have the value @code{'extended}. In text modes where words contain special
177 characters, such as European (non-English) letters, Cyrillic letters, etc.,
178 the value can be @code{'reformed-vi} or @code{'emacs}.
179
180 Changes to @code{vip-syntax-preference} should be done in the hooks to
181 various major modes. Furthermore, for these changes to take effect, you
182 should execute @code{(vip-update-alphanumeric-class)} right after changing
183 the value of @code{vip-syntax-preference}.
184
185 The above discussion concerns only the movement commands. In regular
186 expressions, words remain the same as in Emacs. That is, the expressions
187 @code{\w}, @code{\>}, @code{\<}, etc., use Emacs' idea of what is a word,
188 and they don't look into the value of variable
189 @code{vip-syntax-preference}. This is because Viper doesn't change syntax
190 tables in order to not thwart the various major modes that set these
191 tables.
192
193 The usual Emacs convention is used to indicate Control Characters, i.e
194 C-h for Control-h. @emph{Do not confuse this to mean the separate
195 characters C - h!!!} The @kbd{^} is itself, never used to indicate a
196 Control character.
197
198 @node Text Handling, Display, Groundwork, Commands
199 @section Text Handling
200
201 @menu
202 * Move Commands:: Moving, Searching
203 * Marking:: Textmarkers in Viper and the Emacs Mark.
204 * Appending Text:: Text insertion, Shifting, Putting
205 * Editing in Insert State:: Autoindent, Quoting etc.
206 * Deleting Text:: Deleting
207 * Changing Text:: Changing, Replacement, Joining
208 * Search and Replace:: Searches, Query Replace, Pattern Commands
209 * Yanking:: Yanking, Viewing Registers
210 * Undoing:: Multiple Undo, Backups
211 @end menu
212
213 @node Move Commands,Marking,,Text Handling
214 @subsection Move Commands
215
216 @cindex movement commands
217 @cindex searching
218 @cindex textmarkers
219 @cindex markers
220 @cindex column movement
221 @cindex paragraphs
222 @cindex headings
223 @cindex sections
224 @cindex sentences
225 @cindex matching parens
226 @cindex paren matching
227
228 @table @kbd
229 @item <count> h C-h
230 <count> chars to the left.
231 @item <count> j <lf> C-n
232 <count> lines downward.
233 @item <count> l <sp>
234 <count> chars to the right.
235 @item <count> k C-p
236 <count> lines upward.
237 @item <count> $
238 To the end of line <count> from the cursor.
239 @item <count> ^
240 To the first CHAR <count> - 1 lines lower.
241 @item <count> -
242 To the first CHAR <count> lines higher.
243 @item <count> + <cr>
244 To the first CHAR <count> lines lower.
245 @item 0
246 To the first char of the line.
247 @item <count> |
248 To column <count>
249 @item <count> f<char>
250 <count> <char>s to the right (find).
251 @item <count> t<char>
252 Till before <count> <char>s to the right.
253 @item <count> F<char>
254 <count> <char>s to the left.
255 @item <count> T<char>
256 Till after <count> <char>s to the left.
257 @item <count> ;
258 Repeat latest @kbd{f t F T} <count> times.
259 @item <count> ,
260 Repeat latest @kbd{f t F T}
261 <count> times in opposite direction.
262 @item <count> w
263 <count> words forward.
264 @item <count> W
265 <count> WORDS forward.
266 @item <count> b
267 <count> words backward.
268 @item <count> B
269 <count> WORDS backward.
270 @item <count> e
271 To the end of word <count> forward.
272 @item <count> E
273 To the end of WORD <count> forward.
274 @item <count> G
275 Go to line <count> (default end-of-file).
276 @item <count> H
277 To line <count> from top of the screen (home).
278 @item <count> L
279 To line <count> from bottom of the screen (last).
280 @item M
281 To the middle line of the screen.
282 @item <count> )
283 <count> sentences forward.
284 @item <count> (
285 <count> sentences backward.
286 @item <count> @}
287 <count> paragraphs forward.
288 @item <count> @{
289 <count> paragraphs backward.
290 @item <count> ]]
291 To the <count>th heading.
292 @item <count> [[
293 To the <count>th previous heading.
294 @item <count> []
295 To the end of <count>th heading.
296 @item m<a-z>
297 Mark the cursor position with a letter.
298 @item `<a-z>
299 To the mark.
300 @item '<a-z>
301 To the first CHAR of the line with the mark.
302 @item [<a-z>
303 Show contents of textmarker.
304 @item ]<a-z>
305 Show contents of register.
306 @item ``
307 To the cursor position before the latest absolute
308 jump (of which are examples @kbd{/} and @kbd{G}).
309 @item ''
310 To the first CHAR of the line on which the cursor
311 was placed before the latest absolute jump.
312 @item <count> /<string>
313 To the <count>th occurrence of <string>.
314 @item <count> /<cr>
315 To the <count>th occurrence of <string> from previous @kbd{/ or ?}.
316 @item <count> ?<string>
317 To the <count>th previous occurrence of <string>.
318 @item <count> ?<cr>
319 To the <count>th previous occurrence of <string> from previous @kbd{? or /}.
320 @item n
321 Repeat latest @kbd{/} @kbd{?} (next).
322 @item N
323 Repeat latest search in opposite direction.
324 @item C-c /
325 Without a prefix argument, this command toggles
326 case-sensitive/case-insensitive search modes and plain vanilla/regular
327 expression search. With the prefix argument 1, i.e.,
328 @kbd{1 C-c /}, this toggles case-sensitivity; with the prefix argument 2,
329 toggles plain vanilla search and search using
330 regular expressions. @xref{Viper Specials}, for alternative ways to invoke
331 this function.
332 @cindex vanilla search
333 @cindex case-sensitive search
334 @cindex case-insensitive search
335 @item %
336 Find the next bracket and go to its match.
337 @end table
338 @kindex @kbd{%}
339 @kindex @kbd{C-c /}
340 @kindex @kbd{N}
341 @kindex @kbd{n}
342 @kindex @kbd{?<cr>}
343 @kindex @kbd{/<cr>}
344 @kindex @kbd{?<string>}
345 @kindex @kbd{/<string>}
346 @kindex @kbd{''}
347 @kindex @kbd{``}
348 @kindex @kbd{]<a-z>}
349 @kindex @kbd{[<a-z>}
350 @kindex @kbd{'<a-z>}
351 @kindex @kbd{`<a-z>}
352 @kindex @kbd{m<a-z>}
353 @kindex @kbd{[]}
354 @kindex @kbd{[[}
355 @kindex @kbd{]]}
356 @kindex @kbd{@{}
357 @kindex @kbd{@}}
358 @kindex @kbd{(}
359 @kindex @kbd{)}
360 @kindex @kbd{M}
361 @kindex @kbd{L}
362 @kindex @kbd{H}
363 @kindex @kbd{G}
364 @kindex @kbd{E}
365 @kindex @kbd{e}
366 @kindex @kbd{B}
367 @kindex @kbd{b}
368 @kindex @kbd{W}
369 @kindex @kbd{w}
370 @kindex @kbd{,}
371 @kindex @kbd{;}
372 @kindex @kbd{T<char>}
373 @kindex @kbd{F<char>}
374 @kindex @kbd{t<char>}
375 @kindex @kbd{f<char>}
376 @kindex @kbd{|}
377 @kindex @kbd{0}
378 @kindex @kbd{<cr>}
379 @kindex @kbd{+}
380 @kindex @kbd{-}
381 @kindex @kbd{^}
382 @kindex @kbd{$}
383 @kindex @kbd{C-p}
384 @kindex @kbd{<lf>}
385 @kindex @kbd{<sp>}
386 @kindex @kbd{C-n}
387 @kindex @kbd{C-h}
388 @kindex @kbd{h}
389 @kindex @kbd{j}
390 @kindex @kbd{k}
391 @kindex @kbd{l}
392
393 @node Marking,Appending Text,Move Commands,Text Handling
394 @subsection Marking
395
396 Emacs mark is referred to in the region specifiers @kbd{r} and @kbd{R}.
397 @xref{Emacs Preliminaries} and @pxref{Basics} for explanation. Also
398 see @ref{Mark,,Mark,emacs,The GNU Emacs manual}, for an explanation of
399 the Emacs mark ring.
400
401 @cindex marking
402
403 @table @kbd
404 @item m<a-z>
405 Mark the current file and position with the specified letter.
406 @item m .
407 Set the Emacs mark (@xref{Emacs Preliminaries}) at point.
408 @item m <
409 Set the Emacs mark at beginning of buffer.
410 @item m >
411 Set the Emacs mark at end of buffer.
412 @item m ,
413 Jump to the Emacs mark.
414 @item :mark <char>
415 Mark position with text marker named <char>. This is an Ex command.
416 @item :k <char>
417 Same as @kbd{:mark}.
418 @item ``
419 Exchange point and mark.
420 @item ''
421 Exchange point and mark and go to the first CHAR on line.
422 @item '<a-z>
423 Go to specified Viper mark.
424 @item
425 Go to specified Viper mark and go to the first CHAR on line.
426 @end table
427 @kindex @kbd{m<a-z>}
428 @kindex @kbd{m.}
429 @kindex @kbd{m>}
430 @kindex @kbd{m<}
431 @kindex @kbd{m,}
432 @findex @kbd{:mark}
433 @findex @kbd{:k}
434 @kindex @kbd{''}
435 @kindex @kbd{``}
436 @kindex @kbd{`<a-z>}
437 @kindex @kbd{'<a-z>}
438
439 @node Appending Text, Editing in Insert State, Marking,Text Handling
440 @subsection Appending Text
441
442 @xref{Options} to see how to change tab and shiftwidth size. See the GNU
443 Emacs manual, or try @kbd{C-ha tabs} (If you have turned Emacs help on).
444 Check out the variable @code{indent-tabs-mode} to put in just spaces.
445 Also see options for word-wrap.
446
447 @cindex inserting
448 @cindex appending
449 @cindex paste
450 @cindex put
451
452 @table @kbd
453 @item <count> a
454 <count> times after the cursor.
455 @item <count> A
456 <count> times at the end of line.
457 @item <count> i
458 <count> times before the cursor (insert).
459 @item <count> I
460 <count> times before the first CHAR of the line
461 @item <count> o
462 On a new line below the current (open).
463 The count is only useful on a slow terminal.
464 @item <count> O
465 On a new line above the current.
466 The count is only useful on a slow terminal.
467 @item <count> ><move>
468 Shift the lines described by <count><move> one
469 shiftwidth to the right (layout!).
470 @item <count> >>
471 Shift <count> lines one shiftwidth to the right.
472 @item <count> ["<a-z1-9>]p
473 Put the contents of the (default undo) buffer
474 <count> times after the cursor. The register will
475 be automatically downcased.
476 @item <count> ["<a-z1-9>]P
477 Put the contents of the (default undo) buffer
478 <count> times before the cursor. The register will
479 @item [<a-z>
480 Show contents of textmarker.
481 @item ]<a-z>
482 Show contents of register.
483 @item <count> .
484 Repeat previous command <count> times. For destructive
485 commands as well as undo.
486 @item f1 1 and f1 2
487 While @kbd{.} repeats the last destructive command,
488 these two macros repeat the second-last and the third-last destructive
489 commands. @xref{Vi Macros}, for more information on Vi macros.
490 @item C-c M-p and C-c M-n
491 In Vi state,
492 these commands help peruse the history of Vi's destructive commands.
493 Successive typing of @kbd{C-c M-p} causes Viper to search the history in
494 the direction
495 of older commands, while hitting @kbd{C-c M-n} does so in reverse
496 order. Each command in the history is displayed in the Minibuffer. The
497 displayed command can
498 then be executed by typing `@kbd{.}'.
499
500 Since typing the above sequences of keys may be tedious, the
501 functions doing the perusing can be bound to unused keyboard keys in the
502 @file{~/.vip} file. @xref{Viper Specials}, for details.
503 @end table
504 @kindex @kbd{C-c M-p}
505 @kindex @kbd{C-c M-n}
506 @kindex @kbd{.}
507 @kindex @kbd{]<a-z>}
508 @kindex @kbd{[<a-z>}
509 @kindex @kbd{P}
510 @kindex @kbd{p}
511 @kindex @kbd{"<a-z1-9>p}
512 @kindex @kbd{"<a-z1-9>P}
513 @kindex @kbd{>>}
514 @kindex @kbd{><move>}
515 @kindex @kbd{O}
516 @kindex @kbd{o}
517 @kindex @kbd{i}
518 @kindex @kbd{A}
519 @kindex @kbd{a}
520
521 @node Editing in Insert State, Deleting Text, Appending Text,Text Handling
522 @subsection Editing in Insert State
523
524 Minibuffer can be edited similarly to Insert state, and you can switch
525 between Insert/Replace/Vi states at will.
526 Some users prefer plain Emacs feel in the Minibuffer. To this end, set
527 @var{vip-vi-style-in-minibuffer} to @code{nil}.
528
529 @cindex Insert state
530
531 @table @kbd
532 @item C-v
533 Deprive the next char of its special meaning (quoting).
534 @item C-h
535 One char back.
536 @item C-w
537 One word back.
538 @item C-u
539 Back to the begin of the change on the
540 current line.
541
542 @end table
543 @kindex @kbd{C-u}
544 @kindex @kbd{C-w}
545 @kindex @kbd{C-v}
546
547 @node Deleting Text, Changing Text, Editing in Insert State, Text Handling
548 @subsection Deleting Text
549
550
551 There is one difference in text deletion that you should be
552 aware of. This difference comes from Emacs and was adopted in Viper
553 because we find it very useful. In Vi, if you delete a line, say, and then
554 another line, these two deletions are separated and are put back
555 separately if you use the @samp{p} command. In Emacs (and Viper), successive
556 series of deletions that are @emph{not interrupted} by other commands are
557 lumped together, so the deleted text gets accumulated and can be put back
558 as one chunk. If you want to break a sequence of deletions so that the
559 newly deleted text could be put back separately from the previously deleted
560 text, you should perform a non-deleting action, e.g., move the cursor one
561 character in any direction.
562
563 @cindex shifting text
564
565 @table @kbd
566 @item <count> x
567 Delete <count> chars under and after the cursor.
568 @item <count> X
569 Delete <count> chars before the cursor.
570 @item <count> d<move>
571 Delete from point to endpoint of <count><move>.
572 @item <count> dd
573 Delete <count> lines.
574 @item D
575 The rest of the line.
576 @item <count> <<move>
577 Shift the lines described by <count><move> one
578 shiftwidth to the left (layout!).
579 @item <count> <<
580 Shift <count> lines one shiftwidth to the left.
581 @end table
582 @kindex @kbd{<<}
583 @kindex @kbd{<<move>}
584 @kindex @kbd{D}
585 @kindex @kbd{dd}
586 @kindex @kbd{d<move>}
587 @kindex @kbd{X}
588 @kindex @kbd{x}
589
590 @node Changing Text, Search and Replace, Deleting Text,Text Handling
591 @subsection Changing Text
592
593 @cindex joining lines
594 @cindex changing case
595 @cindex quoting regions
596 @cindex substitution
597
598 @table @kbd
599 @item <count> r<char>
600 Replace <count> chars by <char> - no <esc>.
601 @item <count> R
602 Overwrite the rest of the line,
603 appending change @var{count - 1} times.
604 @item <count> s
605 Substitute <count> chars.
606 @item <count> S
607 Change <count> lines.
608 @item <count> c<move>
609 Change from begin to endpoint of <count><move>.
610 @item <count> cc
611 Change <count> lines.
612 @item <count> C
613 The rest of the line and <count> - 1 next lines.
614 @item <count> =<move>
615 Reindent the region described by move.
616 @item <count> ~
617 Switch lower and upper cases.
618 @item <count> J
619 Join <count> lines (default 2).
620 @item :[x,y]s/<p>/<r>/<f>
621 Substitute (on lines x through y) the pattern
622 <p> (default the last pattern) with <r>. Useful
623 flags <f> are @samp{g} for @samp{global} (i.e. change every
624 non-overlapping occurrence of <p>) and @samp{c} for
625 @samp{confirm} (type @samp{y} to confirm a particular
626 substitution, else @samp{n} ). Instead of @kbd{/} any
627 punctuation CHAR unequal to <space> <tab> and <lf> can be used as
628 delimiter.
629 @item :[x,y]copy [z]
630 Copy text between @kbd{x} and @kbd{y} to the position after @kbd{z}.
631 @item :[x,y]t [z]
632 Same as @kbd{:copy}.
633 @item :[x,y]move [z]
634 Move text between @kbd{x} and @kbd{y} to the position after @kbd{z}.
635 @item &
636 Repeat latest Ex substitute command, e.g.
637 @kbd{:s/wrong/good}.
638 @item C-c /
639 Toggle case-sensitive search. With prefix argument, toggle vanilla/regular
640 expression search.
641 @item #c<move>
642 Change upper case characters in the region to lower case.
643 @item #C<move>
644 Change lower case characters in the region to upper case.
645 @item #q<move>
646 Insert specified string at the beginning of each line in the region
647 @item C-c M-p and C-c M-n
648 In Insert and Replace states, these keys are bound to commands that peruse
649 the history of the text
650 previously inserted in other insert or replace commands. By repeatedly typing
651 @kbd{C-c M-p} or @kbd{C-c M-n}, you will cause Viper to
652 insert these previously used strings one by one.
653 When a new string is inserted, the previous one is deleted.
654
655 In Vi state, these keys are bound to functions that peruse the history of
656 destructive Vi commands.
657 @xref{Viper Specials}, for details.
658 @end table
659 @kindex @kbd{C-c M-p}
660 @kindex @kbd{C-c M-n}
661 @kindex @kbd{#q<move> }
662 @kindex @kbd{#C<move>}
663 @kindex @kbd{#c<move>}
664 @kindex @kbd{&}
665 @findex @kbd{:substitute/<p>/<r>/<f>}
666 @findex @kbd{:s/<p>/<r>/<f>}
667 @findex @kbd{:copy [z]}
668 @findex @kbd{:t [z]}
669 @findex @kbd{:move [z]}
670 @kindex @kbd{J}
671 @kindex @kbd{~}
672 @kindex @kbd{=<move>}
673 @kindex @kbd{C}
674 @kindex @kbd{cc}
675 @kindex @kbd{c<move>}
676 @kindex @kbd{S}
677 @kindex @kbd{s}
678 @kindex @kbd{R}
679 @kindex @kbd{r<char>}
680
681 @node Search and Replace, Yanking, Changing Text,Text Handling
682 @subsection Search and Replace
683
684 @xref{Groundwork}, for Ex address syntax. @xref{Options} to see how to
685 get literal (non-regular-expression) search and how to stop search from
686 wrapping around.
687
688 @table @kbd
689 @item <count> /<string>
690 To the <count>th occurrence of <string>.
691 @item <count> ?<string>
692 To the <count>th previous occurrence of <string>.
693 @item <count> g<move>
694 Search for the text described by move. (off by default)
695 @item n
696 Repeat latest @kbd{/} @kbd{?} (next).
697 @item N
698 Idem in opposite direction.
699 @item %
700 Find the next bracket and go to its match
701 @item :[x,y]g/<string>/<cmd>
702 @cindex text processing
703 Search globally [from line x to y] for <string>
704 and execute the Ex <cmd> on each occurrence.
705 @item :[x,y]v/<string>/<cmd>
706 Execute <cmd> on the lines that don't match.
707 @item #g<move>
708 Execute the last keyboard macro for each line in the region.
709 @xref{Macros and Registers}, for more info.
710 @item Q
711 Query Replace.
712 @item :ta <name>
713 Search in the tags file where <name> is defined (file, line), and go to it.
714 @item :[x,y]s/<p>/<r>/<f>
715 Substitute (on lines x through y) the pattern <p> (default the last
716 pattern) with <r>. Useful
717 flags <f> are @samp{g} for @samp{global} (i.e. change every
718 non-overlapping occurrence of <p>) and @samp{c} for
719 @samp{confirm} (type @samp{y} to confirm a particular
720 substitution, else @samp{n}). Instead of @kbd{/} any
721 punctuation CHAR unequal to <space> <tab> and <lf> can be used as delimiter.
722 @item &
723 Repeat latest Ex substitute command, e.g. @kbd{:s/wrong/good}.
724 @end table
725 @kindex @kbd{&}
726 @findex @kbd{:substitute/<p>/<r>/<f>}
727 @kindex @kbd{Q}
728 @kindex @kbd{#g<move>}
729 @findex @kbd{:v/<string>/<cmd>}
730 @findex @kbd{:g/<string>/<cmd>}
731 @findex @kbd{:global/<string>/<cmd>}
732 @findex @kbd{:tag <name>}
733 @kindex @kbd{%}
734 @kindex @kbd{N}
735 @kindex @kbd{n}
736 @kindex @kbd{g<move>}
737 @kindex @kbd{?<string>}
738 @kindex @kbd{/<string>}
739
740 @node Yanking,Undoing,Search and Replace,Text Handling
741 @subsection Yanking
742
743 @cindex cut and paste
744 @cindex paste
745
746 @table @kbd
747 @item <count> y<move>
748 Yank from begin to endpoint of <count><move>.
749 @item <count> "<a-z>y<move>
750 Yank from begin to endpoint of <count><move> to register.
751 @item <count> "<A-Z>y<move>
752 Yank from begin to endpoint of <count><move> and append
753 to register.
754 @item <count> yy
755 <count> lines.
756 @item <count> Y
757 Idem (should be equivalent to @kbd{y$} though).
758 @item m<a-z>
759 Mark the cursor position with a letter.
760 @item [<a-z>
761 Show contents of textmarker.
762 @item ]<a-z>
763 Show contents of register.
764 @item <count> ["<a-z1-9>]p
765 Put the contents of the (default undo) buffer
766 <count> times after the cursor. The register will
767 be automatically downcased.
768 @item <count> ["<a-z1-9>]P
769 Put the contents of the (default undo) buffer
770 <count> times before the cursor. The register will
771 @end table
772 @kindex @kbd{P}
773 @kindex @kbd{p}
774 @kindex @kbd{"<a-z1-9>p}
775 @kindex @kbd{"<a-z1-9>P}
776 @kindex @kbd{]<a-z>}
777 @kindex @kbd{[<a-z>}
778 @kindex @kbd{m<a-z>}
779 @kindex @kbd{Y}
780 @kindex @kbd{yy}
781 @kindex @kbd{"<A-Z>y<move>}
782 @kindex @kbd{"<a-z>y<move>}
783 @kindex @kbd{y<move>}
784 @kindex @kbd{yank}
785 @findex @kbd{:yank}
786
787 @node Undoing,, Yanking,Text Handling
788 @subsection Undoing
789
790 @cindex undo
791 @cindex backup files
792
793 @table @kbd
794 @item u U
795 Undo the latest change.
796 @item .
797 Repeat undo.
798 @item :q!
799 Quit Vi without writing.
800 @item :e!
801 Re-edit a messed-up file.
802 @item :rec
803 Recover file from autosave. Viper also creates backup files
804 that have a @samp{~} appended to them.
805 @end table
806 @findex @kbd{:rec}
807 @findex @kbd{:e!}
808 @findex @kbd{:q!}
809 @kindex @kbd{.}
810 @kindex @kbd{U}
811 @kindex @kbd{u}
812
813 @node Display, File and Buffer Handling, Text Handling, Commands
814 @section Display
815
816 @cindex scrolling
817
818 @table @kbd
819 @item C-g
820 At user level 1,
821 give file name, status, current line number
822 and relative position. @*
823 At user levels 2 and higher, abort the current command.
824 @item C-c g
825 Give file name, status, current line number and relative position -- all
826 user levels.
827 @item C-l
828 Refresh the screen.
829 @item <count> C-e
830 Expose <count> more lines at bottom, cursor stays put (if possible).
831 @item <count> C-y
832 Expose <count> more lines at top, cursor stays put (if possible).
833 @item <count> C-d
834 Scroll <count> lines downward (default the number of the previous scroll;
835 initialization: half a page).
836 @item <count> C-u
837 Scroll <count> lines upward (default the number of the previous scroll;
838 initialization: half a page).
839 @item <count> C-f
840 <count> pages forward.
841 @item <count> C-b
842 <count> pages backward (in older versions @kbd{C-b} only works without count).
843 @item <count> z<cr>
844 @item zH
845 Put line <count> at the top of the window (default the current line).
846 @item <count> z-
847 @item zL
848 Put line <count> at the bottom of the window
849 (default the current line).
850 @item <count> z.
851 @item zM
852 Put line <count> in the center of the window
853 (default the current line).
854 @end table
855 @kindex @kbd{zM}
856 @kindex @kbd{zL}
857 @kindex @kbd{zH}
858 @kindex @kbd{z<cr>}
859 @kindex @kbd{z.}
860 @kindex @kbd{z-}
861 @kindex @kbd{z<cr>}
862 @kindex @kbd{C-b}
863 @kindex @kbd{C-f}
864 @kindex @kbd{C-u}
865 @kindex @kbd{C-d}
866 @kindex @kbd{C-y}
867 @kindex @kbd{C-e}
868 @kindex @kbd{C-l}
869 @kindex @kbd{C-g}
870
871
872 @node File and Buffer Handling, Mapping, Display,Commands
873 @section File and Buffer Handling
874
875 @cindex multiple files
876
877 In all file handling commands, space should be typed before entering the file
878 name. If you need to type a modifier, such as @kbd{>>} or @kbd{!}, don't
879 put any space between the command and the modifier.
880
881 @table @kbd
882 @item :q
883 Quit buffer except if modified.
884 @item :q!
885 Quit buffer without checking. In Viper, these two commands
886 are identical. Confirmation is required if exiting modified buffers that
887 visit files.
888 @item :susp
889 @item :stop
890 Suspend Viper
891 @item :[x,y] w
892 Write the file. Viper nakes sure that a final newline is always added to
893 any file where this newline is missing. This is done by setting Emacs
894 variable @code{require-final-newline} to @code{t}. If you don't like this
895 feature, use @code{setq-default} to set @code{require-final-newline} to
896 @code{nil}. This must be done either in @file{.vip} file or in
897 @code{.emacs} after Viper is loaded.
898 @item :[x,y] w <name>
899 Write to the file <name>.
900 @item :[x,y] w>> <name>
901 Append the buffer to the file <name>. There should be no space between
902 @kbd{w} and @kbd{>>}. Type space after the @kbd{>>} and see what happens.
903 @item :w! <name>
904 Overwrite the file <name>. In Viper, @kbd{:w} and @kbd{:w!} are identical.
905 Confirmation is required for writing to an existing file (if this is not
906 the file the buffer is visiting) or to a read-only file.
907 @item :x,y w <name>
908 Write lines x through y to the file <name>.
909 @item :wq
910 Write the file and kill buffer.
911 @item :r <file> [<file> ...]
912 Read file into a buffer, inserting its contents after the current line.
913 @item :xit
914 Same as @kbd{:wq}.
915 @item :W
916 Save unsaved buffers, asking for confirmation.
917 @item :WW
918 Like @kbd{W}, but without asking for confirmation.
919 @item ZZ
920 Save current buffer and kill it. If user level is 1, then save all files
921 and kill Emacs. Killing Emacs is the wrong way to use it, so you should
922 switch to higher user levels as soon as possible.
923 @item :x [<file>]
924 Save and kill buffer.
925 @item :x! [<file>]
926 @kbd{:w![<file>]} and @kbd{:q}.
927 @item :pre
928 Preserve the file -- autosave buffers.
929 @item :rec
930 Recover file from autosave.
931 @item :f
932 Print file name and lines.
933 @item :cd [<dir>]
934 Set the working directory to <dir> (default home directory).
935 @item :pwd
936 Print present working directory.
937 @item :e [+<cmd>] <files>
938 Edit files. If no filename is given, edit the file visited by the current
939 buffer. If buffer was modified or the file changed on disk, ask for
940 confirmation. Unlike Vi, Viper allows @kbd{:e} to take multiple arguments.
941 The first file is edited the same way as in Vi. The rest are visited
942 in the usual Emacs way.
943 @item :e! [+<cmd>] <files>
944 Re-edit file. If no filename, reedit current file.
945 In Viper, unlike Vi, @kbd{e!} is identical to @kbd{:e}. In both cases, the
946 user is asked to confirm if there is a danger of discarding changes to a
947 buffer.
948 @item :q!
949 Quit Vi without writing.
950 @item C-^
951 Edit the alternate (normally the previous) file.
952 @item :rew
953 Obsolete
954 @item :args
955 List files not shown anywhere with counts for next
956 @item :n [count] [+<cmd>] [<files>]
957 Edit <count> file, or edit files. The count comes from :args.
958 @item :N [count] [+<cmd>] [<files>]
959 Like @kbd{:n}, but the meaning of the variable
960 @var{ex-cycle-other-window} is reversed.
961 @item :b
962 Switch to another buffer. If @var{ex-cycle-other-window} is @code{t},
963 switch in another window. Buffer completion is supported.
964 @item :B
965 Like @kbd{:b}, but the meaning of @var{ex-cycle-other-window} is reversed.
966 @item :<address>r <name>
967 Read the file <name> into the buffer after the line <address>.
968 @item v, V, C-v
969 Edit a file in current or another window, or in another frame. File name
970 is typed in Minibuffer. File completion and history are supported.
971 @end table
972 @kindex @kbd{v}
973 @kindex @kbd{V}
974 @findex @kbd{:args}
975 @findex @kbd{:rew}
976 @kindex @kbd{C-^}
977 @findex @kbd{:e! [<files>]}
978 @findex @kbd{:e [<files>]}
979 @findex @kbd{:edit [<files>]}
980 @findex @kbd{:edit! [<files>]}
981 @findex @kbd{:q!}
982 @findex @kbd{:q}
983 @findex @kbd{:quit}
984 @findex @kbd{:quit!}
985 @findex @kbd{:f}
986 @findex @kbd{:rec}
987 @findex @kbd{:r}
988 @findex @kbd{:read}
989 @findex @kbd{:pre}
990 @kindex @kbd{ZZ}
991 @findex @kbd{:wq}
992 @findex @kbd{:w <file>}
993 @findex @kbd{:w! <file>}
994 @findex @kbd{:w >> <file>}
995 @findex @kbd{:write <file>}
996 @findex @kbd{:write! <file>}
997 @findex @kbd{:write >> <file>}
998 @findex @kbd{:W}
999 @findex @kbd{:WW}
1000 @findex @kbd{:Write}
1001 @findex @kbd{:WWrite}
1002 @findex @kbd{:WWrite}
1003 @findex @kbd{:x}
1004 @findex @kbd{:x!}
1005 @findex @kbd{:susp}
1006 @findex @kbd{:stop}
1007 @findex @kbd{:n [<count> | <file>]}
1008 @findex @kbd{:cd [<dir>]}
1009 @findex @kbd{:pwd}
1010
1011 @node Mapping, Shell Commands, File and Buffer Handling, Commands
1012 @section Mapping
1013
1014 @cindex keybindings
1015 @cindex keymapping
1016
1017 @table @kbd
1018 @item :map <string>
1019 Start defining a Vi-style keyboard macro.
1020 For instance, typing
1021 @kbd{:map www} followed by @kbd{:!wc %} and then typing @kbd{C-x )}
1022 will cause @kbd{www} to run wc on
1023 current file (Vi replaces @samp{%} with the current file name).
1024 @item C-x )
1025 Finish defining a keyboard macro.
1026 In Viper, this command completes the process of defining all keyboard
1027 macros, whether they are Emacs-style or Vi-style.
1028 This is a departure from Vi, needed to allow WYSIWYG mapping of
1029 keyboard macros and to permit the use of function keys and arbitrary Emacs
1030 functions in the macros.
1031 @item :unmap <string>
1032 Deprive <string> of its mappings in Vi state.
1033 @item :map! <string>
1034 Map a macro for Insert state.
1035 @item :unmap! <string>
1036 Deprive <string> of its mapping in Insert state (see @kbd{:unmap}).
1037 @item @@<a-z>
1038 In Vi state,
1039 execute the contents of register as a command.
1040 @item @@@@
1041 In Vi state,
1042 repeat last register command.
1043 @item @@#
1044 In Vi state,
1045 begin keyboard macro. End with @@<a-z>. This will
1046 put the macro in the proper register. Register will
1047 be automatically downcased.
1048 @xref{Macros and Registers}, for more info.
1049 @item @@!<a-z>
1050 In Vi state,
1051 yank anonymous macro to register
1052 @item *
1053 In Vi state,
1054 execute anonymous macro (defined by C-x( and C-x )).
1055 @item C-x e
1056 Like @kbd{*}, but works in all Viper states.
1057 @item #g<move>
1058 Execute the last keyboard macro for each line in the region.
1059 @xref{Macros and Registers}, for more info.
1060 @item [<a-z>
1061 Show contents of textmarker.
1062 @item ]<a-z>
1063 Show contents of register.
1064 @end table
1065 @kindex @kbd{]<a-z>}
1066 @kindex @kbd{[<a-z>}
1067 @kindex @kbd{#g<move>}
1068 @kindex @kbd{*}
1069 @kindex @kbd{@@!<a-z>}
1070 @kindex @kbd{@@#}
1071 @kindex @kbd{@@@@}
1072 @kindex @kbd{@@<a-z>}
1073 @findex @kbd{:unmap <char>}
1074 @findex @kbd{:map <char> <seq>}
1075 @findex @kbd{:unmap! <char>}
1076 @findex @kbd{:map! <char> <seq>}
1077
1078 @node Shell Commands, Options, Mapping, Commands
1079 @section Shell Commands
1080
1081 @cindex % (Current file)
1082
1083 Note that % is used in Ex commands to mean current file. If you want a %
1084 in your command, it must be escaped as @samp{\%}.
1085 @cindex % (Ex address)
1086 However if % is the
1087 first character, it stands as the address for the whole file.
1088 @cindex # (Previous file)
1089 Similarly, @samp{#} expands to the previous file. The previous file is
1090 the first file in @kbd{:args} listing. This defaults
1091 to the previous file in the VI sense if you have one window.@refill
1092
1093 @cindex shell commands
1094
1095 @table @kbd
1096 @item :sh
1097 Execute a subshell in another window
1098 @item :[x,y]!<cmd>
1099 Execute a shell <cmd> [on lines x through y;
1100 % is replace by current file, \% is changed to %
1101 @item :[x,y]!! [<args>]
1102 Repeat last shell command [and append <args>].
1103 @item :!<cmd>
1104 Just execute command and display result in a buffer.
1105 @item :!! <args>
1106 Repeat last shell command and append <args>
1107 @item <count> !<move><cmd>
1108 The shell executes <cmd>, with standard
1109 input the lines described by <count><move>,
1110 next the standard output replaces those lines
1111 (think of @samp{cb}, @samp{sort}, @samp{nroff}, etc.).
1112 @item <count> !!<cmd>
1113 Give <count> lines as standard input to the
1114 shell <cmd>, next let the standard output
1115 replace those lines.
1116 @item :[x,y] w !<cmd>
1117 Let lines x to y be standard input for <cmd>
1118 (notice the <sp> between @kbd{w} and @kbd{!}).
1119 @item :<address>r !<cmd>
1120 Put the output of <cmd> after the line <address> (default current).
1121 @item :<address>r <name>
1122 Read the file <name> into the buffer after the line <address> (default
1123 current).
1124 @end table
1125 @findex @kbd{:<address>r <name>}
1126 @findex @kbd{:<address>r !<cmd>}
1127 @findex @kbd{!<cmd>}
1128 @findex @kbd{!!<cmd>}
1129 @findex @kbd{!<move><cmd>}
1130 @findex @kbd{:w !<cmd>}
1131 @findex @kbd{:x,y w !<cmd>}
1132 @findex @kbd{:!! <args>}
1133 @findex @kbd{:!<cmd>}
1134 @findex @kbd{:sh}
1135
1136 @node Options,Emacs Related Commands,Shell Commands,Commands
1137 @section Options
1138
1139 @cindex Vi options
1140
1141 @table @kbd
1142 @item ai
1143 @cindex autoindent
1144 autoindent -- In append mode after a <cr> the
1145 cursor will move directly below the first
1146 CHAR on the previous line.
1147 @item ic
1148 @cindex case and searching
1149 ignorecase -- No distinction between upper and
1150 lower cases when searching.
1151 @item magic
1152 @cindex literal searching
1153 Regular expressions used in searches; nomagic means no regexps.
1154 @item ro
1155 @cindex readonly files
1156 readonly -- The file is not to be changed.
1157 If the user attempts to write to this file, confirmation will be requested.
1158 @item sh=<string>
1159 @cindex shell
1160 shell -- The program to be used for shell escapes
1161 (default @samp{$SHELL} (default @file{/bin/sh})).
1162 @item sw=<count>
1163 @cindex layout
1164 @cindex shifting text
1165 shiftwidth -- Gives the shiftwidth (default 8 positions).
1166 @item sm
1167 @cindex paren matching
1168 @cindex matching parens
1169 showmatch -- Whenever you append a @kbd{)}, Vi shows
1170 its match if it's on the same page; also with
1171 @kbd{@{} and @kbd{@}}. If there's no match, Vi will beep.
1172 @item ts=<count>
1173 @cindex changing tab width
1174 @cindex tabbing
1175 tabstop -- The length of a <ht>; warning: this is
1176 only IN the editor, outside of it <ht>s have
1177 their normal length (default 8 positions).
1178 @item wm=<count>
1179 @cindex auto fill
1180 @cindex word wrap
1181 wrapmargin -- In append mode Vi automatically
1182 puts a <lf> whenever there is a <sp> or <ht>
1183 within <wm> columns from the right margin.
1184 @item ws
1185 @cindex searching
1186 wrapscan -- When searching, the end is
1187 considered @samp{stuck} to the begin of the file.
1188 @item :set <option>
1189 Turn <option> on.
1190 @item :set no<option>
1191 Turn <option> off.
1192 @item :set <option>=<value>
1193 Set <option> to <value>.
1194 @end table
1195 @findex @kbd{:set <option>=<value>}
1196 @findex @kbd{:set no<option>}
1197 @findex @kbd{:set <option>}
1198 @findex @kbd{:set ws}
1199 @findex @kbd{:set wrapscan}
1200 @findex @kbd{:set wm=<count>}
1201 @findex @kbd{:set wrapmargin=<count>}
1202 @findex @kbd{:set ts=<count>}
1203 @findex @kbd{:set tabstop=<count>}
1204 @findex @kbd{:set tab-stop-local=<count>}
1205 @findex @kbd{:set sm}
1206 @findex @kbd{:set showmatch}
1207 @findex @kbd{:set sw=<count>}
1208 @findex @kbd{:set shiftwidth=<count>}
1209 @findex @kbd{:set sh=<string>}
1210 @findex @kbd{:set shell=<string>}
1211 @findex @kbd{:set ro}
1212 @findex @kbd{:set readonly}
1213 @findex @kbd{:set magic}
1214 @findex @kbd{:set ic}
1215 @findex @kbd{:set ignorecase}
1216 @findex @kbd{:set ai}
1217 @findex @kbd{:set autoindent}
1218
1219 @node Emacs Related Commands,,Options,Commands
1220 @section Emacs Related Commands
1221
1222 @table @kbd
1223 @item _
1224 Begin Meta command in Vi state. Most often used as _x (M-x).
1225 @item C-z
1226 Begin Meta command in Insert state.
1227 @item C-z
1228 Switch between Emacs and Vi states.
1229 @item C-x0
1230 Close Window
1231 @item C-x1
1232 Close Other Windows
1233 @item C-x2
1234 Split Window
1235 @item C-xo
1236 Move among windows
1237 @item C-xC-f
1238 Emacs find-file, useful in Insert state
1239 @item C-y
1240 Put back the last killed text. Similar to Vi's @kbd{p}, but also works in
1241 Insert and Replace state. This command doesn't work in Vi command state,
1242 since this binding is taken for something else.
1243 @item M-y
1244 Undoes the last @kbd{C-y} and puts another kill from the kill ring.
1245 Using this command, you can try may different kills until you find the one
1246 you need.
1247 @end table
1248 @kindex @kbd{M-y}
1249 @kindex @kbd{C-y}
1250 @kindex @kbd{C-xC-f}
1251 @kindex @kbd{C-xo}
1252 @kindex @kbd{C-x2}
1253 @kindex @kbd{C-x1}
1254 @kindex @kbd{C-x0}
1255 @kindex @kbd{C-z}
1256 @kindex @kbd{C-z}
1257 @kindex @kbd{_}
1258
1259 @node Mouse-bound Commands,,,Commands
1260 @section Mouse-bound Commands
1261
1262 The following two mouse actions are normally bound to to special search and
1263 insert commands in of Viper:
1264
1265 @table @kbd
1266 @item S-mouse-1 (Emacs)
1267 @item meta button1up (XEmacs)
1268 Holding Shift (or Meta, if XEmacs) and clicking mouse button 1 will
1269 initiate search for
1270 a region under the mouse pointer.
1271 This command can take a prefix argument. Note: Viper sets this
1272 binding only if this mouse action is not
1273 already bound to something else.
1274 @xref{Viper Specials}, for more information.@refill
1275
1276 @item S-mouse-2 (Emacs)
1277 @item meta button2up (XEmacs)
1278 Holding Shift (or Meta, if XEmacs) and clicking button 2 of the mouse will
1279 insert a region surrounding the mouse pointer.
1280 This command can also take a prefix argument.
1281 Note: Viper sets this binding only if this mouse action is not
1282 already bound to something else.
1283 @xref{Viper Specials}, for more details.@refill
1284 @end table
1285 @kindex @kbd{S-mouse-1}
1286 @kindex @kbd{S-mouse-2}
1287 @kindex @kbd{meta button1up}
1288 @kindex @kbd{meta button2up}