*usr_04.txt* Nvim
VIM USER MANUAL - by Bram Moolenaar
Making small changes
This chapter shows you several ways of making corrections and moving text
around. It teaches you the three basic ways to change text: operator-motion,
Visual mode and text objects.
|04.1| Operators and motions
|04.2| Changing text
|04.3| Repeating a change
|04.4| Visual mode
|04.5| Moving text
|04.6| Copying text
|04.7| Using the clipboard
|04.8| Text objects
|04.9| Replace mode
|04.10| Conclusion
Next chapter: |usr_05.txt| Set your settings
Previous chapter: |usr_03.txt| Moving around
Table of contents: |usr_toc.txt|
==============================================================================
*04.1* Operators and motions
In chapter 2 you learned the "x" command to delete a single character. And
using a count: "4x" deletes four characters.
The "dw" command deletes a word. You may recognize the "w" command as the
move word command. In fact, the "d" command may be followed by any motion
command, and it deletes from the current location to the place where the
cursor winds up.
The "4w" command, for example, moves the cursor over four words. The "d4w"
command deletes four words.
To err is human. To really foul up you need a computer. ~
------------------>
d4w
To err is human. you need a computer. ~
Vim only deletes up to the position where the motion takes the cursor. That's
because Vim knows that you probably don't want to delete the first character
of a word. If you use the "e" command to move to the end of a word, Vim
guesses that you do want to include that last character:
To err is human. you need a computer. ~
-------->
d2e
To err is human. a computer. ~
Whether the character under the cursor is included depends on the command you
used to move to that character. The reference manual calls this "exclusive"
when the character isn't included and "inclusive" when it is.
The "$" command moves to the end of a line. The "d$" command deletes from the
cursor to the end of the line. This is an inclusive motion, thus the last
character of the line is included in the delete operation:
To err is human. a computer. ~
------------>
d$
To err is human ~
There is a pattern here: operator-motion. You first type an operator command.
For example, "d" is the delete operator. Then you type a motion command like
"4l" or "w". This way you can operate on any text you can move over.
==============================================================================
*04.2* Changing text
Another operator is "c", change. It acts just like the "d" operator, except
it leaves you in Insert mode. For example, "cw" changes a word. Or more
specifically, it deletes a word and then puts you in Insert mode.
To err is human ~
------->
c2wbe<Esc>
To be human ~
This "c2wbe<Esc>" contains these bits:
c the change operator
2w move two words (they are deleted and Insert mode started)
be insert this text
<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