*insert.txt* For Vim version 7.0aa. Last change: 2006 Jan 08
VIM REFERENCE MANUAL by Bram Moolenaar
*Insert* *Insert-mode*
Inserting and replacing text *mode-ins-repl*
Most of this file is about Insert and Replace mode. At the end are a few
commands for inserting text in other ways.
An overview of the most often used commands can be found in chapter 24 of the
user manual |usr_24.txt|.
1. Special keys |ins-special-keys|
2. Special special keys |ins-special-special|
3. 'textwidth' and 'wrapmargin' options |ins-textwidth|
4. 'expandtab', 'smarttab' and 'softtabstop' options |ins-expandtab|
5. Replace mode |Replace-mode|
6. Virtual Replace mode |Virtual-Replace-mode|
7. Insert mode completion |ins-completion|
8. Insert mode commands |inserting|
9. Ex insert commands |inserting-ex|
10. Inserting a file |inserting-file|
Also see 'virtualedit', for moving the cursor to positions where there is no
character. Useful for editing a table.
==============================================================================
1. Special keys *ins-special-keys*
In Insert and Replace mode, the following characters have a special meaning;
other characters are inserted directly. To insert one of these special
characters into the buffer, precede it with CTRL-V. To insert a <Nul>
character use "CTRL-V CTRL-@" or "CTRL-V 000". On some systems, you have to
use "CTRL-V 003" to insert a CTRL-C. Note: When CTRL-V is mapped you can
often use CTRL-Q instead |i_CTRL-Q|.
If you are working in a special language mode when inserting text, see the
'langmap' option, |'langmap'|, on how to avoid switching this mode on and off
all the time.
If you have 'insertmode' set, <Esc> and a few other keys get another meaning.
See |'insertmode'|.
char action ~
-----------------------------------------------------------------------
*i_CTRL-[* *i_<Esc>*
<Esc> or CTRL-[ End insert or Replace mode, go back to Normal mode. Finish
abbreviation.
Note: If your <Esc> key is hard to hit on your keyboard, train
yourself to use CTRL-[.
*i_CTRL-C*
CTRL-C Quit insert mode, go back to Normal mode. Do not check for
abbreviations. Does not trigger the |InsertLeave| autocommand
event.
*i_CTRL-@*
CTRL-@ Insert previously inserted text and stop insert. {Vi: only
when typed as first char, only up to 128 chars}
*i_CTRL-A*
CTRL-A Insert previously inserted text. {not in Vi}
*i_CTRL-H* *i_<BS>* *i_BS*
<BS> or CTRL-H Delete the character before the cursor (see |i_backspacing|
about joining lines).
See |:fixdel| if your <BS> key does not do what you want.
{Vi: does not delete autoindents}
*i_<Del>* *i_DEL*
<Del> Delete the character under the cursor. If the cursor is at
the end of the line, and the 'backspace' option includes
"eol", delete the <EOL>; the next line is appended after the
current one.
See |:fixdel| if your <Del> key does not do what you want.
{not in Vi}
*i_CTRL-W*
CTRL-W Delete the word before the cursor (see |i_backspacing| about
joining lines). See the section "word motions",
|word-motions|, for the definition of a word.
*i_CTRL-U*
CTRL-U Delete all entered characters in the current line (see
|i_backspacing| about joining lines).
*i_CTRL-I* *i_<Tab>* *i_Tab*
<Tab> or CTRL-I Insert a tab. If the 'expandtab' option is on, the
equivalent number of spaces is inserted (use CTRL-V <Tab> to
avoid the expansion; use CTRL-Q <Tab> if CTRL-V is mapped
|i_CTRL-Q|). See also the 'smarttab' option and
|ins-expandtab|.
*i_CTRL-J* *i_<NL>*
<NL> or CTRL-J Begin new line.
*i_CTRL-M* *i_<CR>*
<CR> or CTRL-M Begin new line.
*i_CTRL-K*
CTRL-K {char1} [char2]
Enter digraph (see |digraphs|). When {char1} is a special
key, the code for that key is inserted in <> form. For
example, the string "<S-Space>" can be entered by typing
<C-K><S-Space> (two keys). Neither char is considered for
mapping. {not in Vi}
CTRL-N Find next keyword (see |i_CTRL-N|). {not in Vi}
CTRL-P Find previous keyword (see |i_CTRL-P|). {not in Vi}
CTRL-R {0-9a-z"%#*+:.-=} *i_CTRL-R*
Insert the contents of a register. Between typing CTRL-R and
the second character, '"' will be displayed to indicate that
you are expected to enter the name of a register.
The text is inserted as if you typed it, but mappings and
abbreviations are not used. If you have options like
'textwidth', 'formatoptions', or 'autoindent' set, this will
influence what will be inserted. This is different from what
happens with the "p" command and pasting with the mouse.
Special registers:
'"' the unnamed register, containing the text of
the last delete or yank
'%' the current file name
'#' the alternate file name
'*' the clipboard contents (X11: primary selection)
'+' the clipboard contents
'/' the last search pattern
':' the last command-line
'.' the last inserted text
'-' the last small (less than a line) delete
'=' the expression register: you are prompted to
enter an expression (see |expression|)
Note that 0x80 (128 decimal) is used for
special keys, use CTRL-R CTRL-R to insert it
literally.
See |registers| about registers. {not in Vi}
CTRL-R CTRL-R {0-9a-z"%#*+/:.-=} *i_CTRL-R_CTRL-R*
Insert the contents of a register. Works like using a single
CTRL-R, but the text is inserted literally, not as if typed.
This differs when the register contains characters like <BS>.
Example, where register a contains "ab^Hc": >
CTRL-R a results in "ac".
CTRL-R CTRL-R a results in "ab^Hc".
< Options 'textwidth', 'formatoptions', etc. still apply. If
you also want to avoid these, use "<C-R><C-O>r", see below.
The '.' register (last inserted text) is still inserted as
typed. {not in Vi}
CTRL-R CTRL-O {0-9a-z"%#*+/:.-=} *i_CTRL-R_CTRL-O*
Insert the contents of a register literally and don't
auto-indent. Does the same as pasting with the mouse
|<MiddleMouse>|.
Does not replace characters!
The '.' register (last inserted text) is still inserted as
typed. {not in Vi}
CTRL-R CTRL-P {0-9a-z"%#*+/:.-=} *i_CTRL-R_CTRL-P*
Insert the contents of a register literally and fix the
indent, like |[<MiddleMouse>|.
Does not replace characters!
The '.' register (last inserted text) is still inserted as
typed. {not in Vi}
*i_CTRL-T*
CTRL-T Insert one shiftwidth of indent at the start of the current
line. The indent is always rounded to a 'shiftwidth' (this is
vi compatible). {Vi: only when in indent}
*i_CTRL-D*
CTRL-D Delete one shiftwidth of indent at the start of the current
line. The indent is always rounded to a 'shiftwidth' (this is
vi compatible). {Vi: CTRL-D works only when used after
autoindent}
*i_0_CTRL-D*
0 CTRL-D Delete all indent in the current line. {Vi: CTRL-D works
only when used after autoindent}
*i_^_CTRL-D*
^ CTRL-D Delete all indent in the current line. The indent is
restored in the next line. This is useful when inserting a
label. {Vi: CTRL-D works only when used after autoindent}
*i_CTRL-V*
CTRL-V Insert next non-digit literally. For special keys, the
terminal code is inserted. It's also possible to enter the
decimal, octal or hexadecimal value of a character
|i_CTRL-V_digit|.
The characters typed right after CTRL-V are not considered for
mapping. {Vi: no decimal byte entry}
Note: When CTRL-V is mapped (e.g., to paste text) you can
often use CTRL-Q instead |i_CTRL-Q|.
*i_CTRL-Q*
CTRL-Q Same as CTRL-V.
Note: Some terminal connections may eat CTRL-Q, it doesn't
work then. It does work in the GUI.
CTRL-X Enter CTRL-X mode. This is a sub-mode where commands can
be given to complete words or scroll the window. See
|i_CTRL-X| and |in