1*insert.txt* For Vim version 7.0aa. Last change: 2004 Jul 02 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 378Using CTRL-O splits undo: the text typed before and after it is undone 379separately. If you want to avoid this (e.g., in a mapping) you might be able 380to use CTRL-R = |i_CTRL-R|. E.g., to call a function: > 381 :imap <F2> <C-R>=MyFunc()<CR> 382 383When the 'whichwrap' option is set appropriately, the <Left> and <Right> 384keys on the first/last character in the line make the cursor wrap to the 385previous/next line. 386 387The CTRL-G j and CTRL-G k commands can be used to insert text in front of a 388column. Example: > 389 int i; 390 int j; 391Position the cursor on the first "int", type "istatic<C-G>j ". The 392result is: > 393 static int i; 394 int j; 395When inserting the same text in front of the column in every line, use the 396Visual blockwise command "I" |v_b_I|. 397 398============================================================================== 3993. 'textwidth' and 'wrapmargin' options *ins-textwidth* 400 401The 'textwidth' option can be used to automatically break a line before it 402gets too long. Set the 'textwidth' option to the desired maximum line 403length. If you then type more characters (not spaces or tabs), the 404last word will be put on a new line (unless it is the only word on the 405line). If you set 'textwidth' to 0, this feature is disabled. 406 407The 'wrapmargin' option does almost the same. The difference is that 408'textwidth' has a fixed width while 'wrapmargin' depends on the width of the 409screen. When using 'wrapmargin' this is equal to using 'textwidth' with a 410value equal to (columns - 'wrapmargin'), where columns is the width of the 411screen. 412 413When 'textwidth' and 'wrapmargin' are both set, 'textwidth' is used. 414 415If you don't really want to break the line, but view the line wrapped at a 416convenient place, see the 'linebreak' option. 417 418The line is only broken automatically when using insert mode, or when 419appending to a line. When in replace mode and the line length is not 420changed, the line will not be broken. 421 422Long lines are broken if you enter a non-white character after the margin. 423The situations where a line will be broken can be restricted by adding 424characters to the 'formatoptions' option: 425"l" Only break a line if it was not longer than 'textwidth' when the insert 426 started. 427"v" Only break at a white character that has been entered during the 428 current insert command. This is mostly Vi-compatible. 429"lv" Only break if the line was not longer than 'textwidth' when the insert 430 started and only at a white character that has been entered during the 431 current insert command. Only differs from "l" when entering non-white 432 characters while crossing the 'textwidth' boundary. 433 434If you want to format a block of text, you can use the "gq" operator. Type 435"gq" and a movement command to move the cursor to the end of the block. In 436many cases, the command "gq}" will do what you want (format until the end of 437paragraph). Alternatively, you can use "gqap", which will format the whole 438paragraph, no matter where the cursor currently is. Or you can use Visual 439mode: hit "v", move to the end of the block, and type "gq". See also |gq|. 440 441============================================================================== 4424. 'expandtab', 'smarttab' and 'softtabstop' options *ins-expandtab* 443 444If the 'expandtab' option is on, spaces will be used to fill the amount of 445whitespace of the tab. If you want to enter a real <Tab>, type CTRL-V first 446(use CTRL-Q when CTRL-V is mapped |i_CTRL-Q|). 447The 'expandtab' option is off by default. Note that in Replace mode, a single 448character is replaced with several spaces. The result of this is that the 449number of characters in the line increases. Backspacing will delete one 450space at a time. The original character will be put back for only one space 451that you backspace over (the last one). {Vi does not have the 'expandtab' 452option} 453 454 *ins-smarttab* 455When the 'smarttab' option is on, a <Tab> inserts 'shiftwidth' positions at 456the beginning of a line and 'tabstop' positions in other places. This means 457that often spaces instead of a <Tab> character are inserted. When 'smarttab 458is off, a <Tab> always inserts 'tabstop' positions, and 'shiftwidth' is only 459used for ">>" and the like. {not in Vi} 460 461 *ins-softtabstop* 462When the 'softtabstop' option is non-zero, a <Tab> inserts 'softtabstop' 463positions, and a <BS> used to delete white space, will delete 'softtabstop' 464positions. This feels like 'tabstop' was set to 'softtabstop', but a real 465<Tab> character still takes 'tabstop' positions, so your file will still look 466correct when used by other applications. 467 468If 'softtabstop' is non-zero, a <BS> will try to delete as much white space to 469move to the previous 'softtabstop' position, except when the previously 470inserted character is a space, then it will only delete the character before 471the cursor. Otherwise you cannot always delete a single character before the 472cursor. You will have to delete 'softtabstop' characters first, and then type 473extra spaces to get where you want to be. 474 475============================================================================== 4765. Replace mode *Replace* *Replace-mode* *mode-replace* 477 478Enter Replace mode with the "R" command in normal mode. 479 480In Replace mode, one character in the line is deleted for every character you 481type. If there is no character to delete (at the end of the line), the 482typed character is appended (as in Insert mode). Thus the number of 483characters in a line stays the same until you get to the end of the line. 484If a <NL> is typed, a line break is inserted and no character is deleted. 485 486Be careful with <Tab> characters. If you type a normal printing character in 487its place, the number of characters is still the same, but the number of 488columns will become smaller. 489 490If you delete characters in Replace mode (with <BS>, CTRL-W, or CTRL-U), what 491happens is that you delete the changes. The characters that were replaced 492are restored. If you had typed past the existing text, the characters you 493added are deleted. This is effectively a character-at-a-time undo. 494 495If the 'expandtab' option is on, a <Tab> will replace one character with 496several spaces. The result of this is that the number of characters in the 497line increases. Backspacing will delete one space at a time. The original 498character will be put back for only one space that you backspace over (the 499last one). {Vi does not have the 'expandtab' option} 500 501============================================================================== 5026. Virtual Replace mode *vreplace-mode* *Virtual-Replace-mode* 503 504Enter Virtual Replace mode with the "gR" command in normal mode. 505{not available when compiled without the +vreplace feature} 506{Vi does not have Virtual Replace mode} 507 508Virtual Replace mode is similar to Replace mode, but instead of replacing 509actual characters in the file, you are replacing screen real estate, so that 510characters further on in the file never appear to move. 511 512So if you type a <Tab> it may replace several normal characters, and if you 513type a letter on top of a <Tab> it may not replace anything at all, since the 514<Tab> will still line up to the same place as before. 515 516Typing a <NL> still doesn't cause characters later in the file to appear to 517move. The rest of the current line will be replaced by the <NL> (that is, 518they are deleted), and replacing continues on the next line. A new line is 519NOT inserted unless you go past the end of the file. 520 521Interesting effects are seen when using CTRL-T and CTRL-D. The characters 522before the cursor are shifted sideways as normal, but characters later in the 523line still remain still. CTRL-T will hide some of the old line under the 524shifted characters, but CTRL-D will reveal them again. 525 526As with Replace mode, using <BS> etc will bring back the characters that were 527replaced. This still works in conjunction with 'smartindent', CTRL-T and 528CTRL-D, 'expandtab', 'smarttab', 'softtabstop', etc. 529 530In 'list' mode, Virtual Replace mode acts as if it was not in 'list' mode, 531unless "L" is in 'cpoptions'. 532 533Note that the only times characters beyond the cursor should appear to move 534are in 'list' mode, and occasionally when 'wrap' is set (and the line changes 535length to become shorter or wider than the width of the screen), or 536momentarily when typing over a CTRL character. A CTRL character takes up two 537screen spaces. When replacing it with two normal characters, the first will 538be inserted and the second will replace the CTRL character. 539 540This mode is very useful for editing <Tab> separated columns in tables, for 541entering new data while keeping all the columns aligned. 542 543============================================================================== 5447. Insert mode completion *ins-completion* 545 546In Insert and Replace modes, there are several commands to complete part of a 547keyword or line that has been typed. This is useful if you are using 548complicated keywords (e.g., function names with capitals and underscores). 549 550These commands are not available when the |+insert_expand| feature was 551disabled at compile time. 552 553Completion can be done for: 554 5551. Whole lines |i_CTRL-X_CTRL-L| 5562. keywords in the current file |i_CTRL-X_CTRL-N| 5573. keywords in 'dictionary' |i_CTRL-X_CTRL-K| 5584. keywords in 'thesaurus', thesaurus-style |i_CTRL-X_CTRL-T| 5595. keywords in the current and included files |i_CTRL-X_CTRL-I| 5606. tags |i_CTRL-X_CTRL-]| 5617. file names |i_CTRL-X_CTRL-F| 5628. definitions or macros |i_CTRL-X_CTRL-D| 5639. Vim command-line |i_CTRL-X_CTRL-V| 56410. keywords in 'complete' |i_CTRL-N| 565 566All these (except 2) are done in CTRL-X mode. This is a sub-mode of Insert 567and Replace modes. You enter CTRL-X mode by typing CTRL-X and one of the 568CTRL-X commands. You exit CTRL-X mode by typing a key that is not a valid 569CTRL-X mode command. Valid keys are the CTRL-X command itself, CTRL-N (next), 570and CTRL-P (previous). 571 572Also see the 'infercase' option if you want to adjust the case of the match. 573 574Note: The keys that are valid in CTRL-X mode are not mapped. This allows for 575":map ^F ^X^F" to work (where ^F is CTRL-F and ^X is CTRL-X). The key that 576ends CTRL-X mode (any key that is not a valid CTRL-X mode command) is mapped. 577Also, when doing completion with 'complete' mappings apply as usual. 578 579The following mappings are suggested to make typing the completion commands 580a bit easier (although they will hide other commands): > 581 :inoremap ^] ^X^] 582 :inoremap ^F ^X^F 583 :inoremap ^D ^X^D 584 :inoremap ^L ^X^L 585 586As a special case, typing CTRL-R to perform register insertion (see 587|i_CTRL-R|) will not exit CTRL-X mode. This is primarily to allow the use of 588the '=' register to call some function to determine the next operation. If 589the contents of the register (or result of the '=' register evaluation) are 590not valid CTRL-X mode keys, then CTRL-X mode will be exited as if those keys 591had been typed. 592 593For example, the following will map <Tab> to either actually insert a <Tab> if 594the current line is currently only whitespace, or start/continue a CTRL-N 595completion operation: > 596 597 function! CleverTab() 598 if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$' 599 return "\<Tab>" 600 else 601 return "\<C-N>" 602 endfunction 603 inoremap <Tab> <C-R>=CleverTab()<CR> 604 605 606 607Completing whole lines *compl-whole-line* 608 609 *i_CTRL-X_CTRL-L* 610CTRL-X CTRL-L Search backwards for a line that starts with the 611 same characters as in the current line before the 612 cursor. Indent is ignored. The found line is 613 inserted in front of the cursor. 614 The 'complete' option is used to decide in which 615 buffers a match is searched for. But only loaded 616 buffers are used. 617 CTRL-L or 618 CTRL-P Search backwards for next matching line. This line 619 replaces the previous matching line. 620 621 CTRL-N Search forward for next matching line. This line 622 replaces the previous matching line. 623 624 CTRL-X CTRL-L After expanding a line you can additionally get the 625 line next to it by typing CTRL-X CTRL-L again, unless 626 a double CTRL-X is used. 627 628Completing keywords in current file *compl-current* 629 630 *i_CTRL-X_CTRL-P* 631 *i_CTRL-X_CTRL-N* 632CTRL-X CTRL-N Search forwards for words that start with the keyword 633 in front of the cursor. The found keyword is inserted 634 in front of the cursor. 635 636CTRL-X CTRL-P Search backwards for words that start with the keyword 637 in front of the cursor. The found keyword is inserted 638 in front of the cursor. 639 640 CTRL-N Search forward for next matching keyword. This 641 keyword replaces the previous matching keyword. 642 643 CTRL-P Search backwards for next matching keyword. This 644 keyword replaces the previous matching keyword. 645 646 CTRL-X CTRL-N or 647 CTRL-X CTRL-P Further use of CTRL-X CTRL-N or CTRL-X CTRL-P will 648 copy the words following the previous expansion in 649 other contexts unless a double CTRL-X is used. 650 651If there is a keyword in front of the cursor (a name made out of alphabetic 652characters and characters in 'iskeyword'), it is used as the search pattern, 653with "\<" prepended (meaning: start of a word). Otherwise "\<\k\k" is used 654as search pattern (start of any keyword of at least two characters). 655 656In Replace mode, the number of characters that are replaced depends on the 657length of the matched string. This works like typing the characters of the 658matched string in Replace mode. 659 660If there is not a valid keyword character before the cursor, any keyword of 661at least two characters is matched. 662 e.g., to get: 663 printf("(%g, %g, %g)", vector[0], vector[1], vector[2]); 664 just type: 665 printf("(%g, %g, %g)", vector[0], ^P[1], ^P[2]); 666 667Multiple repeats of the same completion are skipped; thus a different match 668will be inserted at each CTRL-N and CTRL-P (unless there is only one 669matching keyword). 670 671Single character matches are never included, as they usually just get in 672the way of what you were really after. 673 e.g., to get: 674 printf("name = %s\n", name); 675 just type: 676 printf("name = %s\n", n^P); 677 or even: 678 printf("name = %s\n", ^P); 679The 'n' in '\n' is skipped. 680 681After expanding a word, you can use CTRL-X CTRL-P or CTRL-X CTRL-N to get the 682word following the expansion in other contexts. These sequences search for 683the text just expanded and further expand by getting an extra word. This is 684useful if you need to repeat a sequence of complicated words. Although CTRL-P 685and CTRL-N look just for strings of at least two characters, CTRL-X CTRL-P and 686CTRL-X CTRL-N can be used to expand words of just one character. 687 e.g., to get: 688 México 689 you can type: 690 M^N^P^X^P^X^P 691CTRL-N starts the expansion and then CTRL-P takes back the single character 692"M", the next two CTRL-X CTRL-P's get the words "é" and ";xico". 693 694If the previous expansion was split, because it got longer than 'textwidth', 695then just the text in the current line will be used. 696 697If the match found is at the end of a line, then the first word in the next 698line will be inserted and the message "word from next line" displayed, if 699this word is accepted the next CTRL-X CTRL-P or CTRL-X CTRL-N will search 700for those lines starting with this word. 701 702 703Completing keywords in 'dictionary' *compl-dictionary* 704 705 *i_CTRL-X_CTRL-K* 706CTRL-X CTRL-K Search the files given with the 'dictionary' option 707 for words that start with the keyword in front of the 708 cursor. This is like CTRL-N, but only the dictionary 709 files are searched, not the current file. The found 710 keyword is inserted in front of the cursor. This 711 could potentially be pretty slow, since all matches 712 are found before the first match is used. By default, 713 the 'dictionary' option is empty. 714 For suggestions where to find a list of words, see the 715 'dictionary' option. 716 717 CTRL-K or 718 CTRL-N Search forward for next matching keyword. This 719 keyword replaces the previous matching keyword. 720 721 CTRL-P Search backwards for next matching keyword. This 722 keyword replaces the previous matching keyword. 723 724 *i_CTRL-X_CTRL-T* 725CTRL-X CTRL-T Works as CTRL-X CTRL-K, but in a special way. It uses 726 the 'thesaurus' option instead of 'dictionary'. If a 727 match is found in the thesaurus file, all the 728 remaining words on the same line are included as 729 matches, even though they don't complete the word. 730 Thus a word can be completely replaced. 731 732 For an example, imagine the 'thesaurus' file has a 733 line like this: > 734 angry furious mad enraged 735< Placing the cursor after the letters "ang" and typing 736 CTRL-X CTRL-T would complete the word "angry"; 737 subsequent presses would change the word to "furious", 738 "mad" etc. 739 Other uses include translation between two languages, 740 or grouping API functions by keyword. 741 742 CTRL-T or 743 CTRL-N Search forward for next matching keyword. This 744 keyword replaces the previous matching keyword. 745 746 CTRL-P Search backwards for next matching keyword. This 747 keyword replaces the previous matching keyword. 748 749 750Completing keywords in the current and included files *compl-keyword* 751 752The 'include' option is used to specify a line that contains an include file 753name. The 'path' option is used to search for include files. 754 755 *i_CTRL-X_CTRL-I* 756CTRL-X CTRL-I Search for the first keyword in the current and 757 included files that starts with the same characters 758 as those before the cursor. The matched keyword is 759 inserted in front of the cursor. 760 761 CTRL-N Search forwards for next matching keyword. This 762 keyword replaces the previous matching keyword. 763 Note: CTRL-I is the same as <Tab>, which is likely to 764 be typed after a successful completion, therefore 765 CTRL-I is not used for searching for the next match. 766 767 CTRL-P Search backward for previous matching keyword. This 768 keyword replaces the previous matching keyword. 769 770 CTRL-X CTRL-I Further use of CTRL-X CTRL-I will copy the words 771 following the previous expansion in other contexts 772 unless a double CTRL-X is used. 773 774Completing tags *compl-tag* 775 *i_CTRL-X_CTRL-]* 776CTRL-X CTRL-] Search for the first tag that starts with the same 777 characters as before the cursor. The matching tag is 778 inserted in front of the cursor. Alphabetic 779 characters and characters in 'iskeyword' are used 780 to decide which characters are included in the tag 781 name (same as for a keyword). See also |CTRL-]|. 782 The 'showfulltag' option can be used to add context 783 from around the tag definition. 784 CTRL-] or 785 CTRL-N Search forwards for next matching tag. This tag 786 replaces the previous matching tag. 787 788 CTRL-P Search backward for previous matching tag. This tag 789 replaces the previous matching tag. 790 791 792Completing file names *compl-filename* 793 *i_CTRL-X_CTRL-F* 794CTRL-X CTRL-F Search for the first file name that starts with the 795 same characters as before the cursor. The matching 796 file name is inserted in front of the cursor. 797 Alphabetic characters and characters in 'isfname' 798 are used to decide which characters are included in 799 the file name. Note: the 'path' option is not used 800 here (yet). 801 CTRL-F or 802 CTRL-N Search forwards for next matching file name. This 803 file name replaces the previous matching file name. 804 805 CTRL-P Search backward for previous matching file name. 806 This file name replaces the previous matching file 807 name. 808 809 810Completing definitions or macros *compl-define* 811 812The 'define' option is used to specify a line that contains a definition. 813The 'include' option is used to specify a line that contains an include file 814name. The 'path' option is used to search for include files. 815 816 *i_CTRL-X_CTRL-D* 817CTRL-X CTRL-D Search in the current and included files for the 818 first definition (or macro) name that starts with 819 the same characters as before the cursor. The found 820 definition name is inserted in front of the cursor. 821 CTRL-D or 822 CTRL-N Search forwards for next matching macro name. This 823 macro name replaces the previous matching macro 824 name. 825 826 CTRL-P Search backward for previous matching macro name. 827 This macro name replaces the previous matching macro 828 name. 829 830 CTRL-X CTRL-D Further use of CTRL-X CTRL-D will copy the words 831 following the previous expansion in other contexts 832 unless a double CTRL-X is used. 833 834 835Completing Vim commands *compl-vim* 836 837Completion is context-sensitive. It works like on the Command-line. It 838completes an Ex command as well as its arguments. 839 840 *i_CTRL-X_CTRL-V* 841CTRL-X CTRL-V Guess what kind of item is in front of the cursor and 842 find the first match for it. 843 Note: When CTRL-V is mapped you can often use CTRL-Q 844 instead |i_CTRL-Q|. 845 CTRL-V or 846 CTRL-N Search forwards for next match. This match replaces 847 the previous one. 848 849 CTRL-P Search backward for previous match. This match 850 replaces the previous one. 851 852 CTRL-X CTRL-V Further use of CTRL-X CTRL-V will do the same as 853 CTRL-V. This allows mapping a key to do Vim command 854 completion, for example: > 855 :imap <Tab> <C-X><C-V> 856 857User defined completing *compl-function* 858 859Completion is done by a function that can be defined by the user with the 860'completefunc' option. See the option for how the function is called and an 861example. 862 863 *i_CTRL-X_CTRL-U* 864CTRL-X CTRL-U Guess what kind of item is in front of the cursor and 865 find the first match for it. 866 CTRL-U or 867 CTRL-N Use the next match. This match replaces the previous 868 one. 869 870 CTRL-P Use the previous match. This match replaces the 871 previous one. 872 873 874Completing keywords from different sources *compl-generic* 875 876 *i_CTRL-N* 877CTRL-N Find next match for words that start with the 878 keyword in front of the cursor, looking in places 879 specified with the 'complete' option. The found 880 keyword is inserted in front of the cursor. 881 882 *i_CTRL-P* 883CTRL-P Find previous match for words that start with the 884 keyword in front of the cursor, looking in places 885 specified with the 'complete' option. The found 886 keyword is inserted in front of the cursor. 887 888 CTRL-N Search forward for next matching keyword. This 889 keyword replaces the previous matching keyword. 890 891 CTRL-P Search backwards for next matching keyword. This 892 keyword replaces the previous matching keyword. 893 894 CTRL-X CTRL-N or 895 CTRL-X CTRL-P Further use of CTRL-X CTRL-N or CTRL-X CTRL-P will 896 copy the words following the previous expansion in 897 other contexts unless a double CTRL-X is used. 898 899============================================================================== 9008. Insert mode commands *inserting* 901 902The following commands can be used to insert new text into the buffer. They 903can all be undone and repeated with the "." command. 904 905 *a* 906a Append text after the cursor [count] times. If the 907 cursor is in the first column of an empty line Insert 908 starts there. But not when 'virtualedit' is set! 909 910 *A* 911A Append text at the end of the line [count] times. 912 913<insert> or *i* *insert* *<Insert>* 914i Insert text before the cursor [count] times. 915 When using CTRL-O in Insert mode |i_CTRL-O| the count 916 is not supported. 917 918 *I* 919I Insert text before the first non-blank in the line 920 [count] times. 921 922 *gI* 923gI Insert text in column 1 [count] times. {not in Vi} 924 925 *gi* 926gi Insert text in the same position as where Insert mode 927 was stopped last time in the current buffer. 928 This uses the |'^| mark. It's different from "`^i" 929 when the mark is past the end of the line. 930 The position is corrected for inserted/deleted lines, 931 but NOT for inserted/deleted characters. 932 When the |:keepjumps| command modifier is used the |'^| 933 mark won't be changed. 934 {not in Vi} 935 936 *o* 937o Begin a new line below the cursor and insert text, 938 repeat [count] times. {Vi: blank [count] screen 939 lines} 940 941 *O* 942O Begin a new line above the cursor and insert text, 943 repeat [count] times. {Vi: blank [count] screen 944 lines} 945 946These commands are used to start inserting text. You can end insert mode with 947<Esc>. See |mode-ins-repl| for the other special characters in Insert mode. 948The effect of [count] takes place after Insert mode is exited. 949 950When 'autoindent' is on, the indent for a new line is obtained from the 951previous line. When 'smartindent' or 'cindent' is on, the indent for a line 952is automatically adjusted for C programs. 953 954'textwidth' can be set to the maximum width for a line. When a line becomes 955too long when appending characters a line break is automatically inserted. 956 957 958============================================================================== 9599. Ex insert commands *inserting-ex* 960 961 *:a* *:append* 962:{range}a[ppend] Insert several lines of text below the specified 963 line. If the {range} is missing, the text will be 964 inserted after the current line. 965 966 *:i* *:in* *:insert* 967:{range}i[nsert] Insert several lines of text above the specified 968 line. If the {range} is missing, the text will be 969 inserted before the current line. 970 971These two commands will keep on asking for lines, until you type a line 972containing only a ".". Watch out for lines starting with a backslash, see 973|line-continuation|. 974NOTE: ":append" and ":insert" don't work properly in between ":if" and 975":endif". 976 977 *:start* *:startinsert* 978:star[tinsert][!] Start Insert mode just after executing this command. 979 Works like typing "i" in Normal mode. When the ! is 980 included it works like "A", append to the line. 981 Otherwise insertion starts at the cursor position. 982 Note that when using this command in a function or 983 script, the insertion only starts after the function 984 or script is finished. 985 {not in Vi} 986 {not available when compiled without the +ex_extra 987 feature} 988 989 *:stopi* *:stopinsert* 990:stopi[nsert] Stop Insert mode as soon as possible. Works like 991 typing <Esc> in Insert mode. 992 Can be used in an autocommand, example: > 993 :au BufEnter scratch stopinsert 994 995============================================================================== 99610. Inserting a file *inserting-file* 997 998 *:r* *:re* *:read* 999:r[ead] [name] Insert the file [name] (default: current file) below 1000 the cursor. 1001 1002:{range}r[ead] [name] Insert the file [name] (default: current file) below 1003 the specified line. 1004 1005 *:r!* *:read!* 1006:r[ead] !{cmd} Execute {cmd} and insert its standard output below 1007 the cursor. A temporary file is used to store the 1008 output of the command which is then read into the 1009 buffer. 'shellredir' is used to save the output of 1010 the command, which can be set to include stderr or 1011 not. {cmd} is executed like with ":!{cmd}", any '!' 1012 is replaced with the previous command |:!|. 1013 1014These commands insert the contents of a file, or the output of a command, 1015into the buffer. They can be undone. They cannot be repeated with the "." 1016command. They work on a line basis, insertion starts below the line in which 1017the cursor is, or below the specified line. To insert text above the first 1018line use the command ":0r {name}". 1019 1020After the ":read" command, the cursor is left on the first non-blank in the 1021first new line. Unless in Ex mode, then the cursor is left on the last new 1022line (sorry, this is Vi compatible). 1023 1024If a file name is given with ":r", it becomes the alternate file. This can be 1025used, for example, when you want to edit that file instead: ":e! #". This can 1026be switched off by removing the 'a' flag from the 'cpoptions' option. 1027 1028 *file-read* 1029The 'fileformat' option sets the <EOL> style for a file: 1030'fileformat' characters name ~ 1031 "dos" <CR><NL> or <NL> DOS format 1032 "unix" <NL> Unix format 1033 "mac" <CR> Mac format 1034Previously 'textmode' was used. It is obsolete now. 1035 1036If 'fileformat' is "dos", a <CR> in front of an <NL> is ignored and a CTRL-Z 1037at the end of the file is ignored. 1038 1039If 'fileformat' is "mac", a <NL> in the file is internally represented by a 1040<CR>. This is to avoid confusion with a <NL> which is used to represent a 1041<NUL>. See |CR-used-for-NL|. 1042 1043If the 'fileformats' option is not empty Vim tries to recognize the type of 1044<EOL> (see |file-formats|). However, the 'fileformat' option will not be 1045changed, the detected format is only used while reading the file. 1046A similar thing happens with 'fileencodings'. 1047 1048On non-MS-DOS, Win32, and OS/2 systems the message "[dos format]" is shown if 1049a file is read in DOS format, to remind you that something unusual is done. 1050On Macintosh, MS-DOS, Win32, and OS/2 the message "[unix format]" is shown if 1051a file is read in Unix format. 1052On non-Macintosh systems, the message "[Mac format]" is shown if a file is 1053read in Mac format. 1054 1055An example on how to use ":r !": > 1056 :r !uuencode binfile binfile 1057This command reads "binfile", uuencodes it and reads it into the current 1058buffer. Useful when you are editing e-mail and want to include a binary 1059file. 1060 1061 *read-messages* 1062When reading a file Vim will display a message with information about the read 1063file. In the table is an explanation for some of the items. The others are 1064self explanatory. Using the long or the short version depends on the 1065'shortmess' option. 1066 1067 long short meaning ~ 1068 [readonly] {RO} the file is write protected 1069 [fifo/socket] using a stream 1070 [fifo] using a fifo stream 1071 [socket] using a socket stream 1072 [CR missing] reading with "dos" 'fileformat' and a 1073 NL without a preceding CR was found. 1074 [NL found] reading with "mac" 'fileformat' and a 1075 NL was found (could be "unix" format) 1076 [long lines split] at least one line was split in two 1077 [NOT converted] conversion from 'fileencoding' to 1078 'encoding' was desired but not 1079 possible 1080 [converted] conversion from 'fileencoding' to 1081 'encoding' done 1082 [crypted] file was decrypted 1083 [READ ERRORS] not all of the file could be read 1084 1085 1086 vim:tw=78:ts=8:ft=help:norl: 1087