Home Explore Blog CI



neovim

2nd chunk of `runtime/doc/usr_04.txt`
11e32e59bedc6c7b5fb08f1c5b14433583a3d1dab44412d40000000100000fa0
	<Esc>	back to Normal mode

You will have noticed something strange: The space before "human" isn't
deleted.  There is a saying that for every problem there is an answer that is
simple, clear, and wrong.  That is the case with the example used here for the
"cw" command.  The c operator works just like the d operator, with one
exception: "cw".  It actually works like "ce", change to end of word.  Thus
the space after the word isn't included.  This is an exception that dates back
to the old Vi.  Since many people are used to it now, the inconsistency has
remained in Vim.


MORE CHANGES

Like "dd" deletes a whole line, "cc" changes a whole line.  It keeps the
existing indent (leading white space) though.

Just like "d$" deletes until the end of the line, "c$" changes until the end
of the line.  It's like doing "d$" to delete the text and then "a" to start
Insert mode and append new text.


SHORTCUTS

Some operator-motion commands are used so often that they have been given a
single-letter command:

	x  stands for  dl  (delete character under the cursor)
	X  stands for  dh  (delete character left of the cursor)
	D  stands for  d$  (delete to end of the line)
	C  stands for  c$  (change to end of the line)
	s  stands for  cl  (change one character)
	S  stands for  cc  (change a whole line)


WHERE TO PUT THE COUNT

The commands "3dw" and "d3w" delete three words.  If you want to get really
picky about things, the first command, "3dw", deletes one word three times;
the command "d3w" deletes three words once.  This is a difference without a
distinction.  You can actually put in two counts, however.  For example,
"3d2w" deletes two words, repeated three times, for a total of six words.


REPLACING WITH ONE CHARACTER

The "r" command is not an operator.  It waits for you to type a character, and
will replace the character under the cursor with it.  You could do the same
with "cl" or with the "s" command, but with "r" you don't have to press <Esc>
to get back out of insert mode.

	there is somerhing grong here ~
	rT	     rt    rw

	There is something wrong here ~

Using a count with "r" causes that many characters to be replaced with the
same character.  Example:

	There is something wrong here ~
			   5rx

	There is something xxxxx here ~

To replace a character with a line break use "r<Enter>".  This deletes one
character and inserts a line break.  Using a count here only applies to the
number of characters deleted: "4r<Enter>" replaces four characters with one
line break.

==============================================================================
*04.3*	Repeating a change

The "." command is one of the simplest yet powerful commands in Vim.  It
repeats the last change.  For instance, suppose you are editing an HTML file
and want to delete all the <B> tags.  You position the cursor on the first <
and delete the <B> with the command "df>".  You then go to the < of the next
</B> and delete it using the "." command.  The "." command executes the last
change command (in this case, "df>").  To delete another tag, position the
cursor on the < and use the "." command.

			      To <B>generate</B> a table of <B>contents ~
	f<   find first <     --->
	df>  delete to >	 -->
	f<   find next <	   --------->
	.    repeat df>			    --->
	f<   find next <		       ------------->
	.    repeat df>					    -->

The "." command works for all changes you make, except for "u" (undo), CTRL-R
(redo) and commands that start with a colon (:).

Another example: You want to change the word "four" to "five".  It appears
several times in your text.  You can do this quickly with this sequence of
commands:

	/four<Enter>	find the first string "four"
	cwfive<Esc>	change the word to "five"
	n		find the next "four"
	.		repeat the change to "five"
	n		find the next "four"
	.		repeat the change
			etc.

==============================================================================
*04.4*	Visual mode

To delete simple items the operator-motion changes work quite well.

Title: Vim: Shortcuts, Repeating Changes, and Visual Mode
Summary
This section covers useful Vim shortcuts for common operator-motion commands, clarifies the use of counts with operators, and introduces the 'r' command for single-character replacement. It explains how the '.' command repeats the last change and illustrates its usage with examples. Finally, it introduces Visual mode as an alternative to operator-motion commands for more complex selections.