💾 Archived View for gmi.noulin.net › vim › change.gmi captured on 2024-08-31 at 17:31:21. Gemini links have been rewritten to link to archived content
View Raw
More Information
⬅️ Previous capture (2024-08-19)
-=-=-=-=-=-=-
- change.txt* For Vim version 9.1. Last change: 2024 Jul 28
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|
7. Sorting text |sorting|
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).
*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|)
When the '#' flag is in 'cpoptions' the count is
ignored.
{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|).
{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.
*:d* *:de* *:del* *:delete* *:dl* *:dp*
:[range]d[elete] [x] Delete [range] lines (default: current line) [into
register x].
Note these weird abbreviations:
:dl delete and list
:dell idem
:delel idem
:deletl idem
:deletel idem
:dp delete and print
:dep idem
:delp idem
:delep idem
:deletp idem
:deletep idem
:[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.
*d-special*
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 there are no non-blanks 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. Use the |o_v| operator to
force the motion to be characterwise or remove the "z" flag from 'cpoptions'
(see |cpo-z|) to disable this peculiarity.
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). Fails when on the last line of the buffer.
If [count] is too big it is reduced to the number of
lines available.
*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).
*gJ*
gJ Join [count] lines, with a minimum of two lines.
Don't insert or remove any spaces.
*v_gJ*
{Visual}gJ Join the highlighted lines, with a minimum of two
lines. Don't insert or remove any spaces.
*:j* *:join*
:[range]j[oin][!] [flags]
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.
See |ex-flags| for [flags].
:[range]j[oin][!] {count} [flags]
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.
See |ex-flags| for [flags].
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 multibyte character |fo-table|.
The '[ mark is set at the end of the first line that was joined, '] at the end
of the resulting line.
==============================================================================
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.
*c*
["x]c{motion} Delete {motion} text [into register x] and start
insert. When 'cpoptions' includes the 'E' flag and
there is no text to delete (e.g., with "cTx" when the
cursor is just after an 'x'), an error occurs and
insert mode does not start (this is Vi compatible).
When 'cpoptions' does not include the 'E' flag, the
"c" command always starts insert mode, even if there
is no text to delete.
*cc*
["x]cc Delete [count] lines [into register x] and start
insert |linewise|. If 'autoindent' is on, preserve
the indent of the first line.
*C*
["x]C Delete from the cursor position to the end of the
line and [count]-1 more lines [into register x], and
start insert. Synonym for c$ (not |linewise|).
*s*
["x]s Delete [count] characters [into register x] and start
insert (s stands for Substitute). Synonym for "cl"
(not |linewise|).
*S*
["x]S Delete [count] lines [into register x] and start
insert. Synonym for "cc" |linewise|.
{Visual}["x]c or *v_c* *v_s*
{Visual}["x]s Delete the highlighted text [into register x] and
start insert (for {Visual} see |Visual-mode|).
*v_r*
{Visual}r{char} Replace all selected characters by {char}.
CTRL-C will be inserted literally.
*v_C*
{Visual}["x]C Delete the highlighted lines [into register x] and
start insert. In Visual block mode it works
differently |v_b_C|.
*v_S*
{Visual}["x]S Delete the highlighted lines [into register x] and
start insert (for {Visual} see |Visual-mode|).
*v_R*
{Visual}["x]R Currently just like {Visual}["x]S. In a next version
it might work differently.
Notes:
- You can end Insert and Replace mode with <Esc>.
- See the section "Insert and Replace mode" |mode-ins-repl| for the other
special characters in these modes.
- The effect of [count] takes place after Vim exits Insert or Replace mode.
- When the 'cpoptions' option contains '