*change.txt* For Vim version 7.0aa. Last change: 2004 Nov 30
VIM REFERENCE MANUAL by Bram Moolenaar
This file describes commands that delete or change text. In this context,
changing text means deleting the text and replacing it with other text using
one command. You can undo all of these commands. You can repeat the non-Ex
commands with the "." command.
1. Deleting text |deleting|
2. Delete and insert |delete-insert|
3. Simple changes |simple-change| *changing*
4. Complex changes |complex-change|
4.1 Filter commands |filter|
4.2 Substitute |:substitute|
4.3 Search and replace |search-replace|
4.4 Changing tabs |change-tabs|
5. Copying and moving text |copy-move|
6. Formatting text |formatting|
For inserting text see |insert.txt|.
==============================================================================
1. Deleting text *deleting* *E470*
["x]<Del> or *<Del>* *x* *dl*
["x]x Delete [count] characters under and after the cursor
[into register x] (not |linewise|). Does the same as
"dl".
The <Del> key does not take a [count]. Instead, it
deletes the last character of the count.
See |:fixdel| if the <Del> key does not do what you
want. See |'whichwrap'| for deleting a line break
(join lines). {Vi does not support <Del>}
*X* *dh*
["x]X Delete [count] characters before the cursor [into
register x] (not |linewise|). Does the same as "dh".
Also see |'whichwrap'|.
*d*
["x]d{motion} Delete text that {motion} moves over [into register
x]. See below for exceptions.
*dd*
["x]dd Delete [count] lines [into register x] |linewise|.
*D*
["x]D Delete the characters under the cursor until the end
of the line and [count]-1 more lines [into register
x]; synonym for "d$".
(not |linewise|)
{Visual}["x]x or *v_x* *v_d* *v_<Del>*
{Visual}["x]d or
{Visual}["x]<Del> Delete the highlighted text [into register x] (for
{Visual} see |Visual-mode|). {not in Vi}
{Visual}["x]CTRL-H or *v_CTRL-H* *v_<BS>*
{Visual}["x]<BS> When in Select mode: Delete the highlighted text [into
register x].
{Visual}["x]X or *v_X* *v_D* *v_b_D*
{Visual}["x]D Delete the highlighted lines [into register x] (for
{Visual} see |Visual-mode|). In Visual block mode,
"D" deletes the highlighted text plus all text until
the end of the line. {not in Vi}
*:d* *:de* *:del* *:delete*
:[range]d[elete] [x] Delete [range] lines (default: current line) [into
register x].
:[range]d[elete] [x] {count}
Delete {count} lines, starting with [range]
(default: current line |cmdline-ranges|) [into
register x].
These commands delete text. You can repeat them with the "." command
(except ":d") and undo them. Use Visual mode to delete blocks of text. See
|registers| for an explanation of registers.
An exception for the d{motion} command: If the motion is not linewise, the
start and end of the motion are not in the same line, and there are only
blanks before the start and after the end of the motion, the delete becomes
linewise. This means that the delete also removes the line of blanks that you
might expect to remain.
Trying to delete an empty region of text (e.g., "d0" in the first column)
is an error when 'cpoptions' includes the 'E' flag.
*J*
J Join [count] lines, with a minimum of two lines.
Remove the indent and insert up to two spaces (see
below).
*v_J*
{Visual}J Join the highlighted lines, with a minimum of two
lines. Remove the indent and insert up to two spaces
(see below). {not in Vi}
*gJ*
gJ Join [count] lines, with a minimum of two lines.
Don't insert or remove any spaces. {not in Vi}
*v_gJ*
{Visual}gJ Join the highlighted lines, with a minimum of two
lines. Don't insert or remove any spaces. {not in
Vi}
*:j* *:join*
:[range]j[oin][!] Join [range] lines. Same as "J", except with [!]
the join does not insert or delete any spaces.
If a [range] has equal start and end values, this
command does nothing. The default behavior is to
join the current line with the line below it.
{not in Vi: !}
:[range]j[oin][!] {count}
Join {count} lines, starting with [range] (default:
current line |cmdline-ranges|). Same as "J", except
with [!] the join does not insert or delete any
spaces.
{not in Vi: !}
These commands delete the <EOL> between lines. This has the effect of joining
multiple lines into one line. You can repeat these commands (except ":j") and
undo them.
These commands, except "gJ", insert one space in place of the <EOL> unless
there is trailing white space or the next line starts with a ')'. These
commands, except "gJ", delete any leading white space on the next line. If
the 'joinspaces' option is on, these commands insert two spaces after a '.',
'!' or '?' (but if 'cpoptions' includes the 'j' flag, they insert two spaces
only after a '.').
The 'B' and 'M' flags in 'formatoptions' change the behavior for inserting
spaces before and after a multi-byte character |fo-table|.
==============================================================================
2. Delete and insert *delete-insert* *replacing*
*R*
R Enter Replace mode: Each character you type replaces
an existing character, starting with the character
under the cursor. Repeat the entered text [count]-1
times. See |Replace-mode| for more details.
*gR*
gR Enter Virtual Replace mode: Each character you type
replaces existing characters in screen space. So a
<Tab> may replace several characters at once.
Repeat the entered text [count]-1 times. See
|Virtual-Replace-mode| for more details.
{not available when compiled without the +vreplace
feature}
*c*
["x]c{motion} Delete {motion} text [into register x] and start
insert. When 'cpoptions' includes the 'E' flag and
there is