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