insert

 *insert.txt* For Vim version 5.4. Last change: 1999 Jun 29 VIM REFERENCE MANUAL by Bram Moolenaar *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. 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| ============================================================================== 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 
character use "CTRL-V CTRL-@" or "CTRL-V 000". On some systems, you have to
use "CTRL-V 003" to insert a CTRL-C. 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,  and a few other keys get another meaning.
See |'insertmode'|. char action     *i_CTRL-[* *i_*
 or CTRL-[      End insert or Replace mode, go back to Normal mode. Finish abbreviation. *i_CTRL-C*
CTRL-C Quit insert mode, go back to Normal mode. Do not check for abbreviations. *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_*
 or CTRL-H      Delete the character before the cursor (see |i_backspacing| about joining lines). See |:fixdel| if your  does not do what you want. {Vi: does not delete autoindents} *i_*
 Delete the character under the cursor. If the cursor is at the end of the line, and the 'backspace' option is non-zero, delete the ; the next line is appended after the current one. See |:fixdel| if your  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_*
 or CTRL-I Insert a tab. If the 'expandtab' option is on, the equivalent number of spaces is inserted (use CTRL-V  to avoid the expansion). See also the 'smarttab' option and |ins-expandtab|. *i_CTRL-J* *i_*
 or CTRL-J      Begin new line. *i_CTRL-M* *i_*
 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 "" can be entered by typing  (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* *i_* 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 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|) See |registers| about registers. {not in Vi} CTRL-R CTRL-R {0-9a-z"%#/:.-=} *i_CTRL-R_CTRL-R* *i__* 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 . 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 ""xP", where 'x' is the name of the register. However, this cannot be used to replace text. 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. Up to three digits form the decimal value of a single byte (see below |i_CTRL-V_digit|. The non-digit and the three digits are not considered for mapping. {Vi: no decimal byte entry} Note: Under Windows CTRL-V is often mapped to paste text. Then use CTRL-Q instead. *i_CTRL-Q*
CTRL-Q Same as CTRL-V. Note: Some terminal connections may eat CTRL-Q. 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 |ins-completion|. {not in Vi} *i_CTRL-E*
CTRL-E Insert the character which is below the cursor. {not in Vi} *i_CTRL-Y*
CTRL-Y Insert the character which is above the cursor. {not in Vi} Note that for CTRL-E and CTRL-Y 'textwidth' is not used, to be able to copy characters from a long line. *i_CTRL-_*
CTRL-_ Switch between languages, as follows: - When in a rightleft window, revins and nohkmap are toggled, since English will likely be inserted in this case. - When in a norightleft window, revins and hkmap are toggled, since Hebrew will likely be inserted in this case. CTRL-_ moves the cursor to the end of the typed text. This command is only available when the 'allowrevins' option is set. Please refer to |rightleft.txt| for more information about right-to-left mode. {not in Vi} Only if compiled with the |+rightleft| feature (which is not the default). *i_CTRL-]*
CTRL-] Trigger abbreviation, without inserting a character. {not in Vi} *i_*
    Toggle between insert and replace mode. {not in Vi} *i_backspacing*
The effect of the , CTRL-W, and CTRL-U depend on the 'backspace' option
(unless 'revins' is set): backspace     action option 0 delete stops in column 1 and start position of insert 1 delete stops at start position of insert 2 delete always; CTRL-W and CTRL-U stop once at start position of insert If the 'backspace' option is non-zero and the cursor is in column 1 when one
of the three keys is used, the current line is joined with the previous
line. This effectively deletes the  in front of the cursor. {Vi: does
not cross lines, does not delete past start position of insert} *i_CTRL-V_digit*
With CTRL-V followed by one, two, or three digits, you can enter the decimal
value of any byte, except 10. Normally CTRL-V is followed by three digits.
The formed byte is inserted as soon as you type the third digit. If you type
only one or two digits and then a non-digit, the decimal value of those one
or two digits form the byte. After that the non-digit is dealt with in the
normal way. If you enter a value of 10, it will end up in the file as a 0.
The 10 is a , which is used internally to represent the  character.
When writing the buffer to a file, the  character is translated into
. The  character is written at the end of each line. Thus if you
want to insert a  character in a file you will have to make a line
break. The maximum value that can be entered is 255. *i_CTRL-X* *insert_expand*
CTRL-X enters a sub-mode where several commands can be used. Most of these
commands do keyword completion; see |ins-completion|. These are not available
when Vim was compiled without the |+insert_expand| feature. Two commands can be used to scroll the window up or down, without exiting
insert mode: *i_CTRL-X_CTRL-E*
CTRL-X CTRL-E scroll window one line up. *i_CTRL-X_CTRL-Y*
CTRL-X CTRL-Y scroll window one line down. After CTRL-X is pressed, each CTRL-E (CTRL-Y) scrolls the window up (down) by
one line unless that would cause the cursor to move from its current position
in the file. As soon as another key is pressed, CTRL-X mode is exited and
that key is interpreted as in Insert mode. ============================================================================== 2. Special special keys *ins-special-special* The following keys are special. They stop the current insert, do something,
and then restart insertion. This means you can do something without getting
out of Insert mode. This is very handy if you prefer to use the Insert mode
all the time, just like editors that don't have a separate Normal mode. You
may also want to set the 'backspace' option to 2 and set the 'insertmode'
option. You can use CTRL-O if you want to map a function key to a command. The changes (inserted or deleted characters) before and after these keys can
be undone separately. Only the last change can be redone and always behaves
like an "i" command. char action      cursor one line up *i_*  cursor one line down *i_*  cursor one character left *i_*  cursor one character right *i_*        cursor one word back (like "b" command) *i_*    cursor one word back (like "b" command) *i_*  cursor one word forward (like "w" command) *i_*      cursor one word forward (like "w" command) *i_*  cursor to first char in the line *i_*  cursor to after last char in the line *i_*      cursor to first char in the file *i_*  cursor to after last char in the file *i_*      cursor to position of mouse click *i_*  move window one page up *i_*         move window one page up *i_*         move window one page down *i_*   move window one page down *i_* CTRL-O execute one command, return to Insert mode *i_CTRL-O* Note: If the cursor keys take you out of Insert mode, check the 'noesckeys'
option. The CTRL-O command sometimes has one side effect: If the cursor was beyond the
end of the line, it will be put on the last character in the line.
The shifted cursor keys are not available on all terminals. When the 'whichwrap' option is set appropriately, the  and 
keys on the first/last character in the line make the cursor wrap to the
previous/next line. ============================================================================== 3. 'textwidth' and 'wrapmargin' options *ins-textwidth* The 'textwidth' option can be used to automatically break a line before it
gets too long. Set the 'textwidth' option to the desired maximum line
length. If you then type more characters (not spaces or tabs), the
last word will be put on a new line (unless it is the only word on the
line). If you set 'textwidth' to 0, this feature is disabled. The 'wrapmargin' option does almost the same. The difference is that
'textwidth' has a fixed width while 'wrapmargin' depends on the width of the
screen. When using 'wrapmargin' this is equal to using 'textwidth' with a
value equal to (columns - 'wrapmargin'), where columns is the width of the
screen. When 'textwidth' and 'wrapmargin' are both set, 'textwidth' is used. If you don't really want to break the line, but view the line wrapped at a
convenient place, see the 'linebreak' option. The line is only broken automatically when using insert mode, or when
appending to a line. When in replace mode and the line length is not
changed, the line will not be broken. Long lines are broken if you enter a non-white character after the margin.
The situations where a line will be broken can be restricted by adding
characters to the 'formatoptions' option:
"l" Only break a line if it was not longer than 'textwidth' when the insert started.
"v" Only break at a white character that has been entered during the current insert command. This is mostly Vi-compatible.
"lv" Only break if the line was not longer than 'textwidth' when the insert started and only at a white character that has been entered during the current insert command. Only differs from "l" when entering non-white characters while crossing the 'textwidth' boundary. If you want to format a block of text, you can use the "gq" operator. Type
"gq" and a movement command to move the cursor to the end of the block. In
many cases, the command "gq}" will do what you want (format until the end of
paragraph). Alternatively, you can use "gqap", which will format the whole
paragraph, no matter where the cursor currently is. Or you can use Visual
mode: hit "v", move to the end of the block, and type "gq". See also |gq|. ============================================================================== 4. 'expandtab', 'smarttab' and 'softtabstop' options        *ins-expandtab* If the 'expandtab' option is on, spaces will be used to fill the amount of
whitespace of the tab. If you want to enter a real , type CTRL-V first.
The 'expandtab' option is off by default. Note that in Replace mode, a single
character is replaced with several spaces. The result of this is that the
number of characters in the line increases. Backspacing will delete one
space at a time. The original character will be put back for only one space
that you backspace over (the last one). {Vi does not have the 'expandtab'
option} *ins-smarttab*
When the 'smarttab' option is on, a  inserts 'shiftwidth' positions at
the beginning of a line and 'tabstop' positions in other places. This means
that often spaces instead of a  character are inserted. When 'smarttab
is off, a  always inserts 'tabstop' positions, and 'shiftwidth' is only
used for ">>" and the like. {not in Vi} *ins-softtabstop*
When the 'softtabstop' option is non-zero, a  inserts 'softtabstop'
positions, and a  used to delete white space, will delete 'softtabstop'
positions. This feels like 'tabstop' was set to 'softtabstop', but a real
 character still takes 'tabstop' positions, so your file will still look
correct when used by other applications. If 'softtabstop' is non-zero, a  will try to delete as much white space to
move to the previous 'softtabstop' position, except when the previously
inserted character is a space, then it will only delete the character before
the cursor. Otherwise you cannot always delete a single character before the
cursor. You will have to delete 'softtabstop' characters first, and then type
extra spaces to get where you want to be. ============================================================================== 5. Replace mode *Replace-mode* *mode-replace* Enter Replace mode with the "R" command in normal mode. In Replace mode, one character in the line is deleted for every character you
type. If there is no character to delete (at the end of the line), the
typed character is appended (as in Insert mode). Thus the number of
characters in a line stays the same until you get to the end of the line.
If a  is typed, a line break is inserted and no character is deleted. Be careful with  characters. If you type a normal printing character in
its place, the number of characters is still the same, but the number of
columns will become smaller. If you delete characters in Replace mode (with , CTRL-W, or CTRL-U), what
happens is that you delete the changes. The characters that were replaced
are restored. If you had typed past the existing text, the characters you
added are deleted. This is effectively a character-at-a-time undo. If the 'expandtab' option is on, a  will replace one character with
several spaces. The result of this is that the number of characters in the
line increases. Backspacing will delete one space at a time. The original
character will be put back for only one space that you backspace over (the
last one). {Vi does not have the 'expandtab' option} ============================================================================== 6. Virtual replace mode *vreplace-mode* *Virtual-replace-mode* Enter Virtual replace mode with the "gR" command in normal mode. Virtual replace mode is similar to Replace mode, but instead of replacing
actual characters in the file, you are replacing screen real estate, so that
characters further on in the file never appear to move. So if you type a  it may replace several normal characters, and if you
type a letter on top of a  it may not replace anything at all, since the
 will still line up to the same place as before. Typing a  still doesn't cause characters later in the file to appear to
move. The rest of the current line will be replaced by the  (that is,
they are deleted), and replacing continues on the next line. A new line is
NOT inserted unless you go past the end of the file. Interesting effects are seen when using CTRL-T and CTRL-D. The characters
before the cursor are shifted sideways as normal, but characters later in the
line still remain still. CTRL-T will hide some of the old line under the
shifted characters, but CTRL-D will reveal them again. As with Replace mode, using  etc will bring back the characters that were
replaced. This still works in conjunction with 'smartindent', CTRL-T and
CTRL-D, 'expandtab', 'smarttab', 'softtabstop', etc. In 'list' mode, Virtual replace mode acts as if it was not in 'list' mode,
unless "L" is in 'cpoptions'. Note that the only times characters beyond the cursor should appear to move
are in 'list' mode, and occasionally when 'wrap' is set (and the line changes
length to become shorter or wider than the width of the screen), or
momentarily when typing over a CTRL character. A CTRL character takes up two
screen spaces. When replacing it with two normal characters, the first will
be inserted and the second will replace the CTRL character. This mode is very useful for editing  separated columns in tables, for
entering new data while keeping all the columns aligned.
{Vi does not have Virtual replace mode} ============================================================================== 7. Insert mode completion *ins-completion* In Insert and Replace modes, there are several commands to complete part of a
keyword or line that has been typed. This is useful if you are using
complicated keywords (e.g., function names with capitals and underscores). These commands are not available when the |+insert_expand| feature was
disabled at compile time. Completion can be done for: 1. Whole lines |i_CTRL-X_CTRL-L|
2. keywords in the current file |i_CTRL-X_CTRL-N|
3. keywords in 'dictionary' |i_CTRL-X_CTRL-K|
4. keywords in the current and included files |i_CTRL-X_CTRL-I|
5. tags |i_CTRL-X_CTRL-]|
6. file names |i_CTRL-X_CTRL-F|
7. definitions or macros |i_CTRL-X_CTRL-D|
8. keywords in 'complete' |i_CTRL-N| All these (except 2) are done in CTRL-X mode. This is a sub-mode of Insert
and Replace modes. You enter CTRL-X mode by typing CTRL-X and one of the
CTRL-X commands. You exit CTRL-X mode by typing a key that is not a valid
CTRL-X mode command. Valid keys are the CTRL-X command itself, CTRL-N (next),
and CTRL-P (previous). Also see the 'infercase' option if you want to adjust the case of the match. Note: The keys that are valid in CTRL-X mode are not mapped. This allows for
":map ^F ^X^F" to work (where ^F is CTRL-F and ^X is CTRL-X). The key that
ends CTRL-X mode (any key that is not a valid CTRL-X mode command) is mapped. The following mappings are suggested to make typing the completion commands
a bit easier (although they will hide other commands): :inoremap ^] ^X^] :inoremap ^F ^X^F :inoremap ^D ^X^D :inoremap ^L ^X^L Completing whole lines *compl-whole-line* *i_CTRL-X_CTRL-L*
CTRL-X CTRL-L Search backwards for a line that starts with the same characters as in the current line before the cursor. Indent is ignored. The found line is inserted in front of the cursor. CTRL-L      or CTRL-P Search backwards for next matching line. This line replaces the previous matching line. CTRL-N Search forward for next matching line. This line replaces the previous matching line. CTRL-X CTRL-L       After expanding a line you can additionally get the line next to it by typing CTRL-X CTRL-L again, unless a double CTRL-X is used. Completing keywords in current file *compl-current* *i_CTRL-X_CTRL-P* *i_CTRL-X_CTRL-N*
CTRL-X CTRL-N Search forwards for words that start with the keyword in front of the cursor. The found keyword is inserted in front of the cursor. CTRL-X CTRL-P Search backwards for words that start with the keyword in front of the cursor. The found keyword is inserted in front of the cursor. CTRL-N Search forward for next matching keyword. This keyword replaces the previous matching keyword. CTRL-P Search backwards for next matching keyword. This keyword replaces the previous matching keyword. CTRL-X CTRL-N or CTRL-X CTRL-P     Further use of CTRL-X CTRL-N or CTRL-X CTRL-P will copy the words following the previous expansion in other contexts unless a double CTRL-X is used. If there is a keyword in front of the cursor (a name made out of alphabetic
characters and characters in 'iskeyword'), it is used as the search pattern,
with "\