4.2.6 Changing Text

<count> r<char>

Replace <count> chars by <char>; no <esc>.

<count> R

Overwrite the rest of the line, appending change count − 1 times.

<count> s

Substitute <count> chars.

<count> S

Change <count> lines.

<count> c<move>

Change from begin to endpoint of <count><move>.

<count> cc

Change <count> lines.

<count> C

The rest of the line and <count> − 1 next lines.

<count> =<move>

Reindent the region described by move.

<count> ~

Switch lower and upper cases.

<count> J

Join <count> lines (default 2).

:[x,y]s/<pat>/<repl>/<f>

Substitute (on lines x through y) the pattern <pat> (default the last pattern) with <repl>. Useful flags <f> are ‘g’ for ‘global’ (i.e., change every non-overlapping occurrence of <pat>) and ‘c’ for ‘confirm’ (type ‘y’ to confirm a particular substitution, else ‘n’ ). Instead of / any punctuation CHAR unequal to <space> <tab> and <lf> can be used as delimiter.

In Emacs, ‘\&’ stands for the last matched expression, so s/[ab]+/\&\&/ will double the string matched by [ab]. Viper doesn’t treat ‘&’ specially, unlike Vi: use ‘\&’ instead.

Viper does not parse search patterns and does not expand special symbols found there (e.g., ‘~’ is not expanded to the result of the previous substitution).

Note: The newline character (inserted as C-qC-j) can be used in <repl>.

:[x,y]copy [z]

Copy text between x and y to the position after z.

:[x,y]t [z]

Same as :copy.

:[x,y]move [z]

Move text between x and y to the position after z.

&

Repeat latest Ex substitute command, e.g., :s/wrong/right.

:x,yp
:g/Pat/p
:v/Pat/p

The above commands display certain buffer lines in a temporary buffer. The first form above displays the buffer lines between x and y. The second displays the lines of the buffer, which match a given pattern. The third form displays the lines that do not match the given pattern.

#c<move>

Change upper-case characters in the region to lower-case.

#C<move>

Change lower-case characters in the region to upper-case.

#q<move>

Insert specified string at the beginning of each line in the region

C-c M-p and C-c M-n

In Insert and Replace states, these keys are bound to commands that peruse the history of the text previously inserted in other insert or replace commands. By repeatedly typing C-c M-p or C-c M-n, you will cause Viper to insert these previously used strings one by one. When a new string is inserted, the previous one is deleted.

In Vi state, these keys are bound to functions that peruse the history of destructive Vi commands. See Viper Specials, for details.