blob: 0a28038dc25d11a36f7fb1c6631cb9ad5c71da9e [file] [log] [blame]
Bram Moolenaar4770d092006-01-12 23:22:24 +00001*insert.txt* For Vim version 7.0aa. Last change: 2006 Jan 08
Bram Moolenaar071d4272004-06-13 20:20:40 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7 *Insert* *Insert-mode*
8Inserting and replacing text *mode-ins-repl*
9
10Most of this file is about Insert and Replace mode. At the end are a few
11commands for inserting text in other ways.
12
13An overview of the most often used commands can be found in chapter 24 of the
14user manual |usr_24.txt|.
15
161. Special keys |ins-special-keys|
172. Special special keys |ins-special-special|
183. 'textwidth' and 'wrapmargin' options |ins-textwidth|
194. 'expandtab', 'smarttab' and 'softtabstop' options |ins-expandtab|
205. Replace mode |Replace-mode|
216. Virtual Replace mode |Virtual-Replace-mode|
227. Insert mode completion |ins-completion|
238. Insert mode commands |inserting|
249. Ex insert commands |inserting-ex|
2510. Inserting a file |inserting-file|
26
27Also see 'virtualedit', for moving the cursor to positions where there is no
28character. Useful for editing a table.
29
30==============================================================================
311. Special keys *ins-special-keys*
32
33In Insert and Replace mode, the following characters have a special meaning;
34other characters are inserted directly. To insert one of these special
35characters into the buffer, precede it with CTRL-V. To insert a <Nul>
36character use "CTRL-V CTRL-@" or "CTRL-V 000". On some systems, you have to
37use "CTRL-V 003" to insert a CTRL-C. Note: When CTRL-V is mapped you can
38often use CTRL-Q instead |i_CTRL-Q|.
39
40If you are working in a special language mode when inserting text, see the
41'langmap' option, |'langmap'|, on how to avoid switching this mode on and off
42all the time.
43
44If you have 'insertmode' set, <Esc> and a few other keys get another meaning.
45See |'insertmode'|.
46
47char action ~
48-----------------------------------------------------------------------
49 *i_CTRL-[* *i_<Esc>*
50<Esc> or CTRL-[ End insert or Replace mode, go back to Normal mode. Finish
51 abbreviation.
52 Note: If your <Esc> key is hard to hit on your keyboard, train
53 yourself to use CTRL-[.
54 *i_CTRL-C*
55CTRL-C Quit insert mode, go back to Normal mode. Do not check for
Bram Moolenaar677ee682005-01-27 14:41:15 +000056 abbreviations. Does not trigger the |InsertLeave| autocommand
57 event.
Bram Moolenaar071d4272004-06-13 20:20:40 +000058
59 *i_CTRL-@*
60CTRL-@ Insert previously inserted text and stop insert. {Vi: only
61 when typed as first char, only up to 128 chars}
62 *i_CTRL-A*
63CTRL-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*
78CTRL-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*
82CTRL-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*
96CTRL-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
103CTRL-N Find next keyword (see |i_CTRL-N|). {not in Vi}
104CTRL-P Find previous keyword (see |i_CTRL-P|). {not in Vi}
105
106CTRL-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 Moolenaar293ee4d2004-12-09 21:34:53 +0000128 Note that 0x80 (128 decimal) is used for
129 special keys, use CTRL-R CTRL-R to insert it
130 literally.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000131 See |registers| about registers. {not in Vi}
132
133CTRL-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
145CTRL-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
153CTRL-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*
161CTRL-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*
165CTRL-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*
1700 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*
178CTRL-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*
188CTRL-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
192CTRL-X Enter CTRL-X mode. This is a sub-mode where commands can
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000193 be given to complete words or scroll the window. See
Bram Moolenaar071d4272004-06-13 20:20:40 +0000194 |i_CTRL-X| and |ins-completion|. {not in Vi}
195
196 *i_CTRL-E*
197CTRL-E Insert the character which is below the cursor. {not in Vi}
198 *i_CTRL-Y*
199CTRL-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-_*
204CTRL-_ 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-^*
220CTRL-^ 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-]*
239CTRL-] 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*
247The 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
250item action ~
251indent allow backspacing over autoindent
252eol allow backspacing over end-of-line (join lines)
253start allow backspacing over the start position of insert; CTRL-W and
254 CTRL-U stop once at the start position
255
256When 'backspace' is empty, Vi compatible backspacing is used. You cannot
257backspace over autoindent, before column 1 or before where insert started.
258
259For backwards compatibility the values "0", "1" and "2" are also allowed, see
260|'backspace'|.
261
262If the 'backspace' option does contain "eol" and the cursor is in column 1
263when one of the three keys is used, the current line is joined with the
264previous 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*
268With CTRL-V the decimal, octal or hexadecimal value of a character can be
269entered 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
272first char mode max nr of chars max value ~
273(none) decimal 3 255
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000274o or O octal 3 377 (255)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000275x or X hexadecimal 2 ff (255)
276u hexadecimal 4 ffff (65535)
277U hexadecimal 8 7fffffff (2147483647)
278
279Normally you would type the maximum number of characters. Thus to enter a
280space (value 32) you would type <C-V>032. You can omit the leading zero, in
281which case the character typed after the number must be a non-digit. This
282happens for the other modes as well: As soon as you type a character that is
283invalid for the mode, the value before it will be used and the "invalid"
284character is dealt with in the normal way.
285
286If 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
288the buffer to a file, the <NL> character is translated into <Nul>. The <NL>
289character 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*
293CTRL-X enters a sub-mode where several commands can be used. Most of these
294commands do keyword completion; see |ins-completion|. These are not available
295when Vim was compiled without the |+insert_expand| feature.
296
297Two commands can be used to scroll the window up or down, without exiting
298insert mode:
299
300 *i_CTRL-X_CTRL-E*
301CTRL-X CTRL-E scroll window one line up.
302
303 *i_CTRL-X_CTRL-Y*
304CTRL-X CTRL-Y scroll window one line down.
305
306After CTRL-X is pressed, each CTRL-E (CTRL-Y) scrolls the window up (down) by
307one line unless that would cause the cursor to move from its current position
308in the file. As soon as another key is pressed, CTRL-X mode is exited and
309that key is interpreted as in Insert mode.
310
311
312==============================================================================
3132. Special special keys *ins-special-special*
314
315The following keys are special. They stop the current insert, do something,
316and then restart insertion. This means you can do something without getting
317out of Insert mode. This is very handy if you prefer to use the Insert mode
318all the time, just like editors that don't have a separate Normal mode. You
319may 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
321a command.
322
323The changes (inserted or deleted characters) before and after these keys can
324be undone separately. Only the last change can be redone and always behaves
325like an "i" command.
326
327char action ~
328-----------------------------------------------------------------------
329<Up> cursor one line up *i_<Up>*
330<Down> cursor one line down *i_<Down>*
331CTRL-G <Up> cursor one line up, insert start column *i_CTRL-G_<Up>*
332CTRL-G k cursor one line up, insert start column *i_CTRL-G_k*
333CTRL-G CTRL-K cursor one line up, insert start column *i_CTRL-G_CTRL-K*
334CTRL-G <Down> cursor one line down, insert start column *i_CTRL-G_<Down>*
335CTRL-G j cursor one line down, insert start column *i_CTRL-G_j*
336CTRL-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>*
356CTRL-O execute one command, return to Insert mode *i_CTRL-O*
Bram Moolenaar4770d092006-01-12 23:22:24 +0000357CTRL-\ CTRL-O like CTRL-O but don't move the cursor *i_CTRL-\_CTRL-O*
Bram Moolenaar488c6512005-08-11 20:09:58 +0000358CTRL-L when 'insertmode' is set: go to Normal mode *i_CTRL-L*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359CTRL-G u break undo sequence, start new change *i_CTRL-G_u*
360-----------------------------------------------------------------------
361
362Note: If the cursor keys take you out of Insert mode, check the 'noesckeys'
363option.
364
365The CTRL-O command sometimes has a side effect: If the cursor was beyond the
366end of the line, it will be put on the last character in the line. In
367mappings it's often better to use <Esc> (first put an "x" in the text, <Esc>
Bram Moolenaar488c6512005-08-11 20:09:58 +0000368will then always put the cursor on it). Or use CTRL-\ CTRL-O, but then
369beware of the cursor possibly being beyond the end of the line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000370
371The shifted cursor keys are not available on all terminals.
372
373Another side effect is that a count specified before the "i" or "a" command is
374ignored. That is because repeating the effect of the command after CTRL-O is
375too complicated.
376
377An example for using CTRL-G u: >
378
379 :inoremap <C-H> <C-G>u<C-H>
380
381This redefines the backspace key to start a new undo sequence. You can now
382undo the effect of the backspace key, without changing what you typed before
383that, with CTRL-O u.
384
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000385Using CTRL-O splits undo: the text typed before and after it is undone
386separately. If you want to avoid this (e.g., in a mapping) you might be able
387to use CTRL-R = |i_CTRL-R|. E.g., to call a function: >
388 :imap <F2> <C-R>=MyFunc()<CR>
389
Bram Moolenaar071d4272004-06-13 20:20:40 +0000390When the 'whichwrap' option is set appropriately, the <Left> and <Right>
391keys on the first/last character in the line make the cursor wrap to the
392previous/next line.
393
394The CTRL-G j and CTRL-G k commands can be used to insert text in front of a
395column. Example: >
396 int i;
397 int j;
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000398Position the cursor on the first "int", type "istatic <C-G>j ". The
Bram Moolenaar071d4272004-06-13 20:20:40 +0000399result is: >
400 static int i;
401 int j;
402When inserting the same text in front of the column in every line, use the
403Visual blockwise command "I" |v_b_I|.
404
405==============================================================================
4063. 'textwidth' and 'wrapmargin' options *ins-textwidth*
407
408The 'textwidth' option can be used to automatically break a line before it
409gets too long. Set the 'textwidth' option to the desired maximum line
410length. If you then type more characters (not spaces or tabs), the
411last word will be put on a new line (unless it is the only word on the
412line). If you set 'textwidth' to 0, this feature is disabled.
413
414The 'wrapmargin' option does almost the same. The difference is that
415'textwidth' has a fixed width while 'wrapmargin' depends on the width of the
416screen. When using 'wrapmargin' this is equal to using 'textwidth' with a
417value equal to (columns - 'wrapmargin'), where columns is the width of the
418screen.
419
420When 'textwidth' and 'wrapmargin' are both set, 'textwidth' is used.
421
422If you don't really want to break the line, but view the line wrapped at a
423convenient place, see the 'linebreak' option.
424
425The line is only broken automatically when using insert mode, or when
426appending to a line. When in replace mode and the line length is not
427changed, the line will not be broken.
428
429Long lines are broken if you enter a non-white character after the margin.
430The situations where a line will be broken can be restricted by adding
431characters to the 'formatoptions' option:
432"l" Only break a line if it was not longer than 'textwidth' when the insert
433 started.
434"v" Only break at a white character that has been entered during the
435 current insert command. This is mostly Vi-compatible.
436"lv" Only break if the line was not longer than 'textwidth' when the insert
437 started and only at a white character that has been entered during the
438 current insert command. Only differs from "l" when entering non-white
439 characters while crossing the 'textwidth' boundary.
440
441If you want to format a block of text, you can use the "gq" operator. Type
442"gq" and a movement command to move the cursor to the end of the block. In
443many cases, the command "gq}" will do what you want (format until the end of
444paragraph). Alternatively, you can use "gqap", which will format the whole
445paragraph, no matter where the cursor currently is. Or you can use Visual
446mode: hit "v", move to the end of the block, and type "gq". See also |gq|.
447
448==============================================================================
4494. 'expandtab', 'smarttab' and 'softtabstop' options *ins-expandtab*
450
451If the 'expandtab' option is on, spaces will be used to fill the amount of
452whitespace of the tab. If you want to enter a real <Tab>, type CTRL-V first
453(use CTRL-Q when CTRL-V is mapped |i_CTRL-Q|).
454The 'expandtab' option is off by default. Note that in Replace mode, a single
455character is replaced with several spaces. The result of this is that the
456number of characters in the line increases. Backspacing will delete one
457space at a time. The original character will be put back for only one space
458that you backspace over (the last one). {Vi does not have the 'expandtab'
459option}
460
461 *ins-smarttab*
462When the 'smarttab' option is on, a <Tab> inserts 'shiftwidth' positions at
463the beginning of a line and 'tabstop' positions in other places. This means
464that often spaces instead of a <Tab> character are inserted. When 'smarttab
465is off, a <Tab> always inserts 'tabstop' positions, and 'shiftwidth' is only
466used for ">>" and the like. {not in Vi}
467
468 *ins-softtabstop*
469When the 'softtabstop' option is non-zero, a <Tab> inserts 'softtabstop'
470positions, and a <BS> used to delete white space, will delete 'softtabstop'
471positions. This feels like 'tabstop' was set to 'softtabstop', but a real
472<Tab> character still takes 'tabstop' positions, so your file will still look
473correct when used by other applications.
474
475If 'softtabstop' is non-zero, a <BS> will try to delete as much white space to
476move to the previous 'softtabstop' position, except when the previously
477inserted character is a space, then it will only delete the character before
478the cursor. Otherwise you cannot always delete a single character before the
479cursor. You will have to delete 'softtabstop' characters first, and then type
480extra spaces to get where you want to be.
481
482==============================================================================
4835. Replace mode *Replace* *Replace-mode* *mode-replace*
484
485Enter Replace mode with the "R" command in normal mode.
486
487In Replace mode, one character in the line is deleted for every character you
488type. If there is no character to delete (at the end of the line), the
489typed character is appended (as in Insert mode). Thus the number of
490characters in a line stays the same until you get to the end of the line.
491If a <NL> is typed, a line break is inserted and no character is deleted.
492
493Be careful with <Tab> characters. If you type a normal printing character in
494its place, the number of characters is still the same, but the number of
495columns will become smaller.
496
497If you delete characters in Replace mode (with <BS>, CTRL-W, or CTRL-U), what
498happens is that you delete the changes. The characters that were replaced
499are restored. If you had typed past the existing text, the characters you
500added are deleted. This is effectively a character-at-a-time undo.
501
502If the 'expandtab' option is on, a <Tab> will replace one character with
503several spaces. The result of this is that the number of characters in the
504line increases. Backspacing will delete one space at a time. The original
505character will be put back for only one space that you backspace over (the
506last one). {Vi does not have the 'expandtab' option}
507
508==============================================================================
5096. Virtual Replace mode *vreplace-mode* *Virtual-Replace-mode*
510
511Enter Virtual Replace mode with the "gR" command in normal mode.
512{not available when compiled without the +vreplace feature}
513{Vi does not have Virtual Replace mode}
514
515Virtual Replace mode is similar to Replace mode, but instead of replacing
516actual characters in the file, you are replacing screen real estate, so that
517characters further on in the file never appear to move.
518
519So if you type a <Tab> it may replace several normal characters, and if you
520type a letter on top of a <Tab> it may not replace anything at all, since the
521<Tab> will still line up to the same place as before.
522
523Typing a <NL> still doesn't cause characters later in the file to appear to
524move. The rest of the current line will be replaced by the <NL> (that is,
525they are deleted), and replacing continues on the next line. A new line is
526NOT inserted unless you go past the end of the file.
527
528Interesting effects are seen when using CTRL-T and CTRL-D. The characters
529before the cursor are shifted sideways as normal, but characters later in the
530line still remain still. CTRL-T will hide some of the old line under the
531shifted characters, but CTRL-D will reveal them again.
532
533As with Replace mode, using <BS> etc will bring back the characters that were
534replaced. This still works in conjunction with 'smartindent', CTRL-T and
535CTRL-D, 'expandtab', 'smarttab', 'softtabstop', etc.
536
537In 'list' mode, Virtual Replace mode acts as if it was not in 'list' mode,
538unless "L" is in 'cpoptions'.
539
540Note that the only times characters beyond the cursor should appear to move
541are in 'list' mode, and occasionally when 'wrap' is set (and the line changes
542length to become shorter or wider than the width of the screen), or
543momentarily when typing over a CTRL character. A CTRL character takes up two
544screen spaces. When replacing it with two normal characters, the first will
545be inserted and the second will replace the CTRL character.
546
547This mode is very useful for editing <Tab> separated columns in tables, for
548entering new data while keeping all the columns aligned.
549
550==============================================================================
5517. Insert mode completion *ins-completion*
552
Bram Moolenaar4be06f92005-07-29 22:36:03 +0000553In Insert and Replace mode, there are several commands to complete part of a
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554keyword or line that has been typed. This is useful if you are using
555complicated keywords (e.g., function names with capitals and underscores).
556
557These commands are not available when the |+insert_expand| feature was
558disabled at compile time.
559
560Completion can be done for:
561
5621. Whole lines |i_CTRL-X_CTRL-L|
5632. keywords in the current file |i_CTRL-X_CTRL-N|
5643. keywords in 'dictionary' |i_CTRL-X_CTRL-K|
5654. keywords in 'thesaurus', thesaurus-style |i_CTRL-X_CTRL-T|
5665. keywords in the current and included files |i_CTRL-X_CTRL-I|
5676. tags |i_CTRL-X_CTRL-]|
5687. file names |i_CTRL-X_CTRL-F|
5698. definitions or macros |i_CTRL-X_CTRL-D|
5709. Vim command-line |i_CTRL-X_CTRL-V|
Bram Moolenaar4be06f92005-07-29 22:36:03 +000057110. User defined completion |i_CTRL-X_CTRL-U|
Bram Moolenaarf75a9632005-09-13 21:20:47 +000057211. omni completion |i_CTRL-X_CTRL-O|
Bram Moolenaar488c6512005-08-11 20:09:58 +000057312. Spelling suggestions |i_CTRL-X_s|
57413. keywords in 'complete' |i_CTRL-N|
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575
576All these (except 2) are done in CTRL-X mode. This is a sub-mode of Insert
577and Replace modes. You enter CTRL-X mode by typing CTRL-X and one of the
578CTRL-X commands. You exit CTRL-X mode by typing a key that is not a valid
579CTRL-X mode command. Valid keys are the CTRL-X command itself, CTRL-N (next),
580and CTRL-P (previous).
581
582Also see the 'infercase' option if you want to adjust the case of the match.
583
584Note: The keys that are valid in CTRL-X mode are not mapped. This allows for
585":map ^F ^X^F" to work (where ^F is CTRL-F and ^X is CTRL-X). The key that
586ends CTRL-X mode (any key that is not a valid CTRL-X mode command) is mapped.
587Also, when doing completion with 'complete' mappings apply as usual.
588
589The following mappings are suggested to make typing the completion commands
590a bit easier (although they will hide other commands): >
591 :inoremap ^] ^X^]
592 :inoremap ^F ^X^F
593 :inoremap ^D ^X^D
594 :inoremap ^L ^X^L
595
596As a special case, typing CTRL-R to perform register insertion (see
597|i_CTRL-R|) will not exit CTRL-X mode. This is primarily to allow the use of
598the '=' register to call some function to determine the next operation. If
599the contents of the register (or result of the '=' register evaluation) are
600not valid CTRL-X mode keys, then CTRL-X mode will be exited as if those keys
601had been typed.
602
603For example, the following will map <Tab> to either actually insert a <Tab> if
604the current line is currently only whitespace, or start/continue a CTRL-N
605completion operation: >
606
607 function! CleverTab()
608 if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
609 return "\<Tab>"
610 else
611 return "\<C-N>"
612 endfunction
613 inoremap <Tab> <C-R>=CleverTab()<CR>
614
615
616
617Completing whole lines *compl-whole-line*
618
619 *i_CTRL-X_CTRL-L*
620CTRL-X CTRL-L Search backwards for a line that starts with the
Bram Moolenaar83bab712005-08-01 21:58:57 +0000621 same characters as those in the current line before
622 the cursor. Indent is ignored. The matching line is
Bram Moolenaar071d4272004-06-13 20:20:40 +0000623 inserted in front of the cursor.
Bram Moolenaar83bab712005-08-01 21:58:57 +0000624 The 'complete' option is used to decide which buffers
625 are searched for a match. Only loaded buffers are
626 used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627 CTRL-L or
628 CTRL-P Search backwards for next matching line. This line
629 replaces the previous matching line.
630
631 CTRL-N Search forward for next matching line. This line
632 replaces the previous matching line.
633
634 CTRL-X CTRL-L After expanding a line you can additionally get the
635 line next to it by typing CTRL-X CTRL-L again, unless
636 a double CTRL-X is used.
637
638Completing keywords in current file *compl-current*
639
640 *i_CTRL-X_CTRL-P*
641 *i_CTRL-X_CTRL-N*
642CTRL-X CTRL-N Search forwards for words that start with the keyword
643 in front of the cursor. The found keyword is inserted
644 in front of the cursor.
645
646CTRL-X CTRL-P Search backwards for words that start with the keyword
647 in front of the cursor. The found keyword is inserted
648 in front of the cursor.
649
650 CTRL-N Search forward for next matching keyword. This
651 keyword replaces the previous matching keyword.
652
653 CTRL-P Search backwards for next matching keyword. This
654 keyword replaces the previous matching keyword.
655
656 CTRL-X CTRL-N or
657 CTRL-X CTRL-P Further use of CTRL-X CTRL-N or CTRL-X CTRL-P will
658 copy the words following the previous expansion in
659 other contexts unless a double CTRL-X is used.
660
661If there is a keyword in front of the cursor (a name made out of alphabetic
662characters and characters in 'iskeyword'), it is used as the search pattern,
663with "\<" prepended (meaning: start of a word). Otherwise "\<\k\k" is used
664as search pattern (start of any keyword of at least two characters).
665
666In Replace mode, the number of characters that are replaced depends on the
667length of the matched string. This works like typing the characters of the
668matched string in Replace mode.
669
670If there is not a valid keyword character before the cursor, any keyword of
671at least two characters is matched.
672 e.g., to get:
673 printf("(%g, %g, %g)", vector[0], vector[1], vector[2]);
674 just type:
675 printf("(%g, %g, %g)", vector[0], ^P[1], ^P[2]);
676
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000677The search wraps around the end of the file, the value of 'wrapscan' is not
678used here.
679
Bram Moolenaar071d4272004-06-13 20:20:40 +0000680Multiple repeats of the same completion are skipped; thus a different match
681will be inserted at each CTRL-N and CTRL-P (unless there is only one
682matching keyword).
683
684Single character matches are never included, as they usually just get in
685the way of what you were really after.
686 e.g., to get:
687 printf("name = %s\n", name);
688 just type:
689 printf("name = %s\n", n^P);
690 or even:
691 printf("name = %s\n", ^P);
692The 'n' in '\n' is skipped.
693
694After expanding a word, you can use CTRL-X CTRL-P or CTRL-X CTRL-N to get the
695word following the expansion in other contexts. These sequences search for
696the text just expanded and further expand by getting an extra word. This is
697useful if you need to repeat a sequence of complicated words. Although CTRL-P
698and CTRL-N look just for strings of at least two characters, CTRL-X CTRL-P and
699CTRL-X CTRL-N can be used to expand words of just one character.
700 e.g., to get:
701 M&eacute;xico
702 you can type:
703 M^N^P^X^P^X^P
704CTRL-N starts the expansion and then CTRL-P takes back the single character
705"M", the next two CTRL-X CTRL-P's get the words "&eacute" and ";xico".
706
707If the previous expansion was split, because it got longer than 'textwidth',
708then just the text in the current line will be used.
709
710If the match found is at the end of a line, then the first word in the next
711line will be inserted and the message "word from next line" displayed, if
712this word is accepted the next CTRL-X CTRL-P or CTRL-X CTRL-N will search
713for those lines starting with this word.
714
715
716Completing keywords in 'dictionary' *compl-dictionary*
717
718 *i_CTRL-X_CTRL-K*
719CTRL-X CTRL-K Search the files given with the 'dictionary' option
720 for words that start with the keyword in front of the
721 cursor. This is like CTRL-N, but only the dictionary
722 files are searched, not the current file. The found
723 keyword is inserted in front of the cursor. This
724 could potentially be pretty slow, since all matches
725 are found before the first match is used. By default,
726 the 'dictionary' option is empty.
727 For suggestions where to find a list of words, see the
728 'dictionary' option.
729
730 CTRL-K or
731 CTRL-N Search forward for next matching keyword. This
732 keyword replaces the previous matching keyword.
733
734 CTRL-P Search backwards for next matching keyword. This
735 keyword replaces the previous matching keyword.
736
737 *i_CTRL-X_CTRL-T*
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000738CTRL-X CTRL-T Works as CTRL-X CTRL-K, but in a special way. It uses
Bram Moolenaar071d4272004-06-13 20:20:40 +0000739 the 'thesaurus' option instead of 'dictionary'. If a
740 match is found in the thesaurus file, all the
741 remaining words on the same line are included as
742 matches, even though they don't complete the word.
743 Thus a word can be completely replaced.
744
745 For an example, imagine the 'thesaurus' file has a
746 line like this: >
747 angry furious mad enraged
748< Placing the cursor after the letters "ang" and typing
749 CTRL-X CTRL-T would complete the word "angry";
750 subsequent presses would change the word to "furious",
751 "mad" etc.
752 Other uses include translation between two languages,
753 or grouping API functions by keyword.
754
755 CTRL-T or
756 CTRL-N Search forward for next matching keyword. This
757 keyword replaces the previous matching keyword.
758
759 CTRL-P Search backwards for next matching keyword. This
760 keyword replaces the previous matching keyword.
761
762
763Completing keywords in the current and included files *compl-keyword*
764
765The 'include' option is used to specify a line that contains an include file
766name. The 'path' option is used to search for include files.
767
768 *i_CTRL-X_CTRL-I*
769CTRL-X CTRL-I Search for the first keyword in the current and
770 included files that starts with the same characters
771 as those before the cursor. The matched keyword is
772 inserted in front of the cursor.
773
774 CTRL-N Search forwards for next matching keyword. This
775 keyword replaces the previous matching keyword.
776 Note: CTRL-I is the same as <Tab>, which is likely to
777 be typed after a successful completion, therefore
778 CTRL-I is not used for searching for the next match.
779
780 CTRL-P Search backward for previous matching keyword. This
781 keyword replaces the previous matching keyword.
782
783 CTRL-X CTRL-I Further use of CTRL-X CTRL-I will copy the words
784 following the previous expansion in other contexts
785 unless a double CTRL-X is used.
786
787Completing tags *compl-tag*
788 *i_CTRL-X_CTRL-]*
789CTRL-X CTRL-] Search for the first tag that starts with the same
790 characters as before the cursor. The matching tag is
791 inserted in front of the cursor. Alphabetic
792 characters and characters in 'iskeyword' are used
793 to decide which characters are included in the tag
794 name (same as for a keyword). See also |CTRL-]|.
795 The 'showfulltag' option can be used to add context
796 from around the tag definition.
797 CTRL-] or
798 CTRL-N Search forwards for next matching tag. This tag
799 replaces the previous matching tag.
800
801 CTRL-P Search backward for previous matching tag. This tag
802 replaces the previous matching tag.
803
804
805Completing file names *compl-filename*
806 *i_CTRL-X_CTRL-F*
807CTRL-X CTRL-F Search for the first file name that starts with the
808 same characters as before the cursor. The matching
809 file name is inserted in front of the cursor.
810 Alphabetic characters and characters in 'isfname'
811 are used to decide which characters are included in
812 the file name. Note: the 'path' option is not used
813 here (yet).
814 CTRL-F or
815 CTRL-N Search forwards for next matching file name. This
816 file name replaces the previous matching file name.
817
818 CTRL-P Search backward for previous matching file name.
819 This file name replaces the previous matching file
820 name.
821
822
823Completing definitions or macros *compl-define*
824
825The 'define' option is used to specify a line that contains a definition.
826The 'include' option is used to specify a line that contains an include file
827name. The 'path' option is used to search for include files.
828
829 *i_CTRL-X_CTRL-D*
830CTRL-X CTRL-D Search in the current and included files for the
831 first definition (or macro) name that starts with
832 the same characters as before the cursor. The found
833 definition name is inserted in front of the cursor.
834 CTRL-D or
835 CTRL-N Search forwards for next matching macro name. This
836 macro name replaces the previous matching macro
837 name.
838
839 CTRL-P Search backward for previous matching macro name.
840 This macro name replaces the previous matching macro
841 name.
842
843 CTRL-X CTRL-D Further use of CTRL-X CTRL-D will copy the words
844 following the previous expansion in other contexts
845 unless a double CTRL-X is used.
846
847
848Completing Vim commands *compl-vim*
849
850Completion is context-sensitive. It works like on the Command-line. It
Bram Moolenaar4be06f92005-07-29 22:36:03 +0000851completes an Ex command as well as its arguments. This is useful when writing
852a Vim script.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000853
854 *i_CTRL-X_CTRL-V*
855CTRL-X CTRL-V Guess what kind of item is in front of the cursor and
856 find the first match for it.
857 Note: When CTRL-V is mapped you can often use CTRL-Q
858 instead |i_CTRL-Q|.
859 CTRL-V or
860 CTRL-N Search forwards for next match. This match replaces
861 the previous one.
862
863 CTRL-P Search backward for previous match. This match
864 replaces the previous one.
865
866 CTRL-X CTRL-V Further use of CTRL-X CTRL-V will do the same as
867 CTRL-V. This allows mapping a key to do Vim command
868 completion, for example: >
869 :imap <Tab> <C-X><C-V>
870
Bram Moolenaar4be06f92005-07-29 22:36:03 +0000871User defined completion *compl-function*
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000872
873Completion is done by a function that can be defined by the user with the
Bram Moolenaare344bea2005-09-01 20:46:49 +0000874'completefunc' option. See the 'completefunc' help for how the function
875is called and an example.
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000876
877 *i_CTRL-X_CTRL-U*
878CTRL-X CTRL-U Guess what kind of item is in front of the cursor and
879 find the first match for it.
880 CTRL-U or
881 CTRL-N Use the next match. This match replaces the previous
882 one.
883
884 CTRL-P Use the previous match. This match replaces the
885 previous one.
886
887
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000888Omni completion *compl-omni*
Bram Moolenaar4be06f92005-07-29 22:36:03 +0000889
Bram Moolenaare344bea2005-09-01 20:46:49 +0000890Completion is done by a function that can be defined by the user with the
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000891'omnifunc' option. This is to be used for filetype-specific completion.
Bram Moolenaare344bea2005-09-01 20:46:49 +0000892
893See the 'completefunc' help for how the function is called and an example.
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000894For remarks about specific filetypes see |compl-omni-filetypes|.
Bram Moolenaar4be06f92005-07-29 22:36:03 +0000895
896 *i_CTRL-X_CTRL-O*
897CTRL-X CTRL-O Guess what kind of item is in front of the cursor and
898 find the first match for it.
899 CTRL-O or
900 CTRL-N Use the next match. This match replaces the previous
901 one.
902
903 CTRL-P Use the previous match. This match replaces the
904 previous one.
905
906
Bram Moolenaar488c6512005-08-11 20:09:58 +0000907Spelling suggestions *compl-spelling*
908
Bram Moolenaar5195e452005-08-19 20:32:47 +0000909A word before or at the cursor is located and correctly spelled words are
910suggested to replace it. If there is a badly spelled word in the line, before
911or under the cursor, the cursor is moved to after it. Otherwise the word just
912before the cursor is used for suggestions, even though it isn't badly spelled.
913
Bram Moolenaar488c6512005-08-11 20:09:58 +0000914NOTE: CTRL-S suspends display in many Unix terminals. Use 's' instead. Type
915CTRL-Q to resume displaying.
916
917 *i_CTRL-X_CTRL-S* *i_CTRL-X_s*
918CTRL-X CTRL-S or
919CTRL-X s Locate the word in front of the cursor and find the
920 first spell suggestion for it.
921 CTRL-S or
922 CTRL-N Use the next suggestion. This replaces the previous
923 one. Note that you can't use 's' here.
924
925 CTRL-P Use the previous suggestion. This replaces the
926 previous one.
927
928
Bram Moolenaar071d4272004-06-13 20:20:40 +0000929Completing keywords from different sources *compl-generic*
930
931 *i_CTRL-N*
932CTRL-N Find next match for words that start with the
933 keyword in front of the cursor, looking in places
934 specified with the 'complete' option. The found
935 keyword is inserted in front of the cursor.
936
937 *i_CTRL-P*
938CTRL-P Find previous match for words that start with the
939 keyword in front of the cursor, looking in places
940 specified with the 'complete' option. The found
941 keyword is inserted in front of the cursor.
942
943 CTRL-N Search forward for next matching keyword. This
944 keyword replaces the previous matching keyword.
945
946 CTRL-P Search backwards for next matching keyword. This
947 keyword replaces the previous matching keyword.
948
949 CTRL-X CTRL-N or
950 CTRL-X CTRL-P Further use of CTRL-X CTRL-N or CTRL-X CTRL-P will
951 copy the words following the previous expansion in
952 other contexts unless a double CTRL-X is used.
953
Bram Moolenaar578b49e2005-09-10 19:22:57 +0000954
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000955INSERT COMPLETION POPUP MENU *ins-completion-menu*
Bram Moolenaarebefac62005-12-28 22:39:57 +0000956 *popupmenu-completion*
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000957Vim can display the matches in a simplistic popup menu.
958
959The menu is used when:
960- The 'completeopt' option contains "menu".
961- The terminal supports at least 8 colors.
962- There are at least two matches.
963
964While the menu is displayed these keys have a special meaning:
965<CR> and <Enter>: Accept the currently selected match
Bram Moolenaar4770d092006-01-12 23:22:24 +0000966<Up>: Select the previous match, as if CTRL-P was used
967<Down>: Select the next match, as if CTRL-N was used
Bram Moolenaard35f9712005-12-18 22:02:33 +0000968<PageUp>: Select a match several entries back
969<PageDown>: Select a match several entries further
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000970
971The colors of the menu can be changed with these highlight groups:
972Pmenu normal item |hl-Pmenu|
973PmenuSel selected item |hl-PmenuSel|
974PmenuSbar scrollbar |hl-PmenuSbar|
975PmenuThumb thumb of the scrollbar |hl-PmenuThumb|
976
977
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000978Filetype-specific remarks for omni completion *compl-omni-filetypes*
Bram Moolenaar578b49e2005-09-10 19:22:57 +0000979
Bram Moolenaara5792f52005-11-23 21:25:05 +0000980
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000981C *ft-c-omni*
Bram Moolenaar578b49e2005-09-10 19:22:57 +0000982
Bram Moolenaarf75a9632005-09-13 21:20:47 +0000983Completion of C code requires a tags file. You should use Exuberant ctags,
984because it adds extra information that is needed for completion. You can find
985it here: http://ctags.sourceforge.net/
986For version 5.5.4 you should add a patch that adds the "typename:" field:
Bram Moolenaar578b49e2005-09-10 19:22:57 +0000987ftp://ftp.vim.org/pub/vim/unstable/patches/ctags-5.5.4.patch
988
989If you want to complete system functions you can do something like this. Use
990ctags to generate a tags file for all the system header files: >
991 % ctags -R -f ~/.vim/systags /usr/include /usr/local/include
992In your vimrc file add this tags file to the 'tags' option: >
993 set tags+=~/.vim/systags
994
995When using CTRL-X CTRL-O after a name without any "." or "->" it is completed
996from the tags file directly. This works for any identifier, also function
997names. If you want to complete a local variable name, which does not appear
998in the tags file, use CTRL-P instead.
999
1000When using CTRL-X CTRL-O after something that has "." or "->" Vim will attempt
1001to recognize the type of the variable and figure out what members it has.
1002This means only members valid for the variable will be listed.
1003
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001004When a member name already was complete, CTRL-X CTRL-O will add a "." or
1005"->" for composite types.
1006
Bram Moolenaar578b49e2005-09-10 19:22:57 +00001007Vim doesn't include a C compiler, only the most obviously formatted
1008declarations are recognized. Preprocessor stuff may cause confusion.
1009When the same structure name appears in multiple places all possible members
1010are included.
1011
Bram Moolenaar6b730e12005-09-16 21:47:57 +00001012
Bram Moolenaar4770d092006-01-12 23:22:24 +00001013CSS *ft-css-omni*
Bram Moolenaara5792f52005-11-23 21:25:05 +00001014
1015Complete properties and their appropriate values according to CSS 2.1
1016specification.
1017
1018
Bram Moolenaar4770d092006-01-12 23:22:24 +00001019(X)HTML *ft-html-omni*
1020 *ft-xhtml-omni*
Bram Moolenaar6b730e12005-09-16 21:47:57 +00001021
Bram Moolenaar1e015462005-09-25 22:16:38 +00001022CTRL-X CTRL-O provides completion of various elements of (X)HTML files.
1023It is designed to support writing of XHTML 1.0 Strict files but will
1024also works for other versions of HTML. Features:
Bram Moolenaar6b730e12005-09-16 21:47:57 +00001025
Bram Moolenaar1e015462005-09-25 22:16:38 +00001026- after "<" complete tag name depending on context (no div suggest
1027 inside of an a tag)
1028- inside of tag complete proper attributes (no width attribute for an
1029 a tag)
1030- when attribute has limited number of possible values help to complete
1031 them
Bram Moolenaara5792f52005-11-23 21:25:05 +00001032- complete names of entities
Bram Moolenaar1e015462005-09-25 22:16:38 +00001033- complete values of "class" and "id" attributes with data obtained from
1034 style tag and included CSS files
1035- when completing "style" attribute or working inside of "style" tag
1036 switch to |ft-css-omni| completion
1037- when used after "</" CTRL-X CTRL-O will close the last opened tag
Bram Moolenaar6b730e12005-09-16 21:47:57 +00001038
Bram Moolenaara5792f52005-11-23 21:25:05 +00001039Note: When used first time completion menu will be shown with little delay
1040- this is time needed for loading of data file.
1041
1042
Bram Moolenaar4770d092006-01-12 23:22:24 +00001043SYNTAX *ft-syntax-omni*
1044
1045This uses the current syntax highlighting for completion. It can be used for
1046any filetype and provides a minimal language-sensitive completion.
1047
1048To enable code completion do: >
1049 source $VIMRUNTIME/autoload/syntaxcomplete.vim
1050
1051You can automate this by placing this in your vimrc (after any ":filetype"
1052command): >
1053 autocmd Filetype *
1054 \ if exists('&ofu') && &ofu == "" |
1055 \ source $VIMRUNTIME/autoload/syntaxcomplete.vim |
1056 \ endif
1057
1058The above will set completion to this script only if a proper one does not
1059already exist for that filetype.
1060
1061
1062XML *ft-xml-omni*
Bram Moolenaara5792f52005-11-23 21:25:05 +00001063
Bram Moolenaar5b962cf2005-12-12 21:58:40 +00001064Vim 7 provides mechanism to context aware completion of XML files. It depends
1065on special |xml-omni-datafile| and two commands: |:XMLns| and |:XMLent|.
1066Features are:
Bram Moolenaara5792f52005-11-23 21:25:05 +00001067
1068- after "<" complete tag name depending on context (no div suggest
1069 inside of an a tag)
1070- inside of tag complete proper attributes (no width attribute for an
1071 a tag)
1072- when attribute has limited number of possible values help to complete
1073 them
Bram Moolenaar5b962cf2005-12-12 21:58:40 +00001074- complete names of entities (defined in |xml-omni-datafile| and in current file
Bram Moolenaara5792f52005-11-23 21:25:05 +00001075 with "<!ENTITY" declarations
1076- when used after "</" CTRL-X CTRL-O will close the last opened tag
1077
Bram Moolenaar4770d092006-01-12 23:22:24 +00001078Format of XML data file *xml-omni-datafile*
Bram Moolenaara5792f52005-11-23 21:25:05 +00001079
1080Vim distribution provides two data files as examples (xhtml10s.vim, xsl.vim)
1081
1082XML data files are stored in "autoload/xml" directory in 'runtimepath'. They
1083have meaningful name which will be used in commands. It should be unique name
1084which will not create conflicts in future. For example name xhtml10s.vim means
1085it is data file for XHTML 1.0 Strict.
1086
1087File contains one variable with fixed name: g:xmldata_xhtml10s . It is
1088compound from two parts:
1089
10901. "g:xmldata_" general prefix
10912. "xhtml10s" name of file and name of described XML dialect
1092
1093Part two must be exactly the same as name of file.
1094
1095Variable is data structure in form of |Dictionary|. Keys are tag names and
1096values are two element |List|. First element of List is also List with
1097names of possible children, second element is |Dictionary| with names of
1098attributes as keys and possible values of attributes as values. Example: >
1099
1100 let g:xmldata_crippledhtml = {
1101 \ "html":
1102 \ [ ["body", "head"], {"id": [], "xmlns": ["http://www.w3.org/1999/xhtml"],
1103 \ "lang": [], "xml:lang": [], "dir": ["ltr", "rtl"]}],
1104 \ "script":
1105 \ [ [], {"id": [], "charset": [], "type": ["text/javascript"], "src": [],
1106 \ "defer": ["BOOL"], "xml:space": ["preserve"]}],
1107 \ "meta":
1108 \ [ [], {"id": [], "http-equiv": [], "name": [], "content": [], "scheme":
1109 \ [], "lang": [], "xml:lang": [], "dir": ["ltr", "rtl"]}]
1110 \ "vimxmlentities": ["amp", "lt", "gt", "apos", "quot"]}
1111
1112This example should be put in "autoload/xml/crippledhtml.vim" file.
1113
1114In example are visible two special elements:
1115
11161. "vimxmlentities" - special key with List containing entities of this XML
1117 dialect.
11182. "BOOL" - value of attribute key showing if attribute should be inserted
1119 bare ("defer" vs. 'defer="'). It can be the only element of List of
1120 attribute values.
1121
1122Note: Tag names in data file MUST not contain namespace description. Check
1123xsl.vim for example.
1124
1125Commands
1126
Bram Moolenaar4770d092006-01-12 23:22:24 +00001127:XMLns {name} [{namespace}] *:XMLns*
Bram Moolenaara5792f52005-11-23 21:25:05 +00001128
1129Vim has to know which data file should be used and with which namespace. For
1130loading of data file and connecting data with prope namespace use |:XMLns|
1131command. First (obligatory) argument is name of data (xhtml10s, xsl). Second
1132argument is code of namespace (h, xsl). When used without second argument
1133dialect will be used as default - without namespace declaration. For example
1134to use XML completion in .xsl files: >
1135
1136 :XMLns xhtml10s
1137 :XMLns xsl xsl
1138
1139
Bram Moolenaar4770d092006-01-12 23:22:24 +00001140:XMLent {name} *:XMLent*
Bram Moolenaara5792f52005-11-23 21:25:05 +00001141
1142By default entities will be completed from data file of default
1143namespace. XMLent command should be used in case when there is no
1144default namespace: >
1145
Bram Moolenaar4770d092006-01-12 23:22:24 +00001146 :XMLent xhtml10s
Bram Moolenaara5792f52005-11-23 21:25:05 +00001147
1148Usage
1149
1150While used in situation (after declarations from previous part, | is
1151cursor position): >
1152
Bram Moolenaar4770d092006-01-12 23:22:24 +00001153 <|
Bram Moolenaara5792f52005-11-23 21:25:05 +00001154
1155Will complete to appropriate XHTML tag, and in this situation: >
1156
Bram Moolenaar4770d092006-01-12 23:22:24 +00001157 <xsl:|
Bram Moolenaara5792f52005-11-23 21:25:05 +00001158
1159Will complete to appropriate XSL tag.
1160
1161File xmlcomplete.vim provides through |autoload| mechanism
Bram Moolenaar6b730e12005-09-16 21:47:57 +00001162GetLastOpenTag function which can be used in XML files to get name of
Bram Moolenaar1e015462005-09-25 22:16:38 +00001163last open tag with (b:unaryTagsStack has to be defined): >
Bram Moolenaar6b730e12005-09-16 21:47:57 +00001164
Bram Moolenaar4770d092006-01-12 23:22:24 +00001165 :echo xmlcomplete#GetLastOpenTag("b:unaryTagsStack")
Bram Moolenaarbfd8fc02005-09-20 23:22:24 +00001166
Bram Moolenaar6b730e12005-09-16 21:47:57 +00001167
Bram Moolenaar1e015462005-09-25 22:16:38 +00001168
Bram Moolenaar1e015462005-09-25 22:16:38 +00001169
1170
Bram Moolenaar071d4272004-06-13 20:20:40 +00001171==============================================================================
11728. Insert mode commands *inserting*
1173
1174The following commands can be used to insert new text into the buffer. They
1175can all be undone and repeated with the "." command.
1176
1177 *a*
1178a Append text after the cursor [count] times. If the
1179 cursor is in the first column of an empty line Insert
1180 starts there. But not when 'virtualedit' is set!
1181
1182 *A*
1183A Append text at the end of the line [count] times.
1184
1185<insert> or *i* *insert* *<Insert>*
1186i Insert text before the cursor [count] times.
1187 When using CTRL-O in Insert mode |i_CTRL-O| the count
1188 is not supported.
1189
1190 *I*
1191I Insert text before the first non-blank in the line
1192 [count] times.
Bram Moolenaar4399ef42005-02-12 14:29:27 +00001193 When the 'H' flag is present in 'cpoptions' and the
1194 line only contains blanks, insert start just before
1195 the last blank.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001196
1197 *gI*
1198gI Insert text in column 1 [count] times. {not in Vi}
1199
1200 *gi*
1201gi Insert text in the same position as where Insert mode
1202 was stopped last time in the current buffer.
1203 This uses the |'^| mark. It's different from "`^i"
1204 when the mark is past the end of the line.
1205 The position is corrected for inserted/deleted lines,
1206 but NOT for inserted/deleted characters.
1207 When the |:keepjumps| command modifier is used the |'^|
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001208 mark won't be changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001209 {not in Vi}
1210
1211 *o*
1212o Begin a new line below the cursor and insert text,
1213 repeat [count] times. {Vi: blank [count] screen
1214 lines}
Bram Moolenaar4399ef42005-02-12 14:29:27 +00001215 When the '#' flag is in 'cpoptions' the count is
1216 ignored.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217
1218 *O*
1219O Begin a new line above the cursor and insert text,
1220 repeat [count] times. {Vi: blank [count] screen
1221 lines}
Bram Moolenaar4399ef42005-02-12 14:29:27 +00001222 When the '#' flag is in 'cpoptions' the count is
1223 ignored.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224
1225These commands are used to start inserting text. You can end insert mode with
1226<Esc>. See |mode-ins-repl| for the other special characters in Insert mode.
1227The effect of [count] takes place after Insert mode is exited.
1228
1229When 'autoindent' is on, the indent for a new line is obtained from the
1230previous line. When 'smartindent' or 'cindent' is on, the indent for a line
1231is automatically adjusted for C programs.
1232
1233'textwidth' can be set to the maximum width for a line. When a line becomes
1234too long when appending characters a line break is automatically inserted.
1235
1236
1237==============================================================================
12389. Ex insert commands *inserting-ex*
1239
1240 *:a* *:append*
Bram Moolenaardf177f62005-02-22 08:39:57 +00001241:{range}a[ppend][!] Insert several lines of text below the specified
Bram Moolenaar071d4272004-06-13 20:20:40 +00001242 line. If the {range} is missing, the text will be
1243 inserted after the current line.
Bram Moolenaardf177f62005-02-22 08:39:57 +00001244 Adding [!] toggles 'autoindent' for the time this
1245 command is executed.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001246
1247 *:i* *:in* *:insert*
Bram Moolenaardf177f62005-02-22 08:39:57 +00001248:{range}i[nsert][!] Insert several lines of text above the specified
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249 line. If the {range} is missing, the text will be
1250 inserted before the current line.
Bram Moolenaardf177f62005-02-22 08:39:57 +00001251 Adding [!] toggles 'autoindent' for the time this
1252 command is executed.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001253
1254These two commands will keep on asking for lines, until you type a line
1255containing only a ".". Watch out for lines starting with a backslash, see
1256|line-continuation|.
Bram Moolenaardf177f62005-02-22 08:39:57 +00001257When these commands are used with |:global| or |:vglobal| then the lines are
1258obtained from the text following the command. Separate lines with a NL
1259escaped with a backslash: >
1260 :global/abc/insert\
1261 one line\
1262 another line
1263The final "." is not needed then.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264NOTE: ":append" and ":insert" don't work properly in between ":if" and
Bram Moolenaar06fb4352005-01-05 22:10:30 +00001265":endif", ":for" and ":endfor", ":while" and ":endwhile".
Bram Moolenaar071d4272004-06-13 20:20:40 +00001266
1267 *:start* *:startinsert*
1268:star[tinsert][!] Start Insert mode just after executing this command.
1269 Works like typing "i" in Normal mode. When the ! is
1270 included it works like "A", append to the line.
1271 Otherwise insertion starts at the cursor position.
1272 Note that when using this command in a function or
1273 script, the insertion only starts after the function
1274 or script is finished.
Bram Moolenaar87e25fd2005-07-27 21:13:01 +00001275 This command does not work from |:normal|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 {not in Vi}
1277 {not available when compiled without the +ex_extra
1278 feature}
1279
1280 *:stopi* *:stopinsert*
1281:stopi[nsert] Stop Insert mode as soon as possible. Works like
1282 typing <Esc> in Insert mode.
1283 Can be used in an autocommand, example: >
1284 :au BufEnter scratch stopinsert
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001285<
1286 *replacing-ex* *:startreplace*
1287:startr[eplace][!] Start Replace mode just after executing this command.
1288 Works just like typing "R" in Normal mode. When the
1289 ! is included it acts just like "$R" had been typed
1290 (ie. begin replace mode at the end-of-line). Other-
1291 wise replacement begins at the cursor position.
1292 Note that when using this command in a function or
1293 script that the replacement will only start after
1294 the function or script is finished.
1295 {not in Vi}
1296 {not available when compiled without the +ex_extra
1297 feature}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001298
Bram Moolenaar61da4982005-12-14 22:02:18 +00001299 *:startgreplace*
1300:startg[replace][!] Just like |:startreplace|, but use Virtual Replace
1301 mode, like with |gR|.
1302 {not in Vi}
1303 {not available when compiled without the +ex_extra
1304 feature}
1305
Bram Moolenaar071d4272004-06-13 20:20:40 +00001306==============================================================================
130710. Inserting a file *inserting-file*
1308
1309 *:r* *:re* *:read*
1310:r[ead] [name] Insert the file [name] (default: current file) below
1311 the cursor.
1312
1313:{range}r[ead] [name] Insert the file [name] (default: current file) below
1314 the specified line.
1315
1316 *:r!* *:read!*
1317:r[ead] !{cmd} Execute {cmd} and insert its standard output below
1318 the cursor. A temporary file is used to store the
1319 output of the command which is then read into the
1320 buffer. 'shellredir' is used to save the output of
1321 the command, which can be set to include stderr or
1322 not. {cmd} is executed like with ":!{cmd}", any '!'
1323 is replaced with the previous command |:!|.
1324
1325These commands insert the contents of a file, or the output of a command,
1326into the buffer. They can be undone. They cannot be repeated with the "."
1327command. They work on a line basis, insertion starts below the line in which
1328the cursor is, or below the specified line. To insert text above the first
1329line use the command ":0r {name}".
1330
1331After the ":read" command, the cursor is left on the first non-blank in the
1332first new line. Unless in Ex mode, then the cursor is left on the last new
1333line (sorry, this is Vi compatible).
1334
1335If a file name is given with ":r", it becomes the alternate file. This can be
1336used, for example, when you want to edit that file instead: ":e! #". This can
1337be switched off by removing the 'a' flag from the 'cpoptions' option.
1338
1339 *file-read*
1340The 'fileformat' option sets the <EOL> style for a file:
1341'fileformat' characters name ~
1342 "dos" <CR><NL> or <NL> DOS format
1343 "unix" <NL> Unix format
1344 "mac" <CR> Mac format
1345Previously 'textmode' was used. It is obsolete now.
1346
1347If 'fileformat' is "dos", a <CR> in front of an <NL> is ignored and a CTRL-Z
1348at the end of the file is ignored.
1349
1350If 'fileformat' is "mac", a <NL> in the file is internally represented by a
1351<CR>. This is to avoid confusion with a <NL> which is used to represent a
1352<NUL>. See |CR-used-for-NL|.
1353
1354If the 'fileformats' option is not empty Vim tries to recognize the type of
1355<EOL> (see |file-formats|). However, the 'fileformat' option will not be
1356changed, the detected format is only used while reading the file.
1357A similar thing happens with 'fileencodings'.
1358
1359On non-MS-DOS, Win32, and OS/2 systems the message "[dos format]" is shown if
1360a file is read in DOS format, to remind you that something unusual is done.
1361On Macintosh, MS-DOS, Win32, and OS/2 the message "[unix format]" is shown if
1362a file is read in Unix format.
1363On non-Macintosh systems, the message "[Mac format]" is shown if a file is
1364read in Mac format.
1365
1366An example on how to use ":r !": >
1367 :r !uuencode binfile binfile
1368This command reads "binfile", uuencodes it and reads it into the current
1369buffer. Useful when you are editing e-mail and want to include a binary
1370file.
1371
1372 *read-messages*
1373When reading a file Vim will display a message with information about the read
1374file. In the table is an explanation for some of the items. The others are
1375self explanatory. Using the long or the short version depends on the
1376'shortmess' option.
1377
1378 long short meaning ~
1379 [readonly] {RO} the file is write protected
1380 [fifo/socket] using a stream
1381 [fifo] using a fifo stream
1382 [socket] using a socket stream
1383 [CR missing] reading with "dos" 'fileformat' and a
1384 NL without a preceding CR was found.
1385 [NL found] reading with "mac" 'fileformat' and a
1386 NL was found (could be "unix" format)
1387 [long lines split] at least one line was split in two
1388 [NOT converted] conversion from 'fileencoding' to
1389 'encoding' was desired but not
1390 possible
1391 [converted] conversion from 'fileencoding' to
1392 'encoding' done
1393 [crypted] file was decrypted
1394 [READ ERRORS] not all of the file could be read
1395
1396
1397 vim:tw=78:ts=8:ft=help:norl: