1*insert.txt* For Vim version 7.0aa. Last change: 2004 Jun 16 2 3 4 VIM REFERENCE MANUAL by Bram Moolenaar 5 6 7 *Insert* *Insert-mode* 8Inserting and replacing text *mode-ins-repl* 9 10Most of this file is about Insert and Replace mode. At the end are a few 11commands for inserting text in other ways. 12 13An overview of the most often used commands can be found in chapter 24 of the 14user manual |usr_24.txt|. 15 161. Special keys |ins-special-keys| 172. Special special keys |ins-special-special| 183. 'textwidth' and 'wrapmargin' options |ins-textwidth| 194. 'expandtab', 'smarttab' and 'softtabstop' options |ins-expandtab| 205. Replace mode |Replace-mode| 216. Virtual Replace mode |Virtual-Replace-mode| 227. Insert mode completion |ins-completion| 238. Insert mode commands |inserting| 249. Ex insert commands |inserting-ex| 2510. Inserting a file |inserting-file| 26 27Also see 'virtualedit', for moving the cursor to positions where there is no 28character. Useful for editing a table. 29 30============================================================================== 311. Special keys *ins-special-keys* 32 33In Insert and Replace mode, the following characters have a special meaning; 34other characters are inserted directly. To insert one of these special 35characters into the buffer, precede it with CTRL-V. To insert a <Nul> 36character use "CTRL-V CTRL-@" or "CTRL-V 000". On some systems, you have to 37use "CTRL-V 003" to insert a CTRL-C. Note: When CTRL-V is mapped you can 38often use CTRL-Q instead |i_CTRL-Q|. 39 40If you are working in a special language mode when inserting text, see the 41'langmap' option, |'langmap'|, on how to avoid switching this mode on and off 42all the time. 43 44If you have 'insertmode' set, <Esc> and a few other keys get another meaning. 45See |'insertmode'|. 46 47char action ~ 48----------------------------------------------------------------------- 49 *i_CTRL-[* *i_<Esc>* 50<Esc> or CTRL-[ End insert or Replace mode, go back to Normal mode. Finish 51 abbreviation. 52 Note: If your <Esc> key is hard to hit on your keyboard, train 53 yourself to use CTRL-[. 54 *i_CTRL-C* 55CTRL-C Quit insert mode, go back to Normal mode. Do not check for 56 abbreviations. 57 58 *i_CTRL-@* 59CTRL-@ Insert previously inserted text and stop insert. {Vi: only 60 when typed as first char, only up to 128 chars} 61 *i_CTRL-A* 62CTRL-A Insert previously inserted text. {not in Vi} 63 64 *i_CTRL-H* *i_<BS>* *i_BS* 65<BS> or CTRL-H Delete the character before the cursor (see |i_backspacing| 66 about joining lines). 67 See |:fixdel| if your <BS> key does not do what you want. 68 {Vi: does not delete autoindents} 69 *i_<Del>* *i_DEL* 70<Del> Delete the character under the cursor. If the cursor is at 71 the end of the line, and the 'backspace' option includes 72 "eol", delete the <EOL>; the next line is appended after the 73 current one. 74 See |:fixdel| if your <Del> key does not do what you want. 75 {not in Vi} 76 *i_CTRL-W* 77CTRL-W Delete the word before the cursor (see |i_backspacing| about 78 joining lines). See the section "word motions", 79 |word-motions|, for the definition of a word. 80 *i_CTRL-U* 81CTRL-U Delete all entered characters in the current line (see 82 |i_backspacing| about joining lines). 83 84 *i_CTRL-I* *i_<Tab>* *i_Tab* 85<Tab> or CTRL-I Insert a tab. If the 'expandtab' option is on, the 86 equivalent number of spaces is inserted (use CTRL-V <Tab> to 87 avoid the expansion; use CTRL-Q <Tab> if CTRL-V is mapped 88 |i_CTRL-Q|). See also the 'smarttab' option and 89 |ins-expandtab|. 90 *i_CTRL-J* *i_<NL>* 91<NL> or CTRL-J Begin new line. 92 *i_CTRL-M* *i_<CR>* 93<CR> or CTRL-M Begin new line. 94 *i_CTRL-K* 95CTRL-K {char1} [char2] 96 Enter digraph (see |digraphs|). When {char1} is a special 97 key, the code for that key is inserted in <> form. For 98 example, the string "<S-Space>" can be entered by typing 99 <C-K><S-Space> (two keys). Neither char is considered for 100 mapping. {not in Vi} 101 102CTRL-N Find next keyword (see |i_CTRL-N|). {not in Vi} 103CTRL-P Find previous keyword (see |i_CTRL-P|). {not in Vi} 104 105CTRL-R {0-9a-z"%#*+:.-=} *i_CTRL-R* 106 Insert the contents of a register. Between typing CTRL-R and 107 the second character, '"' will be displayed to indicate that 108 you are expected to enter the name of a register. 109 The text is inserted as if you typed it, but mappings and 110 abbreviations are not used. If you have options like 111 'textwidth', 'formatoptions', or 'autoindent' set, this will 112 influence what will be inserted. This is different from what 113 happens with the "p" command and pasting with the mouse. 114 Special registers: 115 '"' the unnamed register, containing the text of 116 the last delete or yank 117 '%' the current file name 118 '#' the alternate file name 119 '*' the clipboard contents (X11: primary selection) 120 '+' the clipboard contents 121 '/' the last search pattern 122 ':' the last command-line 123 '.' the last inserted text 124 '-' the last small (less than a line) delete 125 '=' the expression register: you are prompted to 126 enter an expression (see |expression|) 127 See |registers| about registers. {not in Vi} 128 129CTRL-R CTRL-R {0-9a-z"%#*+/:.-=} *i_CTRL-R_CTRL-R* 130 Insert the contents of a register. Works like using a single 131 CTRL-R, but the text is inserted literally, not as if typed. 132 This differs when the register contains characters like <BS>. 133 Example, where register a contains "ab^Hc": > 134 CTRL-R a results in "ac". 135 CTRL-R CTRL-R a results in "ab^Hc". 136< Options 'textwidth', 'formatoptions', etc. still apply. If 137 you also want to avoid these, use "<C-R><C-O>r", see below. 138 The '.' register (last inserted text) is still inserted as 139 typed. {not in Vi} 140 141CTRL-R CTRL-O {0-9a-z"%#*+/:.-=} *i_CTRL-R_CTRL-O* 142 Insert the contents of a register literally and don't 143 auto-indent. Does the same as pasting with the mouse 144 |<MiddleMouse>|. 145 Does not replace characters! 146 The '.' register (last inserted text) is still inserted as 147 typed. {not in Vi} 148 149CTRL-R CTRL-P {0-9a-z"%#*+/:.-=} *i_CTRL-R_CTRL-P* 150 Insert the contents of a register literally and fix the 151 indent, like |[<MiddleMouse>|. 152 Does not replace characters! 153 The '.' register (last inserted text) is still inserted as 154 typed. {not in Vi} 155 156 *i_CTRL-T* 157CTRL-T Insert one shiftwidth of indent at the start of the current 158 line. The indent is always rounded to a 'shiftwidth' (this is 159 vi compatible). {Vi: only when in indent} 160 *i_CTRL-D* 161CTRL-D Delete one shiftwidth of indent at the start of the current 162 line. The indent is always rounded to a 'shiftwidth' (this is 163 vi compatible). {Vi: CTRL-D works only when used after 164 autoindent} 165 *i_0_CTRL-D* 1660 CTRL-D Delete all indent in the current line. {Vi: CTRL-D works 167 only when used after autoindent} 168 *i_^_CTRL-D* 169^ CTRL-D Delete all indent in the current line. The indent is 170 restored in the next line. This is useful when inserting a 171 label. {Vi: CTRL-D works only when used after autoindent} 172 173 *i_CTRL-V* 174CTRL-V Insert next non-digit literally. For special keys, the 175 terminal code is inserted. It's also possible to enter the 176 decimal, octal or hexadecimal value of a character 177 |i_CTRL-V_digit|. 178 The characters typed right after CTRL-V are not considered for 179 mapping. {Vi: no decimal byte entry} 180 Note: When CTRL-V is mapped (e.g., to paste text) you can 181 often use CTRL-Q instead |i_CTRL-Q|. 182 183 *i_CTRL-Q* 184CTRL-Q Same as CTRL-V. 185 Note: Some terminal connections may eat CTRL-Q, it doesn't 186 work then. It does work in the GUI. 187 188CTRL-X Enter CTRL-X mode. This is a sub-mode where commands can 189 be given to complete words or scroll the window. See 190 |i_CTRL-X| and |ins-completion|. {not in Vi} 191 192 *i_CTRL-E* 193CTRL-E Insert the character which is below the cursor. {not in Vi} 194 *i_CTRL-Y* 195CTRL-Y Insert the character which is above the cursor. {not in Vi} 196 Note that for CTRL-E and CTRL-Y 'textwidth' is not used, to be 197 able to copy characters from a long line. 198 199 *i_CTRL-_* 200CTRL-_ Switch between languages, as follows: 201 - When in a rightleft window, revins and nohkmap are toggled, 202 since English will likely be inserted in this case. 203 - When in a norightleft window, revins and hkmap are toggled, 204 since Hebrew will likely be inserted in this case. 205 206 CTRL-_ moves the cursor to the end of the typed text. 207 208 This command is only available when the 'allowrevins' option 209 is set. 210 Please refer to |rileft.txt| for more information about 211 right-to-left mode. 212 {not in Vi} 213 Only if compiled with the |+rightleft| feature (which is not 214 the default). 215 *i_CTRL-^* 216CTRL-^ Toggle the use of typing language characters. 217 When language |:lmap| mappings are defined: 218 - If 'iminsert' is 1 (langmap mappings used) it becomes 0 (no 219 langmap mappings used). 220 - If 'iminsert' has another value it becomes 1, thus langmap 221 mappings are enabled. 222 When no language mappings are defined: 223 - If 'iminsert' is 2 (Input Method used) it becomes 0 (no 224 Input Method used). 225 - If 'iminsert' has another value it becomes 2, thus the Input 226 Method is enabled. 227 When set to 1, the value of the "b:keymap_name" variable, the 228 'keymap' option or "<lang>" appears in the status line. 229 The language mappings are normally used to type characters 230 that are different from what the keyboard produces. The 231 'keymap' option can be used to install a whole number of them. 232 {not in Vi} 233 234 *i_CTRL-]* 235CTRL-] Trigger abbreviation, without inserting a character. {not in 236 Vi} 237 238 *i_<Insert>* 239<Insert> Toggle between Insert and Replace mode. {not in Vi} 240----------------------------------------------------------------------- 241 242 *i_backspacing* 243The effect of the <BS>, CTRL-W, and CTRL-U depend on the 'backspace' option 244(unless 'revins' is set). This is a comma separated list of items: 245 246item action ~ 247indent allow backspacing over autoindent 248eol allow backspacing over end-of-line (join lines) 249start allow backspacing over the start position of insert; CTRL-W and 250 CTRL-U stop once at the start position 251 252When 'backspace' is empty, Vi compatible backspacing is used. You cannot 253backspace over autoindent, before column 1 or before where insert started. 254 255For backwards compatibility the values "0", "1" and "2" are also allowed, see 256|'backspace'|. 257 258If the 'backspace' option does contain "eol" and the cursor is in column 1 259when one of the three keys is used, the current line is joined with the 260previous line. This effectively deletes the <EOL> in front of the cursor. 261{Vi: does not cross lines, does not delete past start position of insert} 262 263 *i_CTRL-V_digit* 264With CTRL-V the decimal, octal or hexadecimal value of a character can be 265entered directly. This way you can enter any character, except a line break 266(<NL>, value 10). There are five ways to enter the character value: 267 268first char mode max nr of chars max value ~ 269(none) decimal 3 255 270o or O octal 3 255 271x or X hexadecimal 2 ff (255) 272u hexadecimal 4 ffff (65535) 273U hexadecimal 8 7fffffff (2147483647) 274 275Normally you would type the maximum number of characters. Thus to enter a 276space (value 32) you would type <C-V>032. You can omit the leading zero, in 277which case the character typed after the number must be a non-digit. This 278happens for the other modes as well: As soon as you type a character that is 279invalid for the mode, the value before it will be used and the "invalid" 280character is dealt with in the normal way. 281 282If you enter a value of 10, it will end up in the file as a 0. The 10 is a 283<NL>, which is used internally to represent the <Nul> character. When writing 284the buffer to a file, the <NL> character is translated into <Nul>. The <NL> 285character is written at the end of each line. Thus if you want to insert a 286<NL> character in a file you will have to make a line break. 287 288 *i_CTRL-X* *insert_expand* 289CTRL-X enters a sub-mode where several commands can be used. Most of these 290commands do keyword completion; see |ins-completion|. These are not available 291when Vim was compiled without the |+insert_expand| feature. 292 293Two commands can be used to scroll the window up or down, without exiting 294insert mode: 295 296 *i_CTRL-X_CTRL-E* 297CTRL-X CTRL-E scroll window one line up. 298 299 *i_CTRL-X_CTRL-Y* 300CTRL-X CTRL-Y scroll window one line down. 301 302After CTRL-X is pressed, each CTRL-E (CTRL-Y) scrolls the window up (down) by 303one line unless that would cause the cursor to move from its current position 304in the file. As soon as another key is pressed, CTRL-X mode is exited and 305that key is interpreted as in Insert mode. 306 307 308============================================================================== 3092. Special special keys *ins-special-special* 310 311The following keys are special. They stop the current insert, do something, 312and then restart insertion. This means you can do something without getting 313out of Insert mode. This is very handy if you prefer to use the Insert mode 314all the time, just like editors that don't have a separate Normal mode. You 315may also want to set the 'backspace' option to "indent,eol,start" and set the 316'insertmode' option. You can use CTRL-O if you want to map a function key to 317a command. 318 319The changes (inserted or deleted characters) before and after these keys can 320be undone separately. Only the last change can be redone and always behaves 321like an "i" command. 322 323char action ~ 324----------------------------------------------------------------------- 325<Up> cursor one line up *i_<Up>* 326<Down> cursor one line down *i_<Down>* 327CTRL-G <Up> cursor one line up, insert start column *i_CTRL-G_<Up>* 328CTRL-G k cursor one line up, insert start column *i_CTRL-G_k* 329CTRL-G CTRL-K cursor one line up, insert start column *i_CTRL-G_CTRL-K* 330CTRL-G <Down> cursor one line down, insert start column *i_CTRL-G_<Down>* 331CTRL-G j cursor one line down, insert start column *i_CTRL-G_j* 332CTRL-G CTRL-J cursor one line down, insert start column *i_CTRL-G_CTRL-J* 333<Left> cursor one character left *i_<Left>* 334<Right> cursor one character right *i_<Right>* 335<S-Left> cursor one word back (like "b" command) *i_<S-Left>* 336<C-Left> cursor one word back (like "b" command) *i_<C-Left>* 337<S-Right> cursor one word forward (like "w" command) *i_<S-Right>* 338<C-Right> cursor one word forward (like "w" command) *i_<C-Right>* 339<Home> cursor to first char in the line *i_<Home>* 340<End> cursor to after last char in the line *i_<End>* 341<C-Home> cursor to first char in the file *i_<C-Home>* 342<C-End> cursor to after last char in the file *i_<C-End>* 343<LeftMouse> cursor to position of mouse click *i_<LeftMouse>* 344<S-Up> move window one page up *i_<S-Up>* 345<PageUp> move window one page up *i_<PageUp>* 346<S-Down> move window one page down *i_<S-Down>* 347<PageDown> move window one page down *i_<PageDown>* 348<MouseDown> scroll three lines down *i_<MouseDown>* 349<S-MouseDown> scroll a full page down *i_<S-MouseDown>* 350<MouseUp> scroll three lines up *i_<MouseUp>* 351<S-MouseUp> scroll a full page up *i_<S-MouseUp>* 352CTRL-O execute one command, return to Insert mode *i_CTRL-O* 353CTRL-G u break undo sequence, start new change *i_CTRL-G_u* 354----------------------------------------------------------------------- 355 356Note: If the cursor keys take you out of Insert mode, check the 'noesckeys' 357option. 358 359The CTRL-O command sometimes has a side effect: If the cursor was beyond the 360end of the line, it will be put on the last character in the line. In 361mappings it's often better to use <Esc> (first put an "x" in the text, <Esc> 362will then always put the cursor on it). 363 364The shifted cursor keys are not available on all terminals. 365 366Another side effect is that a count specified before the "i" or "a" command is 367ignored. That is because repeating the effect of the command after CTRL-O is 368too complicated. 369 370An example for using CTRL-G u: > 371 372 :inoremap <C-H> <C-G>u<C-H> 373 374This redefines the backspace key to start a new undo sequence. You can now 375undo the effect of the backspace key, without changing what you typed before 376that, with CTRL-O u. 377 378When the 'whichwrap' option is set appropriately, the <Left> and <Right> 379keys on the first/last character in the line make the cursor wrap to the 380previous/next line. 381 382The CTRL-G j and CTRL-G k commands can be used to insert text in front of a 383column. Example: > 384 int i; 385 int j; 386Position the cursor on the first "int", type "istatic<C-G>j ". The 387result is: > 388 static int i; 389 int j; 390When inserting the same text in front of the column in every line, use the 391Visual blockwise command "I" |v_b_I|. 392 393============================================================================== 3943. 'textwidth' and 'wrapmargin' options *ins-textwidth* 395 396The 'textwidth' option can be used to automatically break a line before it 397gets too long. Set the 'textwidth' option to the desired maximum line 398length. If you then type more characters (not spaces or tabs), the 399last word will be put on a new line (unless it is the only word on the 400line). If you set 'textwidth' to 0, this feature is disabled. 401 402The 'wrapmargin' option does almost the same. The difference is that 403'textwidth' has a fixed width while 'wrapmargin' depends on the width of the 404screen. When using 'wrapmargin' this is equal to using 'textwidth' with a 405value equal to (columns - 'wrapmargin'), where columns is the width of the 406screen. 407 408When 'textwidth' and 'wrapmargin' are both set, 'textwidth' is used. 409 410If you don't really want to break the line, but view the line wrapped at a 411convenient place, see the 'linebreak' option. 412 413The line is only broken automatically when using insert mode, or when 414appending to a line. When in replace mode and the line length is not 415changed, the line will not be broken. 416 417Long lines are broken if you enter a non-white character after the margin. 418The situations where a line will be broken can be restricted by adding 419characters to the 'formatoptions' option: 420"l" Only break a line if it was not longer than 'textwidth' when the insert 421 started. 422"v" Only break at a white character that has been entered during the 423 current insert command. This is mostly Vi-compatible. 424"lv" Only break if the line was not longer than 'textwidth' when the insert 425 started and only at a white character that has been entered during the 426 current insert command. Only differs from "l" when entering non-white 427 characters while crossing the 'textwidth' boundary. 428 429If you want to format a block of text, you can use the "gq" operator. Type 430"gq" and a movement command to move the cursor to the end of the block. In 431many cases, the command "gq}" will do what you want (format until the end of 432paragraph). Alternatively, you can use "gqap", which will format the whole 433paragraph, no matter where the cursor currently is. Or you can use Visual 434mode: hit "v", move to the end of the block, and type "gq". See also |gq|. 435 436============================================================================== 4374. 'expandtab', 'smarttab' and 'softtabstop' options *ins-expandtab* 438 439If the 'expandtab' option is on, spaces will be used to fill the amount of 440whitespace of the tab. If you want to enter a real <Tab>, type CTRL-V first 441(use CTRL-Q when CTRL-V is mapped |i_CTRL-Q|). 442The 'expandtab' option is off by default. Note that in Replace mode, a single 443character is replaced with several spaces. The result of this is that the 444number of characters in the line increases. Backspacing will delete one 445space at a time. The original character will be put back for only one space 446that you backspace over (the last one). {Vi does not have the 'expandtab' 447option} 448 449 *ins-smarttab* 450When the 'smarttab' option is on, a <Tab> inserts 'shiftwidth' positions at 451the beginning of a line and 'tabstop' positions in other places. This means 452that often spaces instead of a <Tab> character are inserted. When 'smarttab 453is off, a <Tab> always inserts 'tabstop' positions, and 'shiftwidth' is only 454used for ">>" and the like. {not in Vi} 455 456 *ins-softtabstop* 457When the 'softtabstop' option is non-zero, a <Tab> inserts 'softtabstop' 458positions, and a <BS> used to delete white space, will delete 'softtabstop' 459positions. This feels like 'tabstop' was set to 'softtabstop', but a real 460<Tab> character still takes 'tabstop' positions, so your file will still look 461correct when used by other applications. 462 463If 'softtabstop' is non-zero, a <BS> will try to delete as much white space to 464move to the previous 'softtabstop' position, except when the previously 465inserted character is a space, then it will only delete the character before 466the cursor. Otherwise you cannot always delete a single character before the 467cursor. You will have to delete 'softtabstop' characters first, and then type 468extra spaces to get where you want to be. 469 470============================================================================== 4715. Replace mode *Replace* *Replace-mode* *mode-replace* 472 473Enter Replace mode with the "R" command in normal mode. 474 475In Replace mode, one character in the line is deleted for every character you 476type. If there is no character to delete (at the end of the line), the 477typed character is appended (as in Insert mode). Thus the number of 478characters in a line stays the same until you get to the end of the line. 479If a <NL> is typed, a line break is inserted and no character is deleted. 480 481Be careful with <Tab> characters. If you type a normal printing character in 482its place, the number of characters is still the same, but the number of 483columns will become smaller. 484 485If you delete characters in Replace mode (with <BS>, CTRL-W, or CTRL-U), what 486happens is that you delete the changes. The characters that were replaced 487are restored. If you had typed past the existing text, the characters you 488added are deleted. This is effectively a character-at-a-time undo. 489 490If the 'expandtab' option is on, a <Tab> will replace one character with 491several spaces. The result of this is that the number of characters in the 492line increases. Backspacing will delete one space at a time. The original 493character will be put back for only one space that you backspace over (the 494last one). {Vi does not have the 'expandtab' option} 495 496============================================================================== 4976. Virtual Replace mode *vreplace-mode* *Virtual-Replace-mode* 498 499Enter Virtual Replace mode with the "gR" command in normal mode. 500{not available when compiled without the +vreplace feature} 501{Vi does not have Virtual Replace mode} 502 503Virtual Replace mode is similar to Replace mode, but instead of replacing 504actual characters in the file, you are replacing screen real estate, so that 505characters further on in the file never appear to move. 506 507So if you type a <Tab> it may replace several normal characters, and if you 508type a letter on top of a <Tab> it may not replace anything at all, since the 509<Tab> will still line up to the same place as before. 510 511Typing a <NL> still doesn't cause characters later in the file to appear to 512move. The rest of the current line will be replaced by the <NL> (that is, 513they are deleted), and replacing continues on the next line. A new line is 514NOT inserted unless you go past the end of the file. 515 516Interesting effects are seen when using CTRL-T and CTRL-D. The characters 517before the cursor are shifted sideways as normal, but characters later in the 518line still remain still. CTRL-T will hide some of the old line under the 519shifted characters, but CTRL-D will reveal them again. 520 521As with Replace mode, using <BS> etc will bring back the characters that were 522replaced. This still works in conjunction with 'smartindent', CTRL-T and 523CTRL-D, 'expandtab', 'smarttab', 'softtabstop', etc. 524 525In 'list' mode, Virtual Replace mode acts as if it was not in 'list' mode, 526unless "L" is in 'cpoptions'. 527 528Note that the only times characters beyond the cursor should appear to move 529are in 'list' mode, and occasionally when 'wrap' is set (and the line changes 530length to become shorter or wider than the width of the screen), or 531momentarily when typing over a CTRL character. A CTRL character takes up two 532screen spaces. When replacing it with two normal characters, the first will 533be inserted and the second will replace the CTRL character. 534 535This mode is very useful for editing <Tab> separated columns in tables, for 536entering new data while keeping all the columns aligned. 537 538============================================================================== 5397. Insert mode completion *ins-completion* 540 541In Insert and Replace modes, there are several commands to complete part of a 542keyword or line that has been typed. This is useful if you are using 543complicated keywords (e.g., function names with capitals and underscores). 544 545These commands are not available when the |+insert_expand| feature was 546disabled at compile time. 547 548Completion can be done for: 549 5501. Whole lines |i_CTRL-X_CTRL-L| 5512. keywords in the current file |i_CTRL-X_CTRL-N| 5523. keywords in 'dictionary' |i_CTRL-X_CTRL-K| 5534. keywords in 'thesaurus', thesaurus-style |i_CTRL-X_CTRL-T| 5545. keywords in the current and included files |i_CTRL-X_CTRL-I| 5556. tags |i_CTRL-X_CTRL-]| 5567. file names |i_CTRL-X_CTRL-F| 5578. definitions or macros |i_CTRL-X_CTRL-D| 5589. Vim command-line |i_CTRL-X_CTRL-V| 55910. keywords in 'complete' |i_CTRL-N| 560 561All these (except 2) are done in CTRL-X mode. This is a sub-mode of Insert 562and Replace modes. You enter CTRL-X mode by typing CTRL-X and one of the 563CTRL-X commands. You exit CTRL-X mode by typing a key that is not a valid 564CTRL-X mode command. Valid keys are the CTRL-X command itself, CTRL-N (next), 565and CTRL-P (previous). 566 567Also see the 'infercase' option if you want to adjust the case of the match. 568 569Note: The keys that are valid in CTRL-X mode are not mapped. This allows for 570":map ^F ^X^F" to work (where ^F is CTRL-F and ^X is CTRL-X). The key that 571ends CTRL-X mode (any key that is not a valid CTRL-X mode command) is mapped. 572Also, when doing completion with 'complete' mappings apply as usual. 573 574The following mappings are suggested to make typing the completion commands 575a bit easier (although they will hide other commands): > 576 :inoremap ^] ^X^] 577 :inoremap ^F ^X^F 578 :inoremap ^D ^X^D 579 :inoremap ^L ^X^L 580 581As a special case, typing CTRL-R to perform register insertion (see 582|i_CTRL-R|) will not exit CTRL-X mode. This is primarily to allow the use of 583the '=' register to call some function to determine the next operation. If 584the contents of the register (or result of the '=' register evaluation) are 585not valid CTRL-X mode keys, then CTRL-X mode will be exited as if those keys 586had been typed. 587 588For example, the following will map <Tab> to either actually insert a <Tab> if 589the current line is currently only whitespace, or start/continue a CTRL-N 590completion operation: > 591 592 function! CleverTab() 593 if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$' 594 return "\<Tab>" 595 else 596 return "\<C-N>" 597 endfunction 598 inoremap <Tab> <C-R>=CleverTab()<CR> 599 600 601 602Completing whole lines *compl-whole-line* 603 604 *i_CTRL-X_CTRL-L* 605CTRL-X CTRL-L Search backwards for a line that starts with the 606 same characters as in the current line before the 607 cursor. Indent is ignored. The found line is 608 inserted in front of the cursor. 609 The 'complete' option is used to decide in which 610 buffers a match is searched for. But only loaded 611 buffers are used. 612 CTRL-L or 613 CTRL-P Search backwards for next matching line. This line 614 replaces the previous matching line. 615 616 CTRL-N Search forward for next matching line. This line 617 replaces the previous matching line. 618 619 CTRL-X CTRL-L After expanding a line you can additionally get the 620 line next to it by typing CTRL-X CTRL-L again, unless 621 a double CTRL-X is used. 622 623Completing keywords in current file *compl-current* 624 625 *i_CTRL-X_CTRL-P* 626 *i_CTRL-X_CTRL-N* 627CTRL-X CTRL-N Search forwards for words that start with the keyword 628 in front of the cursor. The found keyword is inserted 629 in front of the cursor. 630 631CTRL-X CTRL-P Search backwards for words that start with the keyword 632 in front of the cursor. The found keyword is inserted 633 in front of the cursor. 634 635 CTRL-N Search forward for next matching keyword. This 636 keyword replaces the previous matching keyword. 637 638 CTRL-P Search backwards for next matching keyword. This 639 keyword replaces the previous matching keyword. 640 641 CTRL-X CTRL-N or 642 CTRL-X CTRL-P Further use of CTRL-X CTRL-N or CTRL-X CTRL-P will 643 copy the words following the previous expansion in 644 other contexts unless a double CTRL-X is used. 645 646If there is a keyword in front of the cursor (a name made out of alphabetic 647characters and characters in 'iskeyword'), it is used as the search pattern, 648with "\<" prepended (meaning: start of a word). Otherwise "\<\k\k" is used 649as search pattern (start of any keyword of at least two characters). 650 651In Replace mode, the number of characters that are replaced depends on the 652length of the matched string. This works like typing the characters of the 653matched string in Replace mode. 654 655If there is not a valid keyword character before the cursor, any keyword of 656at least two characters is matched. 657 e.g., to get: 658 printf("(%g, %g, %g)", vector[0], vector[1], vector[2]); 659 just type: 660 printf("(%g, %g, %g)", vector[0], ^P[1], ^P[2]); 661 662Multiple repeats of the same completion are skipped; thus a different match 663will be inserted at each CTRL-N and CTRL-P (unless there is only one 664matching keyword). 665 666Single character matches are never included, as they usually just get in 667the way of what you were really after. 668 e.g., to get: 669 printf("name = %s\n", name); 670 just type: 671 printf("name = %s\n", n^P); 672 or even: 673 printf("name = %s\n", ^P); 674The 'n' in '\n' is skipped. 675 676After expanding a word, you can use CTRL-X CTRL-P or CTRL-X CTRL-N to get the 677word following the expansion in other contexts. These sequences search for 678the text just expanded and further expand by getting an extra word. This is 679useful if you need to repeat a sequence of complicated words. Although CTRL-P 680and CTRL-N look just for strings of at least two characters, CTRL-X CTRL-P and 681CTRL-X CTRL-N can be used to expand words of just one character. 682 e.g., to get: 683 México 684 you can type: 685 M^N^P^X^P^X^P 686CTRL-N starts the expansion and then CTRL-P takes back the single character 687"M", the next two CTRL-X CTRL-P's get the words "é" and ";xico". 688 689If the previous expansion was split, because it got longer than 'textwidth', 690then just the text in the current line will be used. 691 692If the match found is at the end of a line, then the first word in the next 693line will be inserted and the message "word from next line" displayed, if 694this word is accepted the next CTRL-X CTRL-P or CTRL-X CTRL-N will search 695for those lines starting with this word. 696 697 698Completing keywords in 'dictionary' *compl-dictionary* 699 700 *i_CTRL-X_CTRL-K* 701CTRL-X CTRL-K Search the files given with the 'dictionary' option 702 for words that start with the keyword in front of the 703 cursor. This is like CTRL-N, but only the dictionary 704 files are searched, not the current file. The found 705 keyword is inserted in front of the cursor. This 706 could potentially be pretty slow, since all matches 707 are found before the first match is used. By default, 708 the 'dictionary' option is empty. 709 For suggestions where to find a list of words, see the 710 'dictionary' option. 711 712 CTRL-K or 713 CTRL-N Search forward for next matching keyword. This 714 keyword replaces the previous matching keyword. 715 716 CTRL-P Search backwards for next matching keyword. This 717 keyword replaces the previous matching keyword. 718 719 *i_CTRL-X_CTRL-T* 720CTRL-X CTRL-T Works as CTRL-X CTRL-K, but in a special way. It uses 721 the 'thesaurus' option instead of 'dictionary'. If a 722 match is found in the thesaurus file, all the 723 remaining words on the same line are included as 724 matches, even though they don't complete the word. 725 Thus a word can be completely replaced. 726 727 For an example, imagine the 'thesaurus' file has a 728 line like this: > 729 angry furious mad enraged 730< Placing the cursor after the letters "ang" and typing 731 CTRL-X CTRL-T would complete the word "angry"; 732 subsequent presses would change the word to "furious", 733 "mad" etc. 734 Other uses include translation between two languages, 735 or grouping API functions by keyword. 736 737 CTRL-T or 738 CTRL-N Search forward for next matching keyword. This 739 keyword replaces the previous matching keyword. 740 741 CTRL-P Search backwards for next matching keyword. This 742 keyword replaces the previous matching keyword. 743 744 745Completing keywords in the current and included files *compl-keyword* 746 747The 'include' option is used to specify a line that contains an include file 748name. The 'path' option is used to search for include files. 749 750 *i_CTRL-X_CTRL-I* 751CTRL-X CTRL-I Search for the first keyword in the current and 752 included files that starts with the same characters 753 as those before the cursor. The matched keyword is 754 inserted in front of the cursor. 755 756 CTRL-N Search forwards for next matching keyword. This 757 keyword replaces the previous matching keyword. 758 Note: CTRL-I is the same as <Tab>, which is likely to 759 be typed after a successful completion, therefore 760 CTRL-I is not used for searching for the next match. 761 762 CTRL-P Search backward for previous matching keyword. This 763 keyword replaces the previous matching keyword. 764 765 CTRL-X CTRL-I Further use of CTRL-X CTRL-I will copy the words 766 following the previous expansion in other contexts 767 unless a double CTRL-X is used. 768 769Completing tags *compl-tag* 770 *i_CTRL-X_CTRL-]* 771CTRL-X CTRL-] Search for the first tag that starts with the same 772 characters as before the cursor. The matching tag is 773 inserted in front of the cursor. Alphabetic 774 characters and characters in 'iskeyword' are used 775 to decide which characters are included in the tag 776 name (same as for a keyword). See also |CTRL-]|. 777 The 'showfulltag' option can be used to add context 778 from around the tag definition. 779 CTRL-] or 780 CTRL-N Search forwards for next matching tag. This tag 781 replaces the previous matching tag. 782 783 CTRL-P Search backward for previous matching tag. This tag 784 replaces the previous matching tag. 785 786 787Completing file names *compl-filename* 788 *i_CTRL-X_CTRL-F* 789CTRL-X CTRL-F Search for the first file name that starts with the 790 same characters as before the cursor. The matching 791 file name is inserted in front of the cursor. 792 Alphabetic characters and characters in 'isfname' 793 are used to decide which characters are included in 794 the file name. Note: the 'path' option is not used 795 here (yet). 796 CTRL-F or 797 CTRL-N Search forwards for next matching file name. This 798 file name replaces the previous matching file name. 799 800 CTRL-P Search backward for previous matching file name. 801 This file name replaces the previous matching file 802 name. 803 804 805Completing definitions or macros *compl-define* 806 807The 'define' option is used to specify a line that contains a definition. 808The 'include' option is used to specify a line that contains an include file 809name. The 'path' option is used to search for include files. 810 811 *i_CTRL-X_CTRL-D* 812CTRL-X CTRL-D Search in the current and included files for the 813 first definition (or macro) name that starts with 814 the same characters as before the cursor. The found 815 definition name is inserted in front of the cursor. 816 CTRL-D or 817 CTRL-N Search forwards for next matching macro name. This 818 macro name replaces the previous matching macro 819 name. 820 821 CTRL-P Search backward for previous matching macro name. 822 This macro name replaces the previous matching macro 823 name. 824 825 CTRL-X CTRL-D Further use of CTRL-X CTRL-D will copy the words 826 following the previous expansion in other contexts 827 unless a double CTRL-X is used. 828 829 830Completing Vim commands *compl-vim* 831 832Completion is context-sensitive. It works like on the Command-line. It 833completes an Ex command as well as its arguments. 834 835 *i_CTRL-X_CTRL-V* 836CTRL-X CTRL-V Guess what kind of item is in front of the cursor and 837 find the first match for it. 838 Note: When CTRL-V is mapped you can often use CTRL-Q 839 instead |i_CTRL-Q|. 840 CTRL-V or 841 CTRL-N Search forwards for next match. This match replaces 842 the previous one. 843 844 CTRL-P Search backward for previous match. This match 845 replaces the previous one. 846 847 CTRL-X CTRL-V Further use of CTRL-X CTRL-V will do the same as 848 CTRL-V. This allows mapping a key to do Vim command 849 completion, for example: > 850 :imap <Tab> <C-X><C-V> 851 852Completing keywords from different sources *compl-generic* 853 854 *i_CTRL-N* 855CTRL-N Find next match for words that start with the 856 keyword in front of the cursor, looking in places 857 specified with the 'complete' option. The found 858 keyword is inserted in front of the cursor. 859 860 *i_CTRL-P* 861CTRL-P Find previous match for words that start with the 862 keyword in front of the cursor, looking in places 863 specified with the 'complete' option. The found 864 keyword is inserted in front of the cursor. 865 866 CTRL-N Search forward for next matching keyword. This 867 keyword replaces the previous matching keyword. 868 869 CTRL-P Search backwards for next matching keyword. This 870 keyword replaces the previous matching keyword. 871 872 CTRL-X CTRL-N or 873 CTRL-X CTRL-P Further use of CTRL-X CTRL-N or CTRL-X CTRL-P will 874 copy the words following the previous expansion in 875 other contexts unless a double CTRL-X is used. 876 877============================================================================== 8788. Insert mode commands *inserting* 879 880The following commands can be used to insert new text into the buffer. They 881can all be undone and repeated with the "." command. 882 883 *a* 884a Append text after the cursor [count] times. If the 885 cursor is in the first column of an empty line Insert 886 starts there. But not when 'virtualedit' is set! 887 888 *A* 889A Append text at the end of the line [count] times. 890 891<insert> or *i* *insert* *<Insert>* 892i Insert text before the cursor [count] times. 893 When using CTRL-O in Insert mode |i_CTRL-O| the count 894 is not supported. 895 896 *I* 897I Insert text before the first non-blank in the line 898 [count] times. 899 900 *gI* 901gI Insert text in column 1 [count] times. {not in Vi} 902 903 *gi* 904gi Insert text in the same position as where Insert mode 905 was stopped last time in the current buffer. 906 This uses the |'^| mark. It's different from "`^i" 907 when the mark is past the end of the line. 908 The position is corrected for inserted/deleted lines, 909 but NOT for inserted/deleted characters. 910 When the |:keepjumps| command modifier is used the |'^| 911 mark won't be changed. 912 {not in Vi} 913 914 *o* 915o Begin a new line below the cursor and insert text, 916 repeat [count] times. {Vi: blank [count] screen 917 lines} 918 919 *O* 920O Begin a new line above the cursor and insert text, 921 repeat [count] times. {Vi: blank [count] screen 922 lines} 923 924These commands are used to start inserting text. You can end insert mode with 925<Esc>. See |mode-ins-repl| for the other special characters in Insert mode. 926The effect of [count] takes place after Insert mode is exited. 927 928When 'autoindent' is on, the indent for a new line is obtained from the 929previous line. When 'smartindent' or 'cindent' is on, the indent for a line 930is automatically adjusted for C programs. 931 932'textwidth' can be set to the maximum width for a line. When a line becomes 933too long when appending characters a line break is automatically inserted. 934 935 936============================================================================== 9379. Ex insert commands *inserting-ex* 938 939 *:a* *:append* 940:{range}a[ppend] Insert several lines of text below the specified 941 line. If the {range} is missing, the text will be 942 inserted after the current line. 943 944 *:i* *:in* *:insert* 945:{range}i[nsert] Insert several lines of text above the specified 946 line. If the {range} is missing, the text will be 947 inserted before the current line. 948 949These two commands will keep on asking for lines, until you type a line 950containing only a ".". Watch out for lines starting with a backslash, see 951|line-continuation|. 952NOTE: ":append" and ":insert" don't work properly in between ":if" and 953":endif". 954 955 *:start* *:startinsert* 956:star[tinsert][!] Start Insert mode just after executing this command. 957 Works like typing "i" in Normal mode. When the ! is 958 included it works like "A", append to the line. 959 Otherwise insertion starts at the cursor position. 960 Note that when using this command in a function or 961 script, the insertion only starts after the function 962 or script is finished. 963 {not in Vi} 964 {not available when compiled without the +ex_extra 965 feature} 966 967 *:stopi* *:stopinsert* 968:stopi[nsert] Stop Insert mode as soon as possible. Works like 969 typing <Esc> in Insert mode. 970 Can be used in an autocommand, example: > 971 :au BufEnter scratch stopinsert 972 973============================================================================== 97410. Inserting a file *inserting-file* 975 976 *:r* *:re* *:read* 977:r[ead] [name] Insert the file [name] (default: current file) below 978 the cursor. 979 980:{range}r[ead] [name] Insert the file [name] (default: current file) below 981 the specified line. 982 983 *:r!* *:read!* 984:r[ead] !{cmd} Execute {cmd} and insert its standard output below 985 the cursor. A temporary file is used to store the 986 output of the command which is then read into the 987 buffer. 'shellredir' is used to save the output of 988 the command, which can be set to include stderr or 989 not. {cmd} is executed like with ":!{cmd}", any '!' 990 is replaced with the previous command |:!|. 991 992These commands insert the contents of a file, or the output of a command, 993into the buffer. They can be undone. They cannot be repeated with the "." 994command. They work on a line basis, insertion starts below the line in which 995the cursor is, or below the specified line. To insert text above the first 996line use the command ":0r {name}". 997 998After the ":read" command, the cursor is left on the first non-blank in the 999first new line. Unless in Ex mode, then the cursor is left on the last new 1000line (sorry, this is Vi compatible). 1001 1002If a file name is given with ":r", it becomes the alternate file. This can be 1003used, for example, when you want to edit that file instead: ":e! #". This can 1004be switched off by removing the 'a' flag from the 'cpoptions' option. 1005 1006 *file-read* 1007The 'fileformat' option sets the <EOL> style for a file: 1008'fileformat' characters name ~ 1009 "dos" <CR><NL> or <NL> DOS format 1010 "unix" <NL> Unix format 1011 "mac" <CR> Mac format 1012Previously 'textmode' was used. It is obsolete now. 1013 1014If 'fileformat' is "dos", a <CR> in front of an <NL> is ignored and a CTRL-Z 1015at the end of the file is ignored. 1016 1017If 'fileformat' is "mac", a <NL> in the file is internally represented by a 1018<CR>. This is to avoid confusion with a <NL> which is used to represent a 1019<NUL>. See |CR-used-for-NL|. 1020 1021If the 'fileformats' option is not empty Vim tries to recognize the type of 1022<EOL> (see |file-formats|). However, the 'fileformat' option will not be 1023changed, the detected format is only used while reading the file. 1024A similar thing happens with 'fileencodings'. 1025 1026On non-MS-DOS, Win32, and OS/2 systems the message "[dos format]" is shown if 1027a file is read in DOS format, to remind you that something unusual is done. 1028On Macintosh, MS-DOS, Win32, and OS/2 the message "[unix format]" is shown if 1029a file is read in Unix format. 1030On non-Macintosh systems, the message "[Mac format]" is shown if a file is 1031read in Mac format. 1032 1033An example on how to use ":r !": > 1034 :r !uuencode binfile binfile 1035This command reads "binfile", uuencodes it and reads it into the current 1036buffer. Useful when you are editing e-mail and want to include a binary 1037file. 1038 1039 *read-messages* 1040When reading a file Vim will display a message with information about the read 1041file. In the table is an explanation for some of the items. The others are 1042self explanatory. Using the long or the short version depends on the 1043'shortmess' option. 1044 1045 long short meaning ~ 1046 [readonly] {RO} the file is write protected 1047 [fifo/socket] using a stream 1048 [fifo] using a fifo stream 1049 [socket] using a socket stream 1050 [CR missing] reading with "dos" 'fileformat' and a 1051 NL without a preceding CR was found. 1052 [NL found] reading with "mac" 'fileformat' and a 1053 NL was found (could be "unix" format) 1054 [long lines split] at least one line was split in two 1055 [NOT converted] conversion from 'fileencoding' to 1056 'encoding' was desired but not 1057 possible 1058 [converted] conversion from 'fileencoding' to 1059 'encoding' done 1060 [crypted] file was decrypted 1061 [READ ERRORS] not all of the file could be read 1062 1063 1064 vim:tw=78:ts=8:ft=help:norl: 1065