insert.txt (88628B)
1 *insert.txt* Nvim 2 3 4 VIM REFERENCE MANUAL by Bram Moolenaar 5 6 7 *Insert* *Insert-mode* 8 Inserting and replacing text *mode-ins-repl* 9 10 Most of this file is about Insert and Replace mode. At the end are a few 11 commands for inserting text in other ways. 12 13 An overview of the most often used commands can be found in chapter 24 of the 14 user manual |usr_24.txt|. 15 16 Also see 'virtualedit', for moving the cursor to positions where there is no 17 character. Useful for editing a table. 18 19 Type |gO| to see the table of contents. 20 21 ============================================================================== 22 1. Special keys *ins-special-keys* 23 24 In Insert and Replace mode, the following characters have a special meaning; 25 other characters are inserted directly. To insert one of these special 26 characters into the buffer, precede it with CTRL-V. To insert a <Nul> 27 character use "CTRL-V CTRL-@" or "CTRL-V 000". On some systems, you have to 28 use "CTRL-V 003" to insert a CTRL-C. Note: When CTRL-V is mapped you can 29 often use CTRL-Q instead |i_CTRL-Q|. 30 31 If you are working in a special language mode when inserting text, see the 32 'langmap' option, 'langmap', on how to avoid switching this mode on and off 33 all the time. 34 35 char action ~ 36 ----------------------------------------------------------------------- 37 *i_CTRL-[* *i_<Esc>* 38 <Esc> or CTRL-[ End insert or Replace mode, go back to Normal mode. Finish 39 abbreviation. 40 Note: If your <Esc> key is hard to hit, try CTRL-[ instead. 41 *i_META* *i_ALT* 42 ALT (|META|) may act like <Esc> if the chord is not mapped. 43 For example <A-x> acts like <Esc>x if <A-x> does not have an 44 insert-mode mapping. 45 *i_CTRL-C* 46 CTRL-C Quit insert mode, go back to Normal mode. Do not check for 47 abbreviations. Does not trigger the |InsertLeave| autocommand 48 event. 49 50 *i_CTRL-@* 51 CTRL-@ Insert previously inserted text and stop insert. 52 53 *i_CTRL-A* 54 CTRL-A Insert previously inserted text. 55 56 *i_CTRL-H* *i_<BS>* *i_BS* 57 <BS> or CTRL-H Delete the character before the cursor (see |i_backspacing| 58 about joining lines). 59 *i_<Del>* *i_DEL* 60 <Del> Delete the character under the cursor. If the cursor is at 61 the end of the line, and the 'backspace' option includes 62 "eol" (the default), delete the <EOL>; the next line is 63 appended after the current one. 64 *i_CTRL-W* 65 CTRL-W Delete the word before the cursor (see |i_backspacing| about 66 joining lines). See the section "word motions", 67 |word-motions|, for the definition of a word. 68 *i_CTRL-W-default* 69 By default, sets a new undo point before deleting. 70 |default-mappings| 71 *i_CTRL-U* 72 CTRL-U Delete all characters that were entered after starting Insert 73 mode and before the cursor in the current line. 74 If there are no newly entered characters and 'backspace' is 75 not empty, delete all characters before the cursor in the 76 current line. 77 If C-indenting is enabled the indent will be adjusted if the 78 line becomes blank. 79 See |i_backspacing| about joining lines. 80 *i_CTRL-U-default* 81 By default, sets a new undo point before deleting. 82 |default-mappings| 83 *i_CTRL-I* *i_<Tab>* *i_Tab* 84 <Tab> or CTRL-I Insert a tab. If the 'expandtab' option is on, the 85 equivalent number of spaces is inserted (use CTRL-V <Tab> to 86 avoid the expansion; use CTRL-Q <Tab> if CTRL-V is mapped 87 |i_CTRL-Q|). See also the 'smarttab' option and 88 |ins-expandtab|. 89 *i_CTRL-J* *i_<NL>* 90 <NL> or CTRL-J Begin new line. 91 *i_CTRL-M* *i_<CR>* 92 <CR> or CTRL-M Begin new line. 93 *i_CTRL-K* 94 CTRL-K {char1} [char2] 95 Enter digraph (see |digraphs|). When {char1} is a special 96 key, the code for that key is inserted in <> form. For 97 example, the string "<S-Space>" can be entered by typing 98 <C-K><S-Space> (two keys). Neither char is considered for 99 mapping. 100 101 CTRL-N Find next keyword (see |i_CTRL-N|). 102 CTRL-P Find previous keyword (see |i_CTRL-P|). 103 104 CTRL-R {register} *i_CTRL-R* 105 Insert the contents of a register. Between typing CTRL-R and 106 the second character, '"' will be displayed to indicate that 107 you are expected to enter the name of a register. When used 108 with named or clipboard registers (A-Z,a-z,0-9,+) text is 109 inserted literally like pasting with "p". For other registers, 110 the text is inserted as if you typed it, but mappings and 111 abbreviations are not used. If you have options like 112 'textwidth', 'formatoptions', or 'autoindent' set, this will 113 influence what will be inserted. This is different from what 114 happens with the "p" command and pasting with the mouse. 115 Special registers: 116 '"' the unnamed register, containing the text of 117 the last delete or yank 118 '%' the current file name 119 '#' the alternate file name 120 "*" the clipboard contents (X11: primary selection) 121 '+' the clipboard contents 122 '/' the last search pattern 123 ':' the last command-line 124 '.' the last inserted text 125 *i_CTRL-R_-* 126 '-' the last small (less than a line) delete 127 register. This is repeatable using |.| since 128 it remembers the register to put instead of 129 the literal text to insert. 130 *i_CTRL-R_=* 131 '=' the expression register: you are prompted to 132 enter an expression (see |expression|) 133 Note that 0x80 (128 decimal) is used for 134 special keys. E.g., you can use this to move 135 the cursor up: 136 CTRL-R ="\<Up>" 137 you can use this to insert a register as 138 typed with CTRL-R =@reg. 139 Use CTRL-R CTRL-R to insert text literally. 140 When the result is a |List| the items are used 141 as lines. They can have line breaks inside 142 too. 143 When the result is a Float it's automatically 144 converted to a String. 145 When append() or setline() is invoked the undo 146 sequence will be broken. 147 See |registers| about registers. 148 149 CTRL-R CTRL-R {register} *i_CTRL-R_CTRL-R* 150 Insert the contents of a register. Works like using a single 151 CTRL-R, but the text is inserted literally, not as if typed. 152 This differs when the register contains characters like <BS>. 153 Example, where register a contains "ab^Hc": > 154 CTRL-R a results in "ac". 155 CTRL-R CTRL-R a results in "ab^Hc". 156 < Options 'textwidth', 'formatoptions', etc. still apply. If 157 you also want to avoid these, use CTRL-R CTRL-O, see below. 158 The '.' register (last inserted text) is still inserted as 159 typed. 160 After this command, the '.' register contains the text from 161 the register as if it was inserted by typing it. 162 163 CTRL-R CTRL-O {register} *i_CTRL-R_CTRL-O* 164 Insert the contents of a register literally and don't 165 auto-indent. Does the same as pasting with the mouse 166 |<MiddleMouse>|. When the register is linewise this will 167 insert the text above the current line, like with `P`. 168 The '.' register (last inserted text) is still inserted as 169 typed. 170 After this command, the '.' register contains the command 171 typed and not the text. I.e., the literals "^R^O" and not the 172 text from the register. 173 Does not replace characters in |Replace-mode|! 174 175 CTRL-R CTRL-P {register} *i_CTRL-R_CTRL-P* 176 Insert the contents of a register literally and fix the 177 indent, like |[<MiddleMouse>|. 178 The '.' register (last inserted text) is still inserted as 179 typed. 180 After this command, the '.' register contains the command 181 typed and not the text. I.e., the literals "^R^P" and not the 182 text from the register. 183 Does not replace characters in |Replace-mode|! 184 185 *i_CTRL-T* 186 CTRL-T Insert one shiftwidth of indent at the start of the current 187 line. The indent is always rounded to a 'shiftwidth'. 188 *i_CTRL-D* 189 CTRL-D Delete one shiftwidth of indent at the start of the current 190 line. The indent is always rounded to a 'shiftwidth'. 191 192 *i_0_CTRL-D* 193 0 CTRL-D Delete all indent in the current line. 194 195 *i_^_CTRL-D* 196 ^ CTRL-D Delete all indent in the current line. The indent is 197 restored in the next line. This is useful when inserting a 198 label. 199 200 *i_CTRL-V* 201 CTRL-V Insert next non-digit literally. It's also possible to enter 202 the decimal, octal or hexadecimal value of a character 203 |i_CTRL-V_digit|. 204 The characters typed right after CTRL-V are not considered for 205 mapping. 206 For special keys, the CTRL modifier may be included into the 207 key to produce a control character. If there is no control 208 character for the key then its |key-notation| is inserted. 209 Note: When CTRL-V is mapped (e.g., to paste text) you can 210 often use CTRL-Q instead |i_CTRL-Q|. 211 212 *i_CTRL-Q* 213 CTRL-Q Same as CTRL-V. 214 Note: Some terminal connections may eat CTRL-Q, it doesn't 215 work then. It does work in the GUI. 216 217 CTRL-SHIFT-V *i_CTRL-SHIFT-V* *i_CTRL-SHIFT-Q* 218 CTRL-SHIFT-Q Works just like CTRL-V, but do not try to include the CTRL 219 modifier into the key. 220 Note: When CTRL-SHIFT-V is intercepted by your system (e.g., 221 to paste text) you can often use CTRL-SHIFT-Q instead. 222 However, in some terminals (e.g. GNOME Terminal), CTRL-SHIFT-Q 223 quits the terminal without confirmation. 224 225 CTRL-X Enter CTRL-X mode. This is a sub-mode where commands can 226 be given to complete words or scroll the window. See 227 |i_CTRL-X| and |ins-completion|. 228 229 *i_CTRL-E* 230 CTRL-E Insert the character which is below the cursor. 231 *i_CTRL-Y* 232 CTRL-Y Insert the character which is above the cursor. 233 Note that for CTRL-E and CTRL-Y 'textwidth' is not used, to be 234 able to copy characters from a long line. 235 236 *i_CTRL-_* 237 CTRL-_ Switch between insert direction, by toggling 'revins'. 238 239 CTRL-_ moves the cursor to the end of the typed text. 240 241 This command is only available when the 'allowrevins' option 242 is set. 243 Please refer to |rileft.txt| for more information about 244 right-to-left mode. 245 246 *i_CTRL-^* 247 CTRL-^ Toggle the use of typing language characters. 248 When language |:lmap| mappings are defined: 249 - If 'iminsert' is 1 (langmap mappings used) it becomes 0 (no 250 langmap mappings used). 251 - If 'iminsert' has another value it becomes 1, thus langmap 252 mappings are enabled. 253 When no language mappings are defined: 254 - If 'iminsert' is 2 (Input Method used) it becomes 0 (no 255 Input Method used). 256 - If 'iminsert' has another value it becomes 2, thus the Input 257 Method is enabled. 258 When set to 1, the value of the "b:keymap_name" variable, the 259 'keymap' option or "<lang>" appears in the status line. 260 The language mappings are normally used to type characters 261 that are different from what the keyboard produces. The 262 'keymap' option can be used to install a whole number of them. 263 264 *i_CTRL-]* 265 CTRL-] Trigger abbreviation, without inserting a character. 266 267 *i_<Insert>* 268 <Insert> Toggle between Insert and Replace mode. 269 270 ----------------------------------------------------------------------- 271 *i_backspacing* 272 The effect of the <BS>, CTRL-W, and CTRL-U depend on the 'backspace' option 273 (unless 'revins' is set). This is a comma-separated list of items: 274 275 item action ~ 276 indent allow backspacing over autoindent 277 eol allow backspacing over line breaks (join lines) 278 start allow backspacing over the start of insert; CTRL-W and CTRL-U stop 279 once at the start of insert. 280 nostop like start, except CTRL-W and CTRL-U do not stop at the start of 281 insert. 282 283 When 'backspace' is empty, Vi compatible backspacing is used. You cannot 284 backspace over autoindent, before column 1 or before where insert started. 285 286 If the 'backspace' option does contain "eol" and the cursor is in column 1 287 when one of the three keys is used, the current line is joined with the 288 previous line. This effectively deletes the <EOL> in front of the cursor. 289 290 *i_CTRL-V_digit* 291 With CTRL-V the decimal, octal or hexadecimal value of a character can be 292 entered directly. This way you can enter any character, except a line break 293 (<NL>, value 10). There are five ways to enter the character value: 294 295 first char mode max nr of chars max value ~ 296 (none) decimal 3 255 297 o or O octal 3 377 (255) 298 x or X hexadecimal 2 ff (255) 299 u hexadecimal 4 ffff (65535) 300 U hexadecimal 8 7fffffff (2147483647) 301 302 Normally you would type the maximum number of characters. Thus to enter a 303 space (value 32) you would type <C-V>032. You can omit the leading zero, in 304 which case the character typed after the number must be a non-digit. This 305 happens for the other modes as well: As soon as you type a character that is 306 invalid for the mode, the value before it will be used and the "invalid" 307 character is dealt with in the normal way. 308 309 If you enter a value of 10, it will end up in the file as a 0. The 10 is a 310 <NL>, which is used internally to represent the <Nul> character. When writing 311 the buffer to a file, the <NL> character is translated into <Nul>. The <NL> 312 character is written at the end of each line. Thus if you want to insert a 313 <NL> character in a file you will have to make a line break. 314 Also see 'fileformat'. 315 316 *i_CTRL-X* *insert_expand* 317 CTRL-X enters a sub-mode where several commands can be used. Most of these 318 commands do keyword completion; see |ins-completion|. 319 320 Two commands can be used to scroll the window up or down, without exiting 321 insert mode: 322 323 *i_CTRL-X_CTRL-E* 324 CTRL-X CTRL-E scroll window one line up. 325 When doing completion look here: |complete_CTRL-E| 326 327 *i_CTRL-X_CTRL-Y* 328 CTRL-X CTRL-Y scroll window one line down. 329 When doing completion look here: |complete_CTRL-Y| 330 331 After CTRL-X is pressed, each CTRL-E (CTRL-Y) scrolls the window up (down) by 332 one line unless that would cause the cursor to move from its current position 333 in the file. As soon as another key is pressed, CTRL-X mode is exited and 334 that key is interpreted as in Insert mode. 335 336 337 ============================================================================== 338 2. Special special keys *ins-special-special* 339 340 The following keys are special. They stop the current insert, do something, 341 and then restart insertion. This means you can do something without getting 342 out of Insert mode. This is very handy if you prefer to use the Insert mode 343 all the time, just like editors that don't have a separate Normal mode. You 344 can use CTRL-O if you want to map a function key to a command. 345 346 The changes (inserted or deleted characters) before and after these keys can 347 be undone separately. Only the last change can be redone and always behaves 348 like an "i" command. 349 350 char action ~ 351 ----------------------------------------------------------------------- 352 <Up> cursor one line up *i_<Up>* 353 <Down> cursor one line down *i_<Down>* 354 CTRL-G <Up> cursor one line up, insert start column *i_CTRL-G_<Up>* 355 CTRL-G k cursor one line up, insert start column *i_CTRL-G_k* 356 CTRL-G CTRL-K cursor one line up, insert start column *i_CTRL-G_CTRL-K* 357 CTRL-G <Down> cursor one line down, insert start column *i_CTRL-G_<Down>* 358 CTRL-G j cursor one line down, insert start column *i_CTRL-G_j* 359 CTRL-G CTRL-J cursor one line down, insert start column *i_CTRL-G_CTRL-J* 360 <Left> cursor one character left *i_<Left>* 361 <Right> cursor one character right *i_<Right>* 362 <S-Left> cursor one word back (like "b" command) *i_<S-Left>* 363 <C-Left> cursor one word back (like "b" command) *i_<C-Left>* 364 <S-Right> cursor one word forward (like "w" command) *i_<S-Right>* 365 <C-Right> cursor one word forward (like "w" command) *i_<C-Right>* 366 <Home> cursor to first char in the line *i_<Home>* 367 <End> cursor to after last char in the line *i_<End>* 368 <C-Home> cursor to first char in the file *i_<C-Home>* 369 <C-End> cursor to after last char in the file *i_<C-End>* 370 <LeftMouse> cursor to position of mouse click *i_<LeftMouse>* 371 <S-Up> move window one page up *i_<S-Up>* 372 <PageUp> move window one page up *i_<PageUp>* 373 <S-Down> move window one page down *i_<S-Down>* 374 <PageDown> move window one page down *i_<PageDown>* 375 <ScrollWheelDown> move window three lines down *i_<ScrollWheelDown>* 376 <S-ScrollWheelDown> move window one page down *i_<S-ScrollWheelDown>* 377 <ScrollWheelUp> move window three lines up *i_<ScrollWheelUp>* 378 <S-ScrollWheelUp> move window one page up *i_<S-ScrollWheelUp>* 379 <ScrollWheelLeft> move window six columns left *i_<ScrollWheelLeft>* 380 <S-ScrollWheelLeft> move window one page left *i_<S-ScrollWheelLeft>* 381 <ScrollWheelRight> move window six columns right *i_<ScrollWheelRight>* 382 <S-ScrollWheelRight> move window one page right *i_<S-ScrollWheelRight>* 383 CTRL-O execute one command, return to Insert mode *i_CTRL-O* 384 CTRL-\ CTRL-O like CTRL-O but don't move the cursor *i_CTRL-\_CTRL-O* 385 CTRL-G u close undo sequence, start new change *i_CTRL-G_u* 386 CTRL-G U don't start a new undo block with the next *i_CTRL-G_U* 387 left/right cursor movement, if the cursor 388 stays within the same line 389 390 ----------------------------------------------------------------------- 391 392 The CTRL-O command sometimes has a side effect: If the cursor was beyond the 393 end of the line, it will be put on the last character in the line. In 394 mappings it's often better to use <Esc> (first put an "x" in the text, <Esc> 395 will then always put the cursor on it). Or use CTRL-\ CTRL-O, but then 396 beware of the cursor possibly being beyond the end of the line. Note that the 397 command following CTRL-\ CTRL-O can still move the cursor, it is not restored 398 to its original position. 399 400 The CTRL-O command takes you to Normal mode. If you then use a command enter 401 Insert mode again it normally doesn't nest. Thus when typing "a<C-O>a" and 402 then <Esc> takes you back to Normal mode, you do not need to type <Esc> twice. 403 An exception is when not typing the command, e.g. when executing a mapping or 404 sourcing a script. This makes mappings work that briefly switch to Insert 405 mode. 406 407 The shifted cursor keys are not available on all terminals. 408 409 Another side effect is that a count specified before the "i" or "a" command is 410 ignored. That is because repeating the effect of the command after CTRL-O is 411 too complicated. 412 413 An example for using CTRL-G u: > 414 415 :inoremap <C-H> <C-G>u<C-H> 416 417 This redefines the backspace key to start a new undo sequence. You can now 418 undo the effect of the backspace key, without changing what you typed before 419 that, with CTRL-O u. Another example: > 420 421 :inoremap <CR> <C-]><C-G>u<CR> 422 423 This starts a new undo block at each line break. It also expands 424 abbreviations before this. 425 426 An example for using CTRL-G U: > 427 428 inoremap <Left> <C-G>U<Left> 429 inoremap <Right> <C-G>U<Right> 430 inoremap <expr> <Home> col('.') == match(getline('.'), '\S') + 1 ? 431 \ repeat('<C-G>U<Left>', col('.') - 1) : 432 \ (col('.') < match(getline('.'), '\S') ? 433 \ repeat('<C-G>U<Right>', match(getline('.'), '\S') + 0) : 434 \ repeat('<C-G>U<Left>', col('.') - 1 - match(getline('.'), '\S'))) 435 inoremap <expr> <End> repeat('<C-G>U<Right>', col('$') - col('.')) 436 inoremap ( ()<C-G>U<Left> 437 438 This makes it possible to use the cursor keys in Insert mode, without starting 439 a new undo block and therefore using |.| (redo) will work as expected. Also 440 entering a text like (with the "(" mapping from above): 441 442 Lorem ipsum (dolor 443 444 will be repeatable by using |.| to the expected 445 446 Lorem ipsum (dolor) 447 448 449 Using CTRL-O splits undo: the text typed before and after it is undone 450 separately. If you want to avoid this (e.g., in a mapping) you might be able 451 to use CTRL-R = |i_CTRL-R|. E.g., to call a function: > 452 :imap <F2> <C-R>=MyFunc()<CR> 453 454 When the 'whichwrap' option is set appropriately, the <Left> and <Right> 455 keys on the first/last character in the line make the cursor wrap to the 456 previous/next line. 457 458 The CTRL-G j and CTRL-G k commands can be used to insert text in front of a 459 column. Example: > 460 int i; 461 int j; 462 Position the cursor on the first "int", type "istatic <C-G>j ". The 463 result is: > 464 static int i; 465 int j; 466 When inserting the same text in front of the column in every line, use the 467 Visual blockwise command "I" |v_b_I|. 468 469 ============================================================================== 470 3. 'textwidth' and 'wrapmargin' options *ins-textwidth* 471 472 The 'textwidth' option can be used to automatically break a line before it 473 gets too long. Set the 'textwidth' option to the desired maximum line 474 length. If you then type more characters (not spaces or tabs), the 475 last word will be put on a new line (unless it is the only word on the 476 line). If you set 'textwidth' to 0, this feature is disabled. 477 478 The 'wrapmargin' option does almost the same. The difference is that 479 'textwidth' has a fixed width while 'wrapmargin' depends on the width of the 480 screen. When using 'wrapmargin' this is equal to using 'textwidth' with a 481 value equal to (columns - 'wrapmargin'), where columns is the width of the 482 screen. 483 484 When 'textwidth' and 'wrapmargin' are both set, 'textwidth' is used. 485 486 If you don't really want to break the line, but view the line wrapped at a 487 convenient place, see the 'linebreak' option. 488 489 The line is only broken automatically when using Insert mode, or when 490 appending to a line. When in replace mode and the line length is not 491 changed, the line will not be broken. 492 493 Long lines are broken if you enter a non-white character after the margin. 494 The situations where a line will be broken can be restricted by adding 495 characters to the 'formatoptions' option: 496 "l" Only break a line if it was not longer than 'textwidth' when the insert 497 started. 498 "v" Only break at a white character that has been entered during the 499 current insert command. This is mostly Vi-compatible. 500 "lv" Only break if the line was not longer than 'textwidth' when the insert 501 started and only at a white character that has been entered during the 502 current insert command. Only differs from "l" when entering non-white 503 characters while crossing the 'textwidth' boundary. 504 505 Normally an internal function will be used to decide where to break the line. 506 If you want to do it in a different way set the 'formatexpr' option to an 507 expression that will take care of the line break. 508 509 If you want to format a block of text, you can use the "gq" operator. Type 510 "gq" and a movement command to move the cursor to the end of the block. In 511 many cases, the command "gq}" will do what you want (format until the end of 512 paragraph). Alternatively, you can use "gqap", which will format the whole 513 paragraph, no matter where the cursor currently is. Or you can use Visual 514 mode: hit "v", move to the end of the block, and type "gq". See also |gq|. 515 516 ============================================================================== 517 4. 'expandtab', 'softtabstop' and 'smarttab' options *ins-expandtab* 518 519 If the 'expandtab' option is on, spaces will be used to fill the amount of 520 whitespace of the tab. If you want to enter a real <Tab>, type CTRL-V first 521 (use CTRL-Q when CTRL-V is mapped |i_CTRL-Q|). 522 The 'expandtab' option is off by default. Note that in Replace mode, a single 523 character is replaced with several spaces. The result of this is that the 524 number of characters in the line increases. Backspacing will delete one 525 space at a time. The original character will be put back for only one space 526 that you backspace over (the last one). 527 528 *ins-softtabstop* 529 When the 'softtabstop' option is non-zero, a <Tab> inserts 'softtabstop' 530 positions, and a <BS> used to delete white space, will delete 'softtabstop' 531 positions. This feels like 'tabstop' was set to 'softtabstop', but a real 532 <Tab> character still takes 'tabstop' positions, so your file will still look 533 correct when used by other applications. 534 535 If 'softtabstop' is non-zero, a <BS> will try to delete as much white space to 536 move to the previous 'softtabstop' position, except when the previously 537 inserted character is a space, then it will only delete the character before 538 the cursor. Otherwise you cannot always delete a single character before the 539 cursor. You will have to delete 'softtabstop' characters first, and then type 540 extra spaces to get where you want to be. 541 542 *ins-smarttab* 543 When the 'smarttab' option is on, the <Tab> key indents by 'shiftwidth' if the 544 cursor is in leading whitespace. The <BS> key has the opposite effect. This 545 behaves as if 'softtabstop' were set to the value of 'shiftwidth'. This 546 option allows the user to set 'softtabstop' to a value other than 'shiftwidth' 547 and still use the <Tab> key for indentation. 548 549 ============================================================================== 550 5. Replace mode *Replace* *Replace-mode* *mode-replace* 551 552 Enter Replace mode with the "R" command in normal mode. 553 554 In Replace mode, one character in the line is deleted for every character you 555 type. If there is no character to delete (at the end of the line), the 556 typed character is appended (as in Insert mode). Thus the number of 557 characters in a line stays the same until you get to the end of the line. 558 If a <NL> is typed, a line break is inserted and no character is deleted. 559 560 Be careful with <Tab> characters. If you type a normal printing character in 561 its place, the number of characters is still the same, but the number of 562 columns will become smaller. 563 564 If you delete characters in Replace mode (with <BS>, CTRL-W, or CTRL-U), what 565 happens is that you delete the changes. The characters that were replaced 566 are restored. If you had typed past the existing text, the characters you 567 added are deleted. This is effectively a character-at-a-time undo. 568 569 If the 'expandtab' option is on, a <Tab> will replace one character with 570 several spaces. The result of this is that the number of characters in the 571 line increases. Backspacing will delete one space at a time. The original 572 character will be put back for only one space that you backspace over (the 573 last one). 574 575 ============================================================================== 576 6. Virtual Replace mode *vreplace-mode* *Virtual-Replace-mode* 577 578 Enter Virtual Replace mode with the "gR" command in normal mode. 579 580 Virtual Replace mode is similar to Replace mode, but instead of replacing 581 actual characters in the file, you are replacing screen real estate, so that 582 characters further on in the file never appear to move. 583 584 So if you type a <Tab> it may replace several normal characters, and if you 585 type a letter on top of a <Tab> it may not replace anything at all, since the 586 <Tab> will still line up to the same place as before. 587 588 Typing a <NL> still doesn't cause characters later in the file to appear to 589 move. The rest of the current line will be replaced by the <NL> (that is, 590 they are deleted), and replacing continues on the next line. A new line is 591 NOT inserted unless you go past the end of the file. 592 593 Interesting effects are seen when using CTRL-T and CTRL-D. The characters 594 before the cursor are shifted sideways as normal, but characters later in the 595 line still remain still. CTRL-T will hide some of the old line under the 596 shifted characters, but CTRL-D will reveal them again. 597 598 As with Replace mode, using <BS> etc will bring back the characters that were 599 replaced. This still works in conjunction with 'smartindent', CTRL-T and 600 CTRL-D, 'expandtab', 'smarttab', 'softtabstop', etc. 601 602 In 'list' mode, Virtual Replace mode acts as if it was not in 'list' mode, 603 unless "L" is in 'cpoptions'. 604 605 Note that the only situations for which characters beyond the cursor should 606 appear to move are in List mode 'list', and occasionally when 'wrap' is set 607 (and the line changes length to become shorter or wider than the width of the 608 screen). In other cases spaces may be inserted to avoid following characters 609 to move. 610 611 This mode is very useful for editing <Tab> separated columns in tables, for 612 entering new data while keeping all the columns aligned. 613 614 ============================================================================== 615 7. Insert mode completion *ins-completion* 616 617 In Insert and Replace mode, there are several commands to complete part of a 618 keyword or line that has been typed. This is useful if you are using 619 complicated keywords (e.g., function names with capitals and underscores). 620 621 Completion can be done for: 622 623 1. Whole lines |i_CTRL-X_CTRL-L| 624 2. keywords in the current file |i_CTRL-X_CTRL-N| 625 3. keywords in 'dictionary' |i_CTRL-X_CTRL-K| 626 4. keywords in 'thesaurus', thesaurus-style |i_CTRL-X_CTRL-T| 627 5. keywords in the current and included files |i_CTRL-X_CTRL-I| 628 6. tags |i_CTRL-X_CTRL-]| 629 7. file names |i_CTRL-X_CTRL-F| 630 8. definitions or macros |i_CTRL-X_CTRL-D| 631 9. Vim command-line |i_CTRL-X_CTRL-V| 632 10. User defined completion |i_CTRL-X_CTRL-U| 633 11. omni completion |i_CTRL-X_CTRL-O| 634 12. Spelling suggestions |i_CTRL-X_s| 635 13. completions from 'complete' |i_CTRL-N| |i_CTRL-P| 636 14. contents from registers |i_CTRL-X_CTRL-R| 637 638 Additionally, |i_CTRL-X_CTRL-Z| stops completion without changing the text. 639 640 All these, except CTRL-N and CTRL-P, are done in CTRL-X mode. This is a 641 sub-mode of Insert and Replace modes. You enter CTRL-X mode by typing CTRL-X 642 and one of the CTRL-X commands. You exit CTRL-X mode by typing a key that is 643 not a valid CTRL-X mode command. Valid keys are the CTRL-X command itself, 644 CTRL-N (next), and CTRL-P (previous). 645 646 By default, the possible completions are showed in a menu and the first 647 completion is inserted into the text. This can be adjusted with 648 'completeopt'. 649 650 To get the current completion information, |complete_info()| can be used. 651 Also see the 'infercase' option if you want to adjust the case of the match. 652 653 When inserting a selected candidate word from the |popup-menu|, the part of 654 the candidate word that does not match the query is highlighted using 655 |hl-ComplMatchIns|. If fuzzy is enabled in 'completeopt', highlighting will 656 not be applied. 657 658 *complete_CTRL-E* 659 When completion is active you can use CTRL-E to stop it and go back to the 660 originally typed text. The CTRL-E will not be inserted. 661 662 *complete_CTRL-Y* 663 When the popup menu is displayed, CTRL-Y stops completion and accepts the 664 currently selected entry. Typing a space, Enter, or some other unprintable 665 character will leave completion mode and insert that typed character. If you 666 want to use <Enter> to accept a completion item, use this mapping: >vim 667 inoremap <expr> <cr> pumvisible() ? '<c-y>' : '<cr>' 668 669 When the popup menu is displayed there are a few more special keys, see 670 |popupmenu-keys|. 671 672 Note: The keys that are valid in CTRL-X mode are not mapped. This allows for 673 `:map <C-F> <C-X><C-F>` to work. The key that ends CTRL-X mode (any key that 674 is not a valid CTRL-X mode command) is mapped. Also, when doing completion 675 with 'complete' mappings apply as usual. 676 677 *E565* 678 Note: While completion is active Insert mode can't be used recursively and 679 buffer text cannot be changed. Mappings that somehow invoke ":normal i.." 680 will generate an E565 error. 681 682 The following mappings are suggested to make typing the completion commands 683 a bit easier (although they will hide other commands): > 684 :inoremap <C-]> <C-X><C-]> 685 :inoremap <C-F> <C-X><C-F> 686 :inoremap <C-D> <C-X><C-D> 687 :inoremap <C-L> <C-X><C-L> 688 689 As a special case, typing CTRL-R to perform register insertion (see 690 |i_CTRL-R|) will not exit CTRL-X mode. This is primarily to allow the use of 691 the '=' register to call some function to determine the next operation. If 692 the contents of the register (or result of the '=' register evaluation) are 693 not valid CTRL-X mode keys, then CTRL-X mode will be exited as if those keys 694 had been typed. 695 696 For example, the following will map <Tab> to either actually insert a <Tab> if 697 the current line is currently only whitespace, or start/continue a CTRL-N 698 completion operation: > 699 700 function! CleverTab() 701 if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$' 702 return "\<Tab>" 703 else 704 return "\<C-N>" 705 endif 706 endfunction 707 inoremap <Tab> <C-R>=CleverTab()<CR> 708 709 710 711 Completing whole lines *compl-whole-line* 712 713 *i_CTRL-X_CTRL-L* 714 CTRL-X CTRL-L Search backwards for a line that starts with the 715 same characters as those in the current line before 716 the cursor. Indent is ignored. The matching line is 717 inserted in front of the cursor. 718 The 'complete' option is used to decide which buffers 719 are searched for a match. Both loaded and unloaded 720 buffers are used. 721 CTRL-L or 722 CTRL-P Search backwards for next matching line. This line 723 replaces the previous matching line. 724 725 CTRL-N Search forward for next matching line. This line 726 replaces the previous matching line. 727 728 CTRL-X CTRL-L After expanding a line you can additionally get the 729 line next to it by typing CTRL-X CTRL-L again, unless 730 a double CTRL-X is used. Only works for loaded 731 buffers. 732 733 Completing keywords in current file *compl-current* 734 735 *i_CTRL-X_CTRL-P* 736 *i_CTRL-X_CTRL-N* 737 CTRL-X CTRL-N Search forwards for words that start with the keyword 738 in front of the cursor. The found keyword is inserted 739 in front of the cursor. 740 741 CTRL-X CTRL-P Search backwards for words that start with the keyword 742 in front of the cursor. The found keyword is inserted 743 in front of the cursor. 744 745 CTRL-N Search forward for next matching keyword. This 746 keyword replaces the previous matching keyword. 747 748 CTRL-P Search backwards for next matching keyword. This 749 keyword replaces the previous matching keyword. 750 751 CTRL-X CTRL-N or 752 CTRL-X CTRL-P Further use of CTRL-X CTRL-N or CTRL-X CTRL-P will 753 copy the words following the previous expansion in 754 other contexts unless a double CTRL-X is used. 755 756 If there is a keyword in front of the cursor (a name made out of alphabetic 757 characters and characters in 'iskeyword'), it is used as the search pattern, 758 with "\<" prepended (meaning: start of a word). Otherwise "\<\k\k" is used 759 as search pattern (start of any keyword of at least two characters). 760 761 In Replace mode, the number of characters that are replaced depends on the 762 length of the matched string. This works like typing the characters of the 763 matched string in Replace mode. 764 765 If there is not a valid keyword character before the cursor, any keyword of 766 at least two characters is matched. 767 e.g., to get: 768 printf("(%g, %g, %g)", vector[0], vector[1], vector[2]); 769 just type: 770 printf("(%g, %g, %g)", vector[0], ^P[1], ^P[2]); 771 772 The search wraps around the end of the file, the value of 'wrapscan' is not 773 used here. 774 775 Multiple repeats of the same completion are skipped; thus a different match 776 will be inserted at each CTRL-N and CTRL-P (unless there is only one 777 matching keyword). 778 779 Single character matches are never included, as they usually just get in 780 the way of what you were really after. 781 e.g., to get: 782 printf("name = %s\n", name); 783 just type: 784 printf("name = %s\n", n^P); 785 or even: 786 printf("name = %s\n", ^P); 787 The 'n' in '\n' is skipped. 788 789 After expanding a word, you can use CTRL-X CTRL-P or CTRL-X CTRL-N to get the 790 word following the expansion in other contexts. These sequences search for 791 the text just expanded and further expand by getting an extra word. This is 792 useful if you need to repeat a sequence of complicated words. Although CTRL-P 793 and CTRL-N look just for strings of at least two characters, CTRL-X CTRL-P and 794 CTRL-X CTRL-N can be used to expand words of just one character. 795 e.g., to get: 796 México 797 you can type: 798 M^N^P^X^P^X^P 799 CTRL-N starts the expansion and then CTRL-P takes back the single character 800 "M", the next two CTRL-X CTRL-P's get the words "é" and ";xico". 801 802 If the previous expansion was split, because it got longer than 'textwidth', 803 then just the text in the current line will be used. 804 805 If the match found is at the end of a line, then the first word in the next 806 line will be inserted and the message "Word from other line" displayed, if 807 this word is accepted the next CTRL-X CTRL-P or CTRL-X CTRL-N will search 808 for those lines starting with this word. 809 810 811 Completing keywords in 'dictionary' *compl-dictionary* 812 813 *i_CTRL-X_CTRL-K* 814 CTRL-X CTRL-K Search the files given with the 'dictionary' option 815 for words that start with the keyword in front of the 816 cursor. This is like CTRL-N, but only the dictionary 817 files are searched, not the current file. The found 818 keyword is inserted in front of the cursor. This 819 could potentially be pretty slow, since all matches 820 are found before the first match is used. By default, 821 the 'dictionary' option is empty. 822 For suggestions where to find a list of words, see the 823 'dictionary' option. 824 'ignorecase', 'smartcase' and 'infercase' apply. 825 826 CTRL-K or 827 CTRL-N Search forward for next matching keyword. This 828 keyword replaces the previous matching keyword. 829 830 CTRL-P Search backwards for next matching keyword. This 831 keyword replaces the previous matching keyword. 832 833 834 Completing words in 'thesaurus' *compl-thesaurus* 835 836 *i_CTRL-X_CTRL-T* 837 CTRL-X CTRL-T Works as CTRL-X CTRL-K, but in a special way. It uses 838 the 'thesaurus' option instead of 'dictionary'. If a 839 match is found in the thesaurus file, all the 840 remaining words on the same line are included as 841 matches, even though they don't complete the word. 842 Thus a word can be completely replaced. 843 844 CTRL-T or 845 CTRL-N Search forward for next matching keyword. This 846 keyword replaces the previous matching keyword. 847 848 CTRL-P Search backwards for next matching keyword. This 849 keyword replaces the previous matching keyword. 850 851 In the file used by the 'thesaurus' option each line in the file should 852 contain words with similar meaning, separated by non-keyword characters (white 853 space is preferred). Maximum line length is 510 bytes. 854 855 For an example, imagine the 'thesaurus' file has a line like this: > 856 angry furious mad enraged 857 Placing the cursor after the letters "ang" and typing CTRL-X CTRL-T would 858 complete the word "angry"; subsequent presses would change the word to 859 "furious", "mad" etc. 860 861 Other uses include translation between two languages, or grouping API 862 functions by keyword. 863 864 An English word list was added to this github issue: 865 https://github.com/vim/vim/issues/629#issuecomment-443293282 866 Unpack thesaurus_pkg.zip, put the thesaurus.txt file somewhere, e.g. 867 ~/.vim/thesaurus/english.txt, and the 'thesaurus' option to this file name. 868 869 870 Completing keywords with 'thesaurusfunc' *compl-thesaurusfunc* 871 872 If the 'thesaurusfunc' option is set, then the user specified function is 873 invoked to get the list of completion matches and the 'thesaurus' option is 874 not used. See |complete-functions| for an explanation of how the function is 875 invoked and what it should return. 876 877 Here is an example that uses the "aiksaurus" command (provided by Magnus 878 Groß): > 879 880 func Thesaur(findstart, base) 881 if a:findstart 882 return searchpos('\<', 'bnW', line('.'))[1] - 1 883 endif 884 let res = [] 885 let h = '' 886 for l in systemlist('aiksaurus ' .. shellescape(a:base)) 887 if l[:3] == '=== ' 888 let h = '(' .. substitute(l[4:], ' =*$', ')', '') 889 elseif l ==# 'Alphabetically similar known words are: ' 890 let h = "\U0001f52e" 891 elseif l[0] =~ '\a' || (h ==# "\U0001f52e" && l[0] ==# "\t") 892 call extend(res, map(split(substitute(l, '^\t', '', ''), ', '), {_, val -> {'word': val, 'menu': h}})) 893 endif 894 endfor 895 return res 896 endfunc 897 898 if exists('+thesaurusfunc') 899 set thesaurusfunc=Thesaur 900 endif 901 902 903 Completing keywords in the current and included files *compl-keyword* 904 905 The 'include' option is used to specify a line that contains an include file 906 name. The 'path' option is used to search for include files. 907 908 *i_CTRL-X_CTRL-I* 909 CTRL-X CTRL-I Search for the first keyword in the current and 910 included files that starts with the same characters 911 as those before the cursor. The matched keyword is 912 inserted in front of the cursor. 913 914 CTRL-N Search forwards for next matching keyword. This 915 keyword replaces the previous matching keyword. 916 Note: CTRL-I is the same as <Tab>, which is likely to 917 be typed after a successful completion, therefore 918 CTRL-I is not used for searching for the next match. 919 920 CTRL-P Search backward for previous matching keyword. This 921 keyword replaces the previous matching keyword. 922 923 CTRL-X CTRL-I Further use of CTRL-X CTRL-I will copy the words 924 following the previous expansion in other contexts 925 unless a double CTRL-X is used. 926 927 Completing tags *compl-tag* 928 *i_CTRL-X_CTRL-]* 929 CTRL-X CTRL-] Search for the first tag that starts with the same 930 characters as before the cursor. The matching tag is 931 inserted in front of the cursor. Alphabetic 932 characters and characters in 'iskeyword' are used 933 to decide which characters are included in the tag 934 name (same as for a keyword). See also |CTRL-]|. 935 The 'showfulltag' option can be used to add context 936 from around the tag definition. 937 CTRL-] or 938 CTRL-N Search forwards for next matching tag. This tag 939 replaces the previous matching tag. 940 941 CTRL-P Search backward for previous matching tag. This tag 942 replaces the previous matching tag. 943 944 945 Completing file names *compl-filename* 946 *i_CTRL-X_CTRL-F* 947 CTRL-X CTRL-F Search for the first file name that starts with the 948 same characters as before the cursor. The matching 949 file name is inserted in front of the cursor. 950 Alphabetic characters and characters in 'isfname' 951 are used to decide which characters are included in 952 the file name. Note: the 'path' option is not used 953 here (yet). 954 CTRL-F or 955 CTRL-N Search forwards for next matching file name. This 956 file name replaces the previous matching file name. 957 958 CTRL-P Search backward for previous matching file name. 959 This file name replaces the previous matching file 960 name. 961 962 963 Completing definitions or macros *compl-define* 964 965 The 'define' option is used to specify a line that contains a definition. 966 The 'include' option is used to specify a line that contains an include file 967 name. The 'path' option is used to search for include files. 968 969 *i_CTRL-X_CTRL-D* 970 CTRL-X CTRL-D Search in the current and included files for the 971 first definition (or macro) name that starts with 972 the same characters as before the cursor. The found 973 definition name is inserted in front of the cursor. 974 CTRL-D or 975 CTRL-N Search forwards for next matching macro name. This 976 macro name replaces the previous matching macro 977 name. 978 979 CTRL-P Search backward for previous matching macro name. 980 This macro name replaces the previous matching macro 981 name. 982 983 CTRL-X CTRL-D Further use of CTRL-X CTRL-D will copy the words 984 following the previous expansion in other contexts 985 unless a double CTRL-X is used. 986 987 988 Completing Vim commands *compl-vim* 989 990 Completion is context-sensitive. It works like on the Command-line. It 991 completes an Ex command as well as its arguments. This is useful when writing 992 a Vim script. 993 994 *i_CTRL-X_CTRL-V* 995 CTRL-X CTRL-V Guess what kind of item is in front of the cursor and 996 find the first match for it. 997 Note: When CTRL-V is mapped you can often use CTRL-Q 998 instead of |i_CTRL-Q|. 999 CTRL-V or 1000 CTRL-N Search forwards for next match. This match replaces 1001 the previous one. 1002 1003 CTRL-P Search backwards for previous match. This match 1004 replaces the previous one. 1005 1006 CTRL-X CTRL-V Further use of CTRL-X CTRL-V will do the same as 1007 CTRL-V. This allows mapping a key to do Vim command 1008 completion, for example: > 1009 :imap <Tab> <C-X><C-V> 1010 1011 Completing contents from registers *compl-register-words* 1012 *i_CTRL-X_CTRL-R* 1013 CTRL-X CTRL-R Guess what kind of item is in front of the cursor from 1014 all registers and find the first match for it. 1015 Further use of CTRL-R (without CTRL-X) will insert the 1016 register content, see |i_CTRL-R|. 1017 'ignorecase' applies to the matching. 1018 1019 CTRL-N Search forwards for next match. This match replaces 1020 the previous one. 1021 1022 CTRL-P Search backwards for previous match. This match 1023 replaces the previous one. 1024 1025 CTRL-X CTRL-R Further use of CTRL-X CTRL-R will copy the line 1026 following the previous expansion in other contexts 1027 unless a double CTRL-X is used (e.g. this switches 1028 from completing register words to register contents). 1029 1030 User defined completion *compl-function* 1031 1032 Completion is done by a function that can be defined by the user with the 1033 'completefunc' option. See below for how the function is called and an 1034 example |complete-functions|. 1035 1036 *i_CTRL-X_CTRL-U* 1037 CTRL-X CTRL-U Guess what kind of item is in front of the cursor and 1038 find the first match for it. 1039 CTRL-U or 1040 CTRL-N Use the next match. This match replaces the previous 1041 one. 1042 1043 CTRL-P Use the previous match. This match replaces the 1044 previous one. 1045 1046 1047 Omni completion *omnicompletion* *compl-omni* 1048 1049 Completion is done by a function that can be defined by the user with the 1050 'omnifunc' option. This is to be used for filetype-specific completion. 1051 1052 See below for how the function is called and an example |complete-functions|. 1053 For remarks about specific filetypes see |compl-omni-filetypes|. 1054 More completion scripts will appear, check www.vim.org. Currently there is a 1055 first version for C++. 1056 1057 *i_CTRL-X_CTRL-O* 1058 CTRL-X CTRL-O Guess what kind of item is in front of the cursor and 1059 find the first match for it. 1060 CTRL-O or 1061 CTRL-N Use the next match. This match replaces the previous 1062 one. 1063 1064 CTRL-P Use the previous match. This match replaces the 1065 previous one. 1066 1067 1068 Spelling suggestions *compl-spelling* 1069 1070 A word before or at the cursor is located and correctly spelled words are 1071 suggested to replace it. If there is a badly spelled word in the line, before 1072 or under the cursor, the cursor is moved to after it. Otherwise the word just 1073 before the cursor is used for suggestions, even though it isn't badly spelled. 1074 1075 NOTE: CTRL-S suspends display in many Unix terminals. Use 's' instead. Type 1076 CTRL-Q to resume displaying. 1077 1078 *i_CTRL-X_CTRL-S* *i_CTRL-X_s* 1079 CTRL-X CTRL-S or 1080 CTRL-X s Locate the word in front of the cursor and find the 1081 first spell suggestion for it. 1082 CTRL-S or 1083 CTRL-N Use the next suggestion. This replaces the previous 1084 one. Note that you can't use 's' here. 1085 1086 CTRL-P Use the previous suggestion. This replaces the 1087 previous one. 1088 1089 1090 Completing from different sources *compl-generic* 1091 1092 *i_CTRL-N* 1093 CTRL-N Find the next match for a word ending at the cursor, 1094 using the sources specified in the 'complete' option. 1095 All sources complete from keywords, except functions, 1096 which may complete from non-keyword. The matched 1097 text is inserted before the cursor. 1098 1099 *i_CTRL-P* 1100 CTRL-P Same as CTRL-N, but find the previous match. 1101 1102 CTRL-N Search forward through the matches and insert the 1103 next one. 1104 1105 CTRL-P Search backward through the matches and insert the 1106 previous one. 1107 1108 CTRL-X CTRL-N or 1109 CTRL-X CTRL-P Further use of CTRL-X CTRL-N or CTRL-X CTRL-P will 1110 copy the words following the previous expansion in 1111 other contexts unless a double CTRL-X is used. 1112 1113 1114 Stop completion *compl-stop* 1115 1116 *i_CTRL-X_CTRL-Z* 1117 CTRL-X CTRL-Z Stop completion without changing the text. 1118 1119 1120 AUTOCOMPLETION *ins-autocompletion* 1121 1122 Vim can display a completion menu as you type, similar to using |i_CTRL-N|, 1123 but triggered automatically. See 'autocomplete'. The menu items are 1124 collected from the sources listed in the 'complete' option, in order. 1125 1126 A decaying timeout keeps Vim responsive. Sources earlier in the 'complete' 1127 list get more time (higher priority), but all sources receive at least a small 1128 time slice. 1129 1130 This mode is fully compatible with other completion modes. You can invoke 1131 any of them at any time by typing |CTRL-X|, which temporarily suspends 1132 autocompletion. To use |i_CTRL-N| or |i_CTRL-X_CTRL-N| specifically, press 1133 |CTRL-E| first to dismiss the popup menu (see |complete_CTRL-E|). 1134 1135 *ins-autocompletion-example* 1136 Example setup ~ 1137 A typical configuration for automatic completion with a popup menu: > 1138 set autocomplete 1139 set complete=.^5,w^5,b^5,u^5 1140 set completeopt=popup 1141 1142 inoremap <silent><expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>" 1143 inoremap <silent><expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>" 1144 < 1145 This enables automatic completion with suggestions from the current buffer, 1146 other windows, and listed buffers, displayed in a popup menu. Each source is 1147 limited to 5 candidates. <Tab> and <S-Tab> move through the items when the 1148 menu is visible. Optionally, add "preinsert" to 'completeopt' to insert the 1149 longest common prefix automatically. You can also add other completion 1150 sources to 'complete' as needed. 1151 1152 See also 'autocomplete', 'autocompletedelay' and 'autocompletetimeout'. 1153 1154 For command-line autocompletion, see |cmdline-autocompletion|. 1155 1156 To get LSP-driven auto-completion, see |lsp-completion|. 1157 1158 1159 FUNCTIONS FOR FINDING COMPLETIONS *complete-functions* 1160 1161 This applies to 'completefunc', 'thesaurusfunc' and 'omnifunc'. 1162 1163 The function is called in two different ways: 1164 - First the function is called to find the start of the text to be completed. 1165 - Later the function is called to actually find the matches. 1166 1167 On the first invocation the arguments are: 1168 a:findstart 1 1169 a:base empty 1170 1171 The function must return the column where the completion starts. It must be a 1172 number between zero and the cursor column "col('.')". This involves looking 1173 at the characters just before the cursor and including those characters that 1174 could be part of the completed item. The text between this column and the 1175 cursor column will be replaced with the matches. If the returned value is 1176 larger than the cursor column, the cursor column is used. 1177 1178 Negative return values: 1179 -2 To cancel silently and stay in completion mode. 1180 -3 To cancel silently and leave completion mode. 1181 Another negative value: completion starts at the cursor column 1182 1183 On the second invocation the arguments are: 1184 a:findstart 0 1185 a:base the text with which matches should match; the text that was 1186 located in the first call (can be empty) 1187 1188 The function must return a List with the matching words. These matches 1189 usually include the "a:base" text. When there are no matches return an empty 1190 List. Note that the cursor may have moved since the first invocation, the 1191 text may have been changed. 1192 1193 In order to return more information than the matching words, return a Dict 1194 that contains the List. The Dict can have these items: 1195 words The List of matching words (mandatory). 1196 refresh A string to control re-invocation of the function 1197 (optional). 1198 The only value currently recognized is "always", the 1199 effect is that the function is called whenever the 1200 leading text is changed. 1201 Other items are ignored. 1202 1203 For acting upon end of completion, see the |CompleteDonePre| and 1204 |CompleteDone| autocommand event. 1205 1206 For example, the function can contain this: > 1207 let matches = ... list of words ... 1208 return {'words': matches, 'refresh': 'always'} 1209 < 1210 If looking for matches is time-consuming, |complete_check()| may be used to 1211 maintain responsiveness. 1212 1213 *complete-items* 1214 Each list item can either be a string or a Dictionary. When it is a string it 1215 is used as the completion. When it is a Dictionary it can contain these 1216 items: 1217 word the text that will be inserted, mandatory 1218 abbr abbreviation of "word"; when not empty it is used in 1219 the menu instead of "word" 1220 menu extra text for the popup menu, displayed after "word" 1221 or "abbr" 1222 info more information about the item, can be displayed in a 1223 preview window 1224 kind single letter indicating the type of completion 1225 icase when non-zero case is to be ignored when comparing 1226 items to be equal; when omitted zero is used, thus 1227 items that only differ in case are added 1228 equal when non-zero, always treat this item to be equal when 1229 comparing. Which means, "equal=1" disables filtering 1230 of this item. 1231 dup when non-zero this match will be added even when an 1232 item with the same word is already present. 1233 empty when non-zero this match will be added even when it is 1234 an empty string 1235 user_data custom data which is associated with the item and 1236 available in |v:completed_item|; it can be any type; 1237 defaults to an empty string 1238 abbr_hlgroup an additional highlight group whose attributes are 1239 combined with |hl-PmenuSel| and |hl-Pmenu| or 1240 |hl-PmenuMatchSel| and |hl-PmenuMatch| highlight 1241 attributes in the popup menu to apply cterm and gui 1242 properties (with higher priority) like strikethrough 1243 to the completion items abbreviation 1244 kind_hlgroup an additional highlight group specifically for setting 1245 the highlight attributes of the completion kind. When 1246 this field is present, it will override the 1247 |hl-PmenuKind| highlight group, allowing for the 1248 customization of ctermfg and guifg properties for the 1249 completion kind 1250 match See "matches" in |complete_info()|. 1251 1252 All of these except "icase", "equal", "dup" and "empty" must be a string. If 1253 an item does not meet these requirements then an error message is given and 1254 further items in the list are not used. You can mix string and Dictionary 1255 items in the returned list. 1256 1257 The "menu" item is used in the popup menu and may be truncated, thus it should 1258 be relatively short. The "info" item can be longer, it will be displayed in 1259 the preview window when "preview" appears in 'completeopt'. The "info" item 1260 will also remain displayed after the popup menu has been removed. This is 1261 useful for function arguments. Use a single space for "info" to remove 1262 existing text in the preview window. The size of the preview window is three 1263 lines, but 'previewheight' is used when it has a value of 1 or 2. 1264 1265 The "kind" item uses a single letter to indicate the kind of completion. This 1266 may be used to show the completion differently (different color or icon). 1267 Currently these types can be used: 1268 v variable 1269 f function or method 1270 m member of a struct or class 1271 t typedef 1272 d #define or macro 1273 1274 When searching for matches takes some time call |complete_add()| to add each 1275 match to the total list. These matches should then not appear in the returned 1276 list! Call |complete_check()| now and then to allow the user to press a key 1277 while still searching for matches. Stop searching when it returns non-zero. 1278 1279 *E840* 1280 The function is allowed to move the cursor, it is restored afterwards. 1281 The function is not allowed to move to another window or delete text. 1282 1283 An example that completes the names of the months: > 1284 fun! CompleteMonths(findstart, base) 1285 if a:findstart 1286 " locate the start of the word 1287 let line = getline('.') 1288 let start = col('.') - 1 1289 while start > 0 && line[start - 1] =~ '\a' 1290 let start -= 1 1291 endwhile 1292 return start 1293 else 1294 " find months matching with "a:base" 1295 let res = [] 1296 for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") 1297 if m =~ '^' .. a:base 1298 call add(res, m) 1299 endif 1300 endfor 1301 return res 1302 endif 1303 endfun 1304 set completefunc=CompleteMonths 1305 < 1306 The same, but now pretending searching for matches is slow: > 1307 fun! CompleteMonths(findstart, base) 1308 if a:findstart 1309 " locate the start of the word 1310 let line = getline('.') 1311 let start = col('.') - 1 1312 while start > 0 && line[start - 1] =~ '\a' 1313 let start -= 1 1314 endwhile 1315 return start 1316 else 1317 " find months matching with "a:base" 1318 for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") 1319 if m =~ '^' .. a:base 1320 call complete_add(m) 1321 endif 1322 sleep 300m " simulate searching for next match 1323 if complete_check() 1324 break 1325 endif 1326 endfor 1327 return [] 1328 endif 1329 endfun 1330 set completefunc=CompleteMonths 1331 < 1332 1333 INSERT COMPLETION POPUP MENU *ins-completion-menu* 1334 *popupmenu-completion* 1335 Vim can display the matches in a simplistic popup menu. 1336 1337 The menu is used when: 1338 - The 'completeopt' option contains "menu" or "menuone". 1339 - The terminal supports at least 8 colors. 1340 - There are at least two matches. One if "menuone" is used. 1341 1342 The 'pumheight' option can be used to set a maximum height. The default is to 1343 use all space available. 1344 The 'pumwidth' option can be used to set a minimum width. The default is 15 1345 characters. 1346 1347 *compl-states* 1348 There are three states: 1349 1. A complete match has been inserted, e.g., after using CTRL-N or CTRL-P. 1350 2. A cursor key has been used to select another match. The match was not 1351 inserted then, only the entry in the popup menu is highlighted. 1352 3. Only part of a match has been inserted and characters were typed or the 1353 backspace key was used. The list of matches was then adjusted for what is 1354 in front of the cursor. 1355 1356 You normally start in the first state, with the first match being inserted. 1357 When "longest" is in 'completeopt' and there is more than one match you start 1358 in the third state. 1359 1360 If you select another match, e.g., with CTRL-N or CTRL-P, you go to the first 1361 state. This doesn't change the list of matches. 1362 1363 When you are back at the original text then you are in the third state. To 1364 get there right away you can use a mapping that uses CTRL-P right after 1365 starting the completion: > 1366 :imap <F7> <C-N><C-P> 1367 < 1368 *popupmenu-keys* 1369 In the first state these keys have a special meaning: 1370 <BS> and CTRL-H Delete one character, find the matches for the word before 1371 the cursor. This reduces the list of matches, often to one 1372 entry, and switches to the second state. 1373 When 'autocomplete' is active, clears the selected item in 1374 the menu. 1375 Any non-special character: 1376 Stop completion without changing the match and insert the 1377 typed character. 1378 1379 In the second and third state these keys have a special meaning: 1380 <BS> and CTRL-H Delete one character, find the matches for the shorter word 1381 before the cursor. This may find more matches. 1382 When 'autocomplete' is active, clears the selected item in 1383 the menu. 1384 CTRL-L Add one character from the current match, may reduce the 1385 number of matches. 1386 any printable, non-white character: 1387 Add this character and reduce the number of matches. 1388 1389 In all three states these can be used: 1390 CTRL-Y Yes: Accept the currently selected match and stop 1391 completion. 1392 CTRL-E End completion, go back to what was there before selecting a 1393 match (what was typed or longest common string). 1394 <PageUp> Select a match several entries back, but don't insert it. 1395 <PageDown> Select a match several entries further, but don't insert it. 1396 <Up> Select the previous match, as if CTRL-P was used, but don't 1397 insert it. 1398 <Down> Select the next match, as if CTRL-N was used, but don't 1399 insert it. 1400 <Space> or <Tab> Stop completion without changing the match and insert the 1401 typed character. 1402 1403 The behavior of the <Enter> key depends on the state you are in: 1404 first state: Use the text as it is and insert a line break. 1405 second state: Insert the currently selected match. 1406 third state: Use the text as it is and insert a line break. 1407 1408 In other words: If you used the cursor keys to select another entry in the 1409 list of matches then the <Enter> key inserts that match. If you typed 1410 something else then <Enter> inserts a line break. 1411 1412 1413 The colors of the menu can be changed with these highlight groups: 1414 Pmenu normal item |hl-Pmenu| 1415 PmenuSel selected item |hl-PmenuSel| 1416 PmenuSbar scrollbar |hl-PmenuSbar| 1417 PmenuThumb thumb of the scrollbar |hl-PmenuThumb| 1418 1419 There are no special mappings for when the popup menu is visible. However, 1420 you can use an Insert mode mapping that checks the |pumvisible()| function to 1421 do something different. Example: > 1422 :inoremap <Down> <C-R>=pumvisible() ? "\<lt>C-N>" : "\<lt>Down>"<CR> 1423 1424 You can use of <expr> in mapping to have the popup menu used when typing a 1425 character and some condition is met. For example, for typing a dot: > 1426 inoremap <expr> . MayComplete() 1427 func MayComplete() 1428 if (can complete) 1429 return ".\<C-X>\<C-O>" 1430 endif 1431 return '.' 1432 endfunc 1433 1434 See |:map-<expr>| for more info. 1435 1436 1437 FILETYPE-SPECIFIC REMARKS FOR OMNI COMPLETION *compl-omni-filetypes* 1438 1439 The file used for {filetype} should be autoload/{filetype}complete.vim 1440 in 'runtimepath'. Thus for "java" it is autoload/javacomplete.vim. 1441 1442 1443 C *ft-c-omni* 1444 1445 Completion of C code requires a tags file. You should use Universal/ 1446 Exuberant ctags, because it adds extra information that is needed for 1447 completion. You can find it here: 1448 Universal Ctags: https://ctags.io 1449 1450 Universal Ctags is preferred, Exuberant Ctags is no longer maintained. 1451 1452 If you want to complete system functions you can do something like this. Use 1453 ctags to generate a tags file for all the system header files: > 1454 % ctags -R -f ~/.config/nvim/systags /usr/include /usr/local/include 1455 In your vimrc file add this tags file to the 'tags' option: > 1456 set tags+=~/.config/nvim/systags 1457 1458 When using CTRL-X CTRL-O after a name without any "." or "->" it is completed 1459 from the tags file directly. This works for any identifier, also function 1460 names. If you want to complete a local variable name, which does not appear 1461 in the tags file, use CTRL-P instead. 1462 1463 When using CTRL-X CTRL-O after something that has "." or "->" Vim will attempt 1464 to recognize the type of the variable and figure out what members it has. 1465 This means only members valid for the variable will be listed. 1466 1467 When a member name already was complete, CTRL-X CTRL-O will add a "." or 1468 "->" for composite types. 1469 1470 Vim doesn't include a C compiler, only the most obviously formatted 1471 declarations are recognized. Preprocessor stuff may cause confusion. 1472 When the same structure name appears in multiple places all possible members 1473 are included. 1474 1475 1476 CSS *ft-css-omni* 1477 1478 Complete properties and their appropriate values according to CSS 2.1 1479 specification. 1480 1481 1482 HTML *ft-html-omni* 1483 XHTML *ft-xhtml-omni* 1484 1485 CTRL-X CTRL-O provides completion of various elements of (X)HTML files. It is 1486 designed to support writing of XHTML 1.0 Strict files but will also work for 1487 other versions of HTML. Features: 1488 1489 - after "<" complete tag name depending on context (no div suggestion inside 1490 of an a tag); '/>' indicates empty tags 1491 - inside of tag complete proper attributes (no width attribute for an a tag); 1492 show also type of attribute; "*" indicates required attributes 1493 - when attribute has limited number of possible values help to complete them 1494 - complete names of entities 1495 - complete values of "class" and "id" attributes with data obtained from 1496 <style> tag and included CSS files 1497 - when completing value of "style" attribute or working inside of "style" tag 1498 switch to |ft-css-omni| completion 1499 - when completing values of events attributes or working inside of "script" 1500 tag switch to |ft-javascript-omni| completion 1501 - when used after "</" CTRL-X CTRL-O will close the last opened tag 1502 1503 Note: When used first time completion menu will be shown with little delay 1504 - this is time needed for loading of data file. 1505 Note: Completion may fail in badly formatted documents. In such case try to 1506 run |:make| command to detect formatting problems. 1507 1508 1509 HTML flavor *html-flavor* 1510 1511 The default HTML completion depends on the filetype. For HTML files it is 1512 HTML 4.01 Transitional ('filetype' is "html"), for XHTML it is XHTML 1.0 1513 Strict ('filetype' is "xhtml"). 1514 1515 When doing completion outside of any other tag you will have possibility to 1516 choose DOCTYPE and the appropriate data file will be loaded and used for all 1517 next completions. 1518 1519 More about format of data file in |xml-omni-datafile|. Some of the data files 1520 may be found on the Vim website (|www|). 1521 1522 Note that b:html_omni_flavor may point to a file with any XML data. This 1523 makes possible to mix PHP (|ft-php-omni|) completion with any XML dialect 1524 (assuming you have data file for it). Without setting that variable XHTML 1.0 1525 Strict will be used. 1526 1527 1528 JAVASCRIPT *ft-javascript-omni* 1529 1530 Completion of most elements of JavaScript language and DOM elements. 1531 1532 Complete: 1533 1534 - variables 1535 - function name; show function arguments 1536 - function arguments 1537 - properties of variables trying to detect type of variable 1538 - complete DOM objects and properties depending on context 1539 - keywords of language 1540 1541 Completion works in separate JavaScript files (&ft==javascript), inside of 1542 <script> tag of (X)HTML and in values of event attributes (including scanning 1543 of external files). 1544 1545 DOM compatibility 1546 1547 At the moment (beginning of 2006) there are two main browsers - MS Internet 1548 Explorer and Mozilla Firefox. These two applications are covering over 90% of 1549 market. Theoretically standards are created by W3C organisation 1550 (https://www.w3.org/) but they are not always followed/implemented. 1551 > 1552 IE FF W3C Omni completion ~ 1553 +/- +/- + + ~ 1554 + + - + ~ 1555 + - - - ~ 1556 - + - - ~ 1557 < 1558 Regardless from state of implementation in browsers but if element is defined 1559 in standards, completion plugin will place element in suggestion list. When 1560 both major engines implemented element, even if this is not in standards it 1561 will be suggested. All other elements are not placed in suggestion list. 1562 1563 1564 LUA *ft-lua-omni* 1565 1566 Lua |ftplugin| sets 'omnifunc' to |vim.lua_omnifunc()|. 1567 1568 1569 PHP *ft-php-omni* 1570 1571 Completion of PHP code requires a tags file for completion of data from 1572 external files and for class aware completion. You should use Universal/ 1573 Exuberant ctags version 5.5.4 or newer. You can find it here: 1574 1575 Universal Ctags: https://ctags.io 1576 1577 Script completes: 1578 1579 - after $ variables name 1580 - if variable was declared as object add "->", if tags file is available 1581 show name of class 1582 - after "->" complete only function and variable names specific for given 1583 class. To find class location and contents tags file is required. 1584 Because PHP isn't strongly typed language user can use @var tag to declare 1585 class: > 1586 1587 /* @var $myVar myClass */ 1588 $myVar-> 1589 < 1590 Still, to find myClass contents tags file is required. 1591 1592 - function names with additional info: 1593 - in case of built-in functions list of possible arguments and after | type 1594 data returned by function 1595 - in case of user function arguments and name of file where function was 1596 defined (if it is not current file) 1597 1598 - constants names 1599 - class names after "new" declaration 1600 1601 1602 Note: when doing completion first time Vim will load all necessary data into 1603 memory. It may take several seconds. After next use of completion delay 1604 should not be noticeable. 1605 1606 Script detects if cursor is inside <?php ?> tags. If it is outside it will 1607 automatically switch to HTML/CSS/JavaScript completion. Note: contrary to 1608 original HTML files completion of tags (and only tags) isn't context aware. 1609 1610 1611 RUBY *ft-ruby-omni* 1612 1613 NOTE: |compl-omni| for Ruby code requires |provider-ruby| to be installed. 1614 1615 Ruby completion will parse your buffer on demand in order to provide a list of 1616 completions. These completions will be drawn from modules loaded by "require" 1617 and modules defined in the current buffer. 1618 1619 The completions provided by CTRL-X CTRL-O are sensitive to the context: 1620 1621 CONTEXT COMPLETIONS PROVIDED ~ 1622 1623 1. Not inside a class definition: Classes, constants and globals 1624 2. Inside a class definition: Methods or constants defined in the class 1625 3. After '.', '::' or ':': Methods applicable to the object being 1626 dereferenced 1627 4. After ':' or ':foo': Symbol name (beginning with "foo") 1628 1629 Notes: 1630 - Vim will load/evaluate code in order to provide completions. This may 1631 cause some code execution, which may be a concern. This is no longer 1632 enabled by default, to enable this feature add > 1633 let g:rubycomplete_buffer_loading = 1 1634 - In context 1 above, Vim can parse the entire buffer to add a list of 1635 classes to the completion results. This feature is turned off by default, 1636 to enable it add > 1637 let g:rubycomplete_classes_in_global = 1 1638 < to your vimrc 1639 - In context 2 above, anonymous classes are not supported. 1640 - In context 3 above, Vim will attempt to determine the methods supported by 1641 the object. 1642 - Vim can detect and load the Rails environment for files within a rails 1643 project. The feature is disabled by default, to enable it add > 1644 let g:rubycomplete_rails = 1 1645 < to your vimrc 1646 1647 1648 SYNTAX *ft-syntax-omni* 1649 1650 Vim has the ability to color syntax highlight nearly 500 languages. Part of 1651 this highlighting includes knowing what keywords are part of a language. Many 1652 filetypes already have custom completion scripts written for them, the 1653 syntaxcomplete plugin provides basic completion for all other filetypes. It 1654 does this by populating the omni completion list with the text Vim already 1655 knows how to color highlight. It can be used for any filetype and provides a 1656 minimal language-sensitive completion. 1657 1658 To enable syntax code completion you can run: > 1659 setlocal omnifunc=syntaxcomplete#Complete 1660 1661 You can automate this by placing the following in your |init.vim| (after any 1662 ":filetype" command): > 1663 if has("autocmd") && exists("+omnifunc") 1664 autocmd Filetype * 1665 \ if &omnifunc == "" | 1666 \ setlocal omnifunc=syntaxcomplete#Complete | 1667 \ endif 1668 endif 1669 1670 The above will set completion to this script only if a specific plugin does 1671 not already exist for that filetype. 1672 1673 Each filetype can have a wide range of syntax items. The plugin allows you to 1674 customize which syntax groups to include or exclude from the list. Let's have 1675 a look at the PHP filetype to see how this works. 1676 1677 If you edit a file called, index.php, run the following command: > 1678 syntax list 1679 1680 The first thing you will notice is that there are many different syntax 1681 groups. The PHP language can include elements from different languages like 1682 HTML, JavaScript and many more. The syntax plugin will only include syntax 1683 groups that begin with the filetype, "php", in this case. For example these 1684 syntax groups are included by default with the PHP: phpEnvVar, phpIntVar, 1685 phpFunctions. 1686 1687 If you wish non-filetype syntax items to also be included, you can use a 1688 regular expression syntax (added in version 13.0 of 1689 autoload/syntaxcomplete.vim) to add items. Looking at the output from 1690 ":syntax list" while editing a PHP file I can see some of these entries: > 1691 htmlArg,htmlTag,htmlTagName,javaScriptStatement,javaScriptGlobalObjects 1692 1693 To pick up any JavaScript and HTML keyword syntax groups while editing a PHP 1694 file, you can use 3 different regexs, one for each language. Or you can 1695 simply restrict the include groups to a particular value, without using 1696 a regex string: > 1697 let g:omni_syntax_group_include_php = 'php\w\+,javaScript\w\+,html\w\+' 1698 let g:omni_syntax_group_include_php = 'phpFunctions,phpMethods' 1699 < 1700 The basic form of this variable is: > 1701 let g:omni_syntax_group_include_{filetype} = 'regex,comma,separated' 1702 1703 The PHP language has an enormous number of items which it knows how to syntax 1704 highlight. These items will be available within the omni completion list. 1705 1706 Some people may find this list unwieldy or are only interested in certain 1707 items. There are two ways to prune this list (if necessary). If you find 1708 certain syntax groups you do not wish displayed you can use two different 1709 methods to identify these groups. The first specifically lists the syntax 1710 groups by name. The second uses a regular expression to identify both 1711 syntax groups. Simply add one the following to your vimrc: > 1712 let g:omni_syntax_group_exclude_php = 'phpCoreConstant,phpConstant' 1713 let g:omni_syntax_group_exclude_php = 'php\w*Constant' 1714 1715 Add as many syntax groups to this list by comma separating them. The basic 1716 form of this variable is: > 1717 let g:omni_syntax_group_exclude_{filetype} = 'regex,comma,separated' 1718 1719 You can create as many of these variables as you need, varying only the 1720 filetype at the end of the variable name. 1721 1722 The plugin uses the isKeyword option to determine where word boundaries are 1723 for the syntax items. For example, in the Scheme language completion should 1724 include the "-", call-with-output-file. Depending on your filetype, this may 1725 not provide the words you are expecting. Setting the 1726 g:omni_syntax_use_iskeyword option to 0 will force the syntax plugin to break 1727 on word characters. This can be controlled adding the following to your 1728 vimrc: > 1729 let g:omni_syntax_use_iskeyword = 0 1730 1731 For plugin developers, the plugin exposes a public function OmniSyntaxList. 1732 This function can be used to request a List of syntax items. When editing a 1733 SQL file (:e syntax.sql) you can use the ":syntax list" command to see the 1734 various groups and syntax items. For example: > 1735 syntax list 1736 1737 Yields data similar to this: > 1738 sqlOperator xxx some prior all like and any escape exists in is not 1739 or intersect minus between distinct 1740 links to Operator 1741 sqlType xxx varbit varchar nvarchar bigint int uniqueidentifier 1742 date money long tinyint unsigned xml text smalldate 1743 double datetime nchar smallint numeric time bit char 1744 varbinary binary smallmoney 1745 image float integer timestamp real decimal 1746 1747 There are two syntax groups listed here: sqlOperator and sqlType. To retrieve 1748 a List of syntax items you can call OmniSyntaxList a number of different 1749 ways. To retrieve all syntax items regardless of syntax group: > 1750 echo OmniSyntaxList( [] ) 1751 1752 To retrieve only the syntax items for the sqlOperator syntax group: > 1753 echo OmniSyntaxList( ['sqlOperator'] ) 1754 1755 To retrieve all syntax items for both the sqlOperator and sqlType groups: > 1756 echo OmniSyntaxList( ['sqlOperator', 'sqlType'] ) 1757 1758 A regular expression can also be used: > 1759 echo OmniSyntaxList( ['sql\w\+'] ) 1760 1761 From within a plugin, you would typically assign the output to a List: > 1762 let myKeywords = [] 1763 let myKeywords = OmniSyntaxList( ['sqlKeyword'] ) 1764 1765 1766 SQL *ft-sql-omni* 1767 1768 Completion for the SQL language includes statements, functions, keywords. 1769 It will also dynamically complete tables, procedures, views and column lists 1770 with data pulled directly from within a database. For detailed instructions 1771 and a tutorial see |omni-sql-completion|. 1772 1773 The SQL completion plugin can be used in conjunction with other completion 1774 plugins. For example, the PHP filetype has its own completion plugin. 1775 Since PHP is often used to generate dynamic website by accessing a database, 1776 the SQL completion plugin can also be enabled. This allows you to complete 1777 PHP code and SQL code at the same time. 1778 1779 1780 XML *ft-xml-omni* 1781 1782 Vim 7 provides a mechanism for context aware completion of XML files. It 1783 depends on a special |xml-omni-datafile| and two commands: |:XMLns| and 1784 |:XMLent|. Features are: 1785 1786 - after "<" complete the tag name, depending on context 1787 - inside of a tag complete proper attributes 1788 - when an attribute has a limited number of possible values help to complete 1789 them 1790 - complete names of entities (defined in |xml-omni-datafile| and in the 1791 current file with "<!ENTITY" declarations) 1792 - when used after "</" CTRL-X CTRL-O will close the last opened tag 1793 1794 Format of XML data file *xml-omni-datafile* 1795 1796 XML data files are stored in the "autoload/xml" directory in 'runtimepath'. 1797 Vim distribution provides examples of data files in the 1798 "$VIMRUNTIME/autoload/xml" directory. They have a meaningful name which will 1799 be used in commands. It should be a unique name which will not create 1800 conflicts. For example, the name xhtml10s.vim means it is the data file for 1801 XHTML 1.0 Strict. 1802 1803 Each file contains a variable with a name like g:xmldata_xhtml10s . It is 1804 a compound from two parts: 1805 1806 1. "g:xmldata_" general prefix, constant for all data files 1807 2. "xhtml10s" the name of the file and the name of the described XML 1808 dialect; it will be used as an argument for the |:XMLns| 1809 command 1810 1811 Part two must be exactly the same as name of file. 1812 1813 The variable is a |Dictionary|. Keys are tag names and each value is a two 1814 element |List|. The first element of the List is also a List with the names 1815 of possible children. The second element is a |Dictionary| with the names of 1816 attributes as keys and the possible values of attributes as values. Example: > 1817 1818 let g:xmldata_crippled = { 1819 \ "vimxmlentities": ["amp", "lt", "gt", "apos", "quot"], 1820 \ 'vimxmlroot': ['tag1'], 1821 \ 'tag1': 1822 \ [ ['childoftag1a', 'childoftag1b'], {'attroftag1a': [], 1823 \ 'attroftag1b': ['valueofattr1', 'valueofattr2']}], 1824 \ 'childoftag1a': 1825 \ [ [], {'attrofchild': ['attrofchild']}], 1826 \ 'childoftag1b': 1827 \ [ ['childoftag1a'], {'attrofchild': []}], 1828 \ "vimxmltaginfo": { 1829 \ 'tag1': ['Menu info', 'Long information visible in preview window']}, 1830 \ 'vimxmlattrinfo': { 1831 \ 'attrofchild': ['Menu info', 'Long information visible in preview window']}} 1832 1833 This example would be put in the "autoload/xml/crippled.vim" file and could 1834 help to write this file: > 1835 1836 <tag1 attroftag1b="valueofattr1"> 1837 <childoftag1a attrofchild> 1838 & < 1839 </childoftag1a> 1840 <childoftag1b attrofchild="5"> 1841 <childoftag1a> 1842 > ' " 1843 </childoftag1a> 1844 </childoftag1b> 1845 </tag1> 1846 1847 In the example four special elements are visible: 1848 1849 1. "vimxmlentities" - a special key with List containing entities of this XML 1850 dialect. 1851 2. If the list containing possible values of attributes has one element and 1852 this element is equal to the name of the attribute this attribute will be 1853 treated as boolean and inserted as "attrname" and not as 'attrname="' 1854 3. "vimxmltaginfo" - a special key with a Dictionary containing tag 1855 names as keys and two element List as values, for additional menu info and 1856 the long description. 1857 4. "vimxmlattrinfo" - special key with Dictionary containing attribute names 1858 as keys and two element List as values, for additional menu info and long 1859 description. 1860 1861 Note: Tag names in the data file MUST not contain a namespace description. 1862 Check xsl.vim for an example. 1863 Note: All data and functions are publicly available as global 1864 variables/functions and can be used for personal editing functions. 1865 1866 1867 DTD -> Vim *dtd2vim* 1868 1869 On |www| is the script |dtd2vim| which parses DTD and creates an XML data file 1870 for Vim XML omni completion. 1871 1872 dtd2vim: https://www.vim.org/scripts/script.php?script_id=1462 1873 1874 Check the beginning of that file for usage details. 1875 The script requires perl and: 1876 1877 perlSGML: https://savannah.nongnu.org/projects/perlsgml 1878 1879 1880 Commands 1881 1882 :XMLns {name} [{namespace}] *:XMLns* 1883 1884 Vim has to know which data file should be used and with which namespace. For 1885 loading of the data file and connecting data with the proper namespace use 1886 |:XMLns| command. The first (obligatory) argument is the name of the data 1887 (xhtml10s, xsl). The second argument is the code of namespace (h, xsl). When 1888 used without a second argument the dialect will be used as default - without 1889 namespace declaration. For example to use XML completion in .xsl files: > 1890 1891 :XMLns xhtml10s 1892 :XMLns xsl xsl 1893 1894 1895 :XMLent {name} *:XMLent* 1896 1897 By default entities will be completed from the data file of the default 1898 namespace. The XMLent command should be used in case when there is no default 1899 namespace: > 1900 1901 :XMLent xhtml10s 1902 1903 Usage 1904 1905 While used in this situation (after declarations from previous part, | is 1906 cursor position): > 1907 1908 <| 1909 1910 Will complete to an appropriate XHTML tag, and in this situation: > 1911 1912 <xsl:| 1913 1914 Will complete to an appropriate XSL tag. 1915 1916 1917 The script xmlcomplete.vim, provided through the |autoload| mechanism, 1918 has the xmlcomplete#GetLastOpenTag() function which can be used in XML files 1919 to get the name of the last open tag (b:unaryTagsStack has to be defined): > 1920 1921 :echo xmlcomplete#GetLastOpenTag("b:unaryTagsStack") 1922 1923 1924 1925 ============================================================================== 1926 8. Insert mode commands *inserting* 1927 1928 The following commands can be used to insert new text into the buffer. They 1929 can all be undone and repeated with the "." command. 1930 1931 *a* 1932 a Append text after the cursor [count] times. If the 1933 cursor is in the first column of an empty line Insert 1934 starts there. But not when 'virtualedit' is set! 1935 1936 *A* 1937 A Append text at the end of the line [count] times. 1938 For using "A" in Visual block mode see |v_b_A|. 1939 1940 <insert> or *i* *insert* *<Insert>* 1941 i Insert text before the cursor [count] times. 1942 When using CTRL-O in Insert mode |i_CTRL-O| the count 1943 is not supported. 1944 1945 *I* 1946 I Insert text before the first non-blank in the line 1947 [count] times. 1948 For using "I" in Visual block mode see |v_b_I|. 1949 1950 *gI* 1951 gI Insert text in column 1 [count] times. 1952 1953 *gi* 1954 gi Insert text in the same position as where Insert mode 1955 was stopped last time in the current buffer. 1956 This uses the |'^| mark. It's different from "`^i" 1957 when the mark is past the end of the line. 1958 The position is corrected for inserted/deleted lines, 1959 but NOT for inserted/deleted characters. 1960 When the |:keepjumps| command modifier is used the |'^| 1961 mark won't be changed. 1962 1963 *o* 1964 o Begin a new line below the cursor and insert text, 1965 repeat [count] times. 1966 1967 *O* 1968 O Begin a new line above the cursor and insert text, 1969 repeat [count] times. 1970 1971 These commands are used to start inserting text. You can end insert mode with 1972 <Esc>. See |mode-ins-repl| for the other special characters in Insert mode. 1973 The effect of [count] takes place after Insert mode is exited. 1974 1975 The following |default-mappings| insert text, but stay in normal mode: 1976 1977 *]<Space>* 1978 ]<Space> Insert an empty line below the cursor without leaving 1979 Normal mode, repeat [count] times. 1980 1981 *[<Space>* 1982 [<Space> Insert an empty line above the cursor without leaving 1983 Normal mode, repeat [count] times. 1984 1985 When 'autoindent' is on, the indent for a new line is obtained from the 1986 previous line. When 'smartindent' or 'cindent' is on, the indent for a line 1987 is automatically adjusted for C programs. 1988 1989 'formatoptions' can be set to copy the comment leader when opening a new 1990 line. 1991 1992 'textwidth' can be set to the maximum width for a line. When a line becomes 1993 too long when appending characters a line break is automatically inserted. 1994 1995 1996 ============================================================================== 1997 9. Ex insert commands *inserting-ex* 1998 1999 *:a* *:append* 2000 :{range}a[ppend][!] Insert several lines of text below the specified 2001 line. If the {range} is missing, the text will be 2002 inserted after the current line. 2003 Adding [!] toggles 'autoindent' for the time this 2004 command is executed. 2005 2006 *:i* *:in* *:insert* 2007 :{range}i[nsert][!] Insert several lines of text above the specified 2008 line. If the {range} is missing, the text will be 2009 inserted before the current line. 2010 Adding [!] toggles 'autoindent' for the time this 2011 command is executed. 2012 2013 These two commands will keep on asking for lines, until you type a line 2014 containing only a ".". Watch out for lines starting with a backslash, see 2015 |line-continuation|. 2016 2017 Text typed after a "|" command separator is used first. So the following 2018 command in ex mode: > 2019 :a|one 2020 two 2021 . 2022 :visual 2023 appends the following text, after the cursor line: > 2024 one 2025 two 2026 < 2027 NOTE: These commands cannot be used with |:global| or |:vglobal|. 2028 ":append" and ":insert" don't work properly in between ":if" and 2029 ":endif", ":for" and ":endfor", ":while" and ":endwhile". 2030 2031 *:start* *:startinsert* 2032 :star[tinsert][!] Start Insert mode (or |Terminal-mode| in a |terminal| 2033 buffer) just after executing this command. 2034 Works like typing "i" in Normal mode. When the ! is 2035 included it works like "A", append to the line. 2036 Otherwise insertion starts at the cursor position. 2037 Note that when using this command in a function or 2038 script, the insertion only starts after the function 2039 or script is finished. 2040 This command does not work from |:normal|. 2041 2042 *:stopi* *:stopinsert* 2043 :stopi[nsert] Stop Insert mode or |Terminal-mode| as soon as 2044 possible. Works like typing <Esc> in Insert mode. 2045 Can be used in an autocommand, example: > 2046 :au BufEnter scratch stopinsert 2047 < 2048 *replacing-ex* *:startreplace* 2049 :startr[eplace][!] Start Replace mode just after executing this command. 2050 Works just like typing "R" in Normal mode. When the 2051 ! is included it acts just like "$R" had been typed 2052 (ie. begin replace mode at the end-of-line). Other- 2053 wise replacement begins at the cursor position. 2054 Note that when using this command in a function or 2055 script that the replacement will only start after 2056 the function or script is finished. 2057 2058 *:startgreplace* 2059 :startg[replace][!] Just like |:startreplace|, but use Virtual Replace 2060 mode, like with |gR|. 2061 2062 ============================================================================== 2063 10. Inserting a file *inserting-file* 2064 2065 *:r* *:re* *:read* 2066 :r[ead] [++opt] [name] 2067 Insert the file [name] (default: current file) below 2068 the cursor. 2069 See |++opt| for the possible values of [++opt]. 2070 2071 :{range}r[ead] [++opt] [name] 2072 Insert the file [name] (default: current file) below 2073 the specified line. 2074 See |++opt| for the possible values of [++opt]. 2075 2076 *:r!* *:read!* 2077 :[range]r[ead] [++opt] !{cmd} 2078 Execute {cmd} and insert its standard output below 2079 the cursor or the specified line. A temporary file is 2080 used to store the output of the command which is then 2081 read into the buffer. 'shellredir' is used to save 2082 the output of the command, which can be set to include 2083 stderr or not. {cmd} is executed like with ":!{cmd}", 2084 any '!' is replaced with the previous command |:!|. 2085 See |++opt| for the possible values of [++opt]. 2086 2087 These commands insert the contents of a file, or the output of a command, 2088 into the buffer. They can be undone. They cannot be repeated with the "." 2089 command. They work on a line basis, insertion starts below the line in which 2090 the cursor is, or below the specified line. To insert text above the first 2091 line use the command ":0r {name}". 2092 2093 After the ":read" command, the cursor is left on the first non-blank in the 2094 first new line. If in Ex mode, then the cursor is left on the last new 2095 line (sorry, this is Vi compatible). 2096 2097 If a file name is given with ":r", it becomes the alternate file. This can be 2098 used, for example, when you want to edit that file instead: ":e! #". This can 2099 be switched off by removing the 'a' flag from the 'cpoptions' option. 2100 2101 Of the [++opt] arguments one is specifically for ":read", the ++edit argument. 2102 This is useful when the ":read" command is actually used to read a file into 2103 the buffer as if editing that file. Use this command in an empty buffer: > 2104 :read ++edit filename 2105 The effect is that the 'fileformat', 'fileencoding', 'bomb', etc. options are 2106 set to what has been detected for "filename". Note that a single empty line 2107 remains, you may want to delete it. 2108 2109 *file-read* 2110 The 'fileformat' option sets the <EOL> style for a file: 2111 'fileformat' characters name ~ 2112 "dos" <CR><NL> or <NL> DOS format 2113 "unix" <NL> Unix format 2114 "mac" <CR> Mac format 2115 2116 If 'fileformat' is "dos", a <CR> in front of an <NL> is ignored and a CTRL-Z 2117 at the end of the file is ignored. 2118 2119 If 'fileformat' is "mac", a <NL> in the file is internally represented by a 2120 <CR>. This is to avoid confusion with a <NL> which is used to represent a 2121 <NUL>. See |CR-used-for-NL|. 2122 2123 If the 'fileformats' option is not empty Vim tries to recognize the type of 2124 <EOL> (see |file-formats|). However, the 'fileformat' option will not be 2125 changed, the detected format is only used while reading the file. 2126 A similar thing happens with 'fileencodings'. 2127 2128 On non-Win32 systems the message "[dos format]" is shown if a file is read in 2129 DOS format, to remind you that something unusual is done. 2130 On Macintosh and Win32 the message "[unix format]" is shown if a file is read 2131 in Unix format. 2132 On non-Macintosh systems, the message "[mac format]" is shown if a file is 2133 read in Mac format. 2134 2135 An example on how to use ":r !": > 2136 :r !uuencode binfile binfile 2137 This command reads "binfile", uuencodes it and reads it into the current 2138 buffer. Useful when you are editing e-mail and want to include a binary 2139 file. 2140 2141 *read-messages* 2142 When reading a file Vim will display a message with information about the read 2143 file. In the table is an explanation for some of the items. The others are 2144 self explanatory. Using the long or the short version depends on the 2145 'shortmess' option. 2146 2147 long short meaning ~ 2148 [readonly] {RO} the file is write protected 2149 [fifo/socket] using a stream 2150 [fifo] using a fifo stream 2151 [socket] using a socket stream 2152 [CR missing] reading with "dos" 'fileformat' and a 2153 NL without a preceding CR was found. 2154 [NL found] reading with "mac" 'fileformat' and a 2155 NL was found (could be "unix" format) 2156 [long lines split] at least one line was split in two 2157 [NOT converted] conversion from 'fileencoding' to 2158 'encoding' was desired but not 2159 possible 2160 [converted] conversion from 'fileencoding' to 2161 'encoding' done 2162 [READ ERRORS] not all of the file could be read 2163 2164 2165 vim:tw=78:ts=8:noet:ft=help:norl: