xref: /vim-8.2.3635/runtime/doc/insert.txt (revision 113cb513)
1*113cb513SBram Moolenaar*insert.txt*    For Vim version 8.2.  Last change: 2021 Oct 24
2071d4279SBram Moolenaar
3071d4279SBram Moolenaar
4071d4279SBram Moolenaar		  VIM REFERENCE MANUAL    by Bram Moolenaar
5071d4279SBram Moolenaar
6071d4279SBram Moolenaar
7071d4279SBram Moolenaar						*Insert* *Insert-mode*
8071d4279SBram MoolenaarInserting and replacing text				*mode-ins-repl*
9071d4279SBram Moolenaar
10071d4279SBram MoolenaarMost of this file is about Insert and Replace mode.  At the end are a few
11071d4279SBram Moolenaarcommands for inserting text in other ways.
12071d4279SBram Moolenaar
13071d4279SBram MoolenaarAn overview of the most often used commands can be found in chapter 24 of the
14071d4279SBram Moolenaaruser manual |usr_24.txt|.
15071d4279SBram Moolenaar
16071d4279SBram Moolenaar1. Special keys						|ins-special-keys|
17071d4279SBram Moolenaar2. Special special keys					|ins-special-special|
18071d4279SBram Moolenaar3. 'textwidth' and 'wrapmargin' options			|ins-textwidth|
19071d4279SBram Moolenaar4. 'expandtab', 'smarttab' and 'softtabstop'  options	|ins-expandtab|
20071d4279SBram Moolenaar5. Replace mode						|Replace-mode|
21071d4279SBram Moolenaar6. Virtual Replace mode					|Virtual-Replace-mode|
22071d4279SBram Moolenaar7. Insert mode completion				|ins-completion|
23071d4279SBram Moolenaar8. Insert mode commands					|inserting|
24071d4279SBram Moolenaar9. Ex insert commands					|inserting-ex|
25071d4279SBram Moolenaar10. Inserting a file					|inserting-file|
26071d4279SBram Moolenaar
27071d4279SBram MoolenaarAlso see 'virtualedit', for moving the cursor to positions where there is no
28071d4279SBram Moolenaarcharacter.  Useful for editing a table.
29071d4279SBram Moolenaar
30071d4279SBram Moolenaar==============================================================================
31071d4279SBram Moolenaar1. Special keys						*ins-special-keys*
32071d4279SBram Moolenaar
33071d4279SBram MoolenaarIn Insert and Replace mode, the following characters have a special meaning;
34071d4279SBram Moolenaarother characters are inserted directly.  To insert one of these special
35071d4279SBram Moolenaarcharacters into the buffer, precede it with CTRL-V.  To insert a <Nul>
36071d4279SBram Moolenaarcharacter use "CTRL-V CTRL-@" or "CTRL-V 000".  On some systems, you have to
37071d4279SBram Moolenaaruse "CTRL-V 003" to insert a CTRL-C.  Note: When CTRL-V is mapped you can
38071d4279SBram Moolenaaroften use CTRL-Q instead |i_CTRL-Q|.
39071d4279SBram Moolenaar
40071d4279SBram MoolenaarIf you are working in a special language mode when inserting text, see the
41071d4279SBram Moolenaar'langmap' option, |'langmap'|, on how to avoid switching this mode on and off
42071d4279SBram Moolenaarall the time.
43071d4279SBram Moolenaar
44071d4279SBram MoolenaarIf you have 'insertmode' set, <Esc> and a few other keys get another meaning.
45071d4279SBram MoolenaarSee |'insertmode'|.
46071d4279SBram Moolenaar
47071d4279SBram Moolenaarchar		action	~
48071d4279SBram Moolenaar-----------------------------------------------------------------------
49071d4279SBram Moolenaar						*i_CTRL-[* *i_<Esc>*
50071d4279SBram Moolenaar<Esc> or CTRL-[	End insert or Replace mode, go back to Normal mode.  Finish
51071d4279SBram Moolenaar		abbreviation.
52071d4279SBram Moolenaar		Note: If your <Esc> key is hard to hit on your keyboard, train
53071d4279SBram Moolenaar		yourself to use CTRL-[.
54fb539273SBram Moolenaar		If Esc doesn't work and you are using a Mac, try CTRL-Esc.
55fb539273SBram Moolenaar		Or disable Listening under Accessibility preferences.
56071d4279SBram Moolenaar						*i_CTRL-C*
57071d4279SBram MoolenaarCTRL-C		Quit insert mode, go back to Normal mode.  Do not check for
58677ee689SBram Moolenaar		abbreviations.  Does not trigger the |InsertLeave| autocommand
59677ee689SBram Moolenaar		event.
60071d4279SBram Moolenaar
61071d4279SBram Moolenaar						*i_CTRL-@*
62a6c27c47SBram MoolenaarCTRL-@		Insert previously inserted text and stop insert.
63a6c27c47SBram Moolenaar
64071d4279SBram Moolenaar						*i_CTRL-A*
6525c9c680SBram MoolenaarCTRL-A		Insert previously inserted text.
66071d4279SBram Moolenaar
67071d4279SBram Moolenaar						*i_CTRL-H* *i_<BS>* *i_BS*
68071d4279SBram Moolenaar<BS> or CTRL-H	Delete the character before the cursor (see |i_backspacing|
69071d4279SBram Moolenaar		about joining lines).
70071d4279SBram Moolenaar		See |:fixdel| if your <BS> key does not do what you want.
71a6c27c47SBram Moolenaar
72071d4279SBram Moolenaar						*i_<Del>* *i_DEL*
73071d4279SBram Moolenaar<Del>		Delete the character under the cursor.  If the cursor is at
74071d4279SBram Moolenaar		the end of the line, and the 'backspace' option includes
75071d4279SBram Moolenaar		"eol", delete the <EOL>; the next line is appended after the
76071d4279SBram Moolenaar		current one.
77071d4279SBram Moolenaar		See |:fixdel| if your <Del> key does not do what you want.
78071d4279SBram Moolenaar						*i_CTRL-W*
79071d4279SBram MoolenaarCTRL-W		Delete the word before the cursor (see |i_backspacing| about
80071d4279SBram Moolenaar		joining lines).  See the section "word motions",
81071d4279SBram Moolenaar		|word-motions|, for the definition of a word.
82071d4279SBram Moolenaar						*i_CTRL-U*
83f2571c61SBram MoolenaarCTRL-U		Delete all entered characters before the cursor in the current
84979243b9SBram Moolenaar		line.  If there are no newly entered characters and
85f2571c61SBram Moolenaar		'backspace' is not empty, delete all characters before the
86f2571c61SBram Moolenaar		cursor in the current line.
87f2571c61SBram Moolenaar		See |i_backspacing| about joining lines.
88071d4279SBram Moolenaar						*i_CTRL-I* *i_<Tab>* *i_Tab*
89071d4279SBram Moolenaar<Tab> or CTRL-I Insert a tab.  If the 'expandtab' option is on, the
90071d4279SBram Moolenaar		equivalent number of spaces is inserted (use CTRL-V <Tab> to
91071d4279SBram Moolenaar		avoid the expansion; use CTRL-Q <Tab> if CTRL-V is mapped
92071d4279SBram Moolenaar		|i_CTRL-Q|).  See also the 'smarttab' option and
93071d4279SBram Moolenaar		|ins-expandtab|.
94071d4279SBram Moolenaar						*i_CTRL-J* *i_<NL>*
95071d4279SBram Moolenaar<NL> or CTRL-J	Begin new line.
96071d4279SBram Moolenaar						*i_CTRL-M* *i_<CR>*
97071d4279SBram Moolenaar<CR> or CTRL-M	Begin new line.
98071d4279SBram Moolenaar						*i_CTRL-K*
99071d4279SBram MoolenaarCTRL-K {char1} [char2]
100071d4279SBram Moolenaar		Enter digraph (see |digraphs|).  When {char1} is a special
101071d4279SBram Moolenaar		key, the code for that key is inserted in <> form.  For
102071d4279SBram Moolenaar		example, the string "<S-Space>" can be entered by typing
103071d4279SBram Moolenaar		<C-K><S-Space> (two keys).  Neither char is considered for
10425c9c680SBram Moolenaar		mapping.
105071d4279SBram Moolenaar
10625c9c680SBram MoolenaarCTRL-N		Find next keyword (see |i_CTRL-N|).
10725c9c680SBram MoolenaarCTRL-P		Find previous keyword (see |i_CTRL-P|).
108071d4279SBram Moolenaar
1095be4ceecSBram MoolenaarCTRL-R {register}				*i_CTRL-R*
110071d4279SBram Moolenaar		Insert the contents of a register.  Between typing CTRL-R and
111071d4279SBram Moolenaar		the second character, '"' will be displayed to indicate that
112071d4279SBram Moolenaar		you are expected to enter the name of a register.
113071d4279SBram Moolenaar		The text is inserted as if you typed it, but mappings and
114071d4279SBram Moolenaar		abbreviations are not used.  If you have options like
115071d4279SBram Moolenaar		'textwidth', 'formatoptions', or 'autoindent' set, this will
116071d4279SBram Moolenaar		influence what will be inserted.  This is different from what
117071d4279SBram Moolenaar		happens with the "p" command and pasting with the mouse.
118071d4279SBram Moolenaar		Special registers:
119071d4279SBram Moolenaar			'"'	the unnamed register, containing the text of
120071d4279SBram Moolenaar				the last delete or yank
121071d4279SBram Moolenaar			'%'	the current file name
122071d4279SBram Moolenaar			'#'	the alternate file name
123071d4279SBram Moolenaar			'*'	the clipboard contents (X11: primary selection)
124071d4279SBram Moolenaar			'+'	the clipboard contents
125071d4279SBram Moolenaar			'/'	the last search pattern
126071d4279SBram Moolenaar			':'	the last command-line
127071d4279SBram Moolenaar			'.'	the last inserted text
128071d4279SBram Moolenaar			'-'	the last small (less than a line) delete
1298f3f58f2SBram Moolenaar							*i_CTRL-R_=*
130071d4279SBram Moolenaar			'='	the expression register: you are prompted to
131071d4279SBram Moolenaar				enter an expression (see |expression|)
132293ee4d4SBram Moolenaar				Note that 0x80 (128 decimal) is used for
1331d2ba7faSBram Moolenaar				special keys.  E.g., you can use this to move
1341d2ba7faSBram Moolenaar				the cursor up:
1351d2ba7faSBram Moolenaar					CTRL-R ="\<Up>"
1361d2ba7faSBram Moolenaar				Use CTRL-R CTRL-R to insert text literally.
137362e1a30SBram Moolenaar				When the result is a |List| the items are used
138362e1a30SBram Moolenaar				as lines.  They can have line breaks inside
139362e1a30SBram Moolenaar				too.
1408f3f58f2SBram Moolenaar				When the result is a Float it's automatically
1418f3f58f2SBram Moolenaar				converted to a String.
14294f76b7fSBram Moolenaar				When append() or setline() is invoked the undo
14394f76b7fSBram Moolenaar				sequence will be broken.
14425c9c680SBram Moolenaar		See |registers| about registers.
145071d4279SBram Moolenaar
1465be4ceecSBram MoolenaarCTRL-R CTRL-R {register}			*i_CTRL-R_CTRL-R*
147071d4279SBram Moolenaar		Insert the contents of a register.  Works like using a single
148071d4279SBram Moolenaar		CTRL-R, but the text is inserted literally, not as if typed.
149071d4279SBram Moolenaar		This differs when the register contains characters like <BS>.
150071d4279SBram Moolenaar		Example, where register a contains "ab^Hc": >
151071d4279SBram Moolenaar	CTRL-R a		results in "ac".
152071d4279SBram Moolenaar	CTRL-R CTRL-R a		results in "ab^Hc".
153071d4279SBram Moolenaar<		Options 'textwidth', 'formatoptions', etc. still apply.  If
154ca63501fSBram Moolenaar		you also want to avoid these, use CTRL-R CTRL-O, see below.
155071d4279SBram Moolenaar		The '.' register (last inserted text) is still inserted as
15625c9c680SBram Moolenaar		typed.
157d1caa941SBram Moolenaar		After this command, the '.' register contains the text from
158d1caa941SBram Moolenaar		the register as if it was inserted by typing it.
159071d4279SBram Moolenaar
1605be4ceecSBram MoolenaarCTRL-R CTRL-O {register}			*i_CTRL-R_CTRL-O*
161071d4279SBram Moolenaar		Insert the contents of a register literally and don't
162071d4279SBram Moolenaar		auto-indent.  Does the same as pasting with the mouse
163cd5c8f82SBram Moolenaar		|<MiddleMouse>|. When the register is linewise this will
164cd5c8f82SBram Moolenaar		insert the text above the current line, like with `P`.
165071d4279SBram Moolenaar		Does not replace characters!
166071d4279SBram Moolenaar		The '.' register (last inserted text) is still inserted as
16725c9c680SBram Moolenaar		typed.
168d1caa941SBram Moolenaar		After this command, the '.' register contains the command
169d1caa941SBram Moolenaar		typed and not the text. I.e., the literals "^R^O" and not the
170d1caa941SBram Moolenaar		text from the register.
171071d4279SBram Moolenaar
1725be4ceecSBram MoolenaarCTRL-R CTRL-P {register}			*i_CTRL-R_CTRL-P*
173071d4279SBram Moolenaar		Insert the contents of a register literally and fix the
174071d4279SBram Moolenaar		indent, like |[<MiddleMouse>|.
175071d4279SBram Moolenaar		Does not replace characters!
176071d4279SBram Moolenaar		The '.' register (last inserted text) is still inserted as
17725c9c680SBram Moolenaar		typed.
178d1caa941SBram Moolenaar		After this command, the '.' register contains the command
179d1caa941SBram Moolenaar		typed and not the text. I.e., the literals "^R^P" and not the
180d1caa941SBram Moolenaar		text from the register.
181071d4279SBram Moolenaar
182071d4279SBram Moolenaar						*i_CTRL-T*
183071d4279SBram MoolenaarCTRL-T		Insert one shiftwidth of indent at the start of the current
184071d4279SBram Moolenaar		line.  The indent is always rounded to a 'shiftwidth' (this is
185a6c27c47SBram Moolenaar		vi compatible).
186071d4279SBram Moolenaar						*i_CTRL-D*
187071d4279SBram MoolenaarCTRL-D		Delete one shiftwidth of indent at the start of the current
188071d4279SBram Moolenaar		line.  The indent is always rounded to a 'shiftwidth' (this is
189a6c27c47SBram Moolenaar		vi compatible).
190071d4279SBram Moolenaar						*i_0_CTRL-D*
191a6c27c47SBram Moolenaar0 CTRL-D	Delete all indent in the current line.
192a6c27c47SBram Moolenaar
193071d4279SBram Moolenaar						*i_^_CTRL-D*
194071d4279SBram Moolenaar^ CTRL-D	Delete all indent in the current line.  The indent is
195071d4279SBram Moolenaar		restored in the next line.  This is useful when inserting a
196a6c27c47SBram Moolenaar		label.
197071d4279SBram Moolenaar
198071d4279SBram Moolenaar						*i_CTRL-V*
199071d4279SBram MoolenaarCTRL-V		Insert next non-digit literally.  For special keys, the
200071d4279SBram Moolenaar		terminal code is inserted.  It's also possible to enter the
201071d4279SBram Moolenaar		decimal, octal or hexadecimal value of a character
202071d4279SBram Moolenaar		|i_CTRL-V_digit|.
203071d4279SBram Moolenaar		The characters typed right after CTRL-V are not considered for
204a6c27c47SBram Moolenaar		mapping.
205071d4279SBram Moolenaar		Note: When CTRL-V is mapped (e.g., to paste text) you can
206071d4279SBram Moolenaar		often use CTRL-Q instead |i_CTRL-Q|.
207fc4ea2a7SBram Moolenaar		When |modifyOtherKeys| is enabled then special Escape sequence
208fc4ea2a7SBram Moolenaar		is converted back to what it was without |modifyOtherKeys|,
209fc4ea2a7SBram Moolenaar		unless the Shift key is also pressed.
210fc4ea2a7SBram Moolenaar
211071d4279SBram Moolenaar						*i_CTRL-Q*
212071d4279SBram MoolenaarCTRL-Q		Same as CTRL-V.
213071d4279SBram Moolenaar		Note: Some terminal connections may eat CTRL-Q, it doesn't
214071d4279SBram Moolenaar		work then.  It does work in the GUI.
215071d4279SBram Moolenaar
2168024f936SBram MoolenaarCTRL-SHIFT-V				*i_CTRL-SHIFT-V* *i_CTRL-SHIFT-Q*
2178024f936SBram MoolenaarCTRL-SHIFT-Q	Works just like CTRL-V, unless |modifyOtherKeys| is active,
2188024f936SBram Moolenaar		then it inserts the Escape sequence for a key with modifiers.
2198024f936SBram Moolenaar
220071d4279SBram MoolenaarCTRL-X		Enter CTRL-X mode.  This is a sub-mode where commands can
221071d4279SBram Moolenaar		be given to complete words or scroll the window.  See
22225c9c680SBram Moolenaar		|i_CTRL-X| and |ins-completion|.
223071d4279SBram Moolenaar
224071d4279SBram Moolenaar						*i_CTRL-E*
22525c9c680SBram MoolenaarCTRL-E		Insert the character which is below the cursor.
226071d4279SBram Moolenaar						*i_CTRL-Y*
22725c9c680SBram MoolenaarCTRL-Y		Insert the character which is above the cursor.
228071d4279SBram Moolenaar		Note that for CTRL-E and CTRL-Y 'textwidth' is not used, to be
229071d4279SBram Moolenaar		able to copy characters from a long line.
230071d4279SBram Moolenaar
231071d4279SBram Moolenaar						*i_CTRL-_*
232071d4279SBram MoolenaarCTRL-_		Switch between languages, as follows:
233071d4279SBram Moolenaar		-  When in a rightleft window, revins and nohkmap are toggled,
234071d4279SBram Moolenaar		   since English will likely be inserted in this case.
235071d4279SBram Moolenaar		-  When in a norightleft window, revins and hkmap are toggled,
236071d4279SBram Moolenaar		   since Hebrew will likely be inserted in this case.
237071d4279SBram Moolenaar
238071d4279SBram Moolenaar		CTRL-_ moves the cursor to the end of the typed text.
239071d4279SBram Moolenaar
240071d4279SBram Moolenaar		This command is only available when the 'allowrevins' option
241071d4279SBram Moolenaar		is set.
242071d4279SBram Moolenaar		Please refer to |rileft.txt| for more information about
243071d4279SBram Moolenaar		right-to-left mode.
2449964e468SBram Moolenaar		Only if compiled with the |+rightleft| feature.
2459964e468SBram Moolenaar
246071d4279SBram Moolenaar						*i_CTRL-^*
247071d4279SBram MoolenaarCTRL-^		Toggle the use of typing language characters.
248071d4279SBram Moolenaar		When language |:lmap| mappings are defined:
249071d4279SBram Moolenaar		- If 'iminsert' is 1 (langmap mappings used) it becomes 0 (no
250071d4279SBram Moolenaar		  langmap mappings used).
251071d4279SBram Moolenaar		- If 'iminsert' has another value it becomes 1, thus langmap
252071d4279SBram Moolenaar		  mappings are enabled.
253071d4279SBram Moolenaar		When no language mappings are defined:
254071d4279SBram Moolenaar		- If 'iminsert' is 2 (Input Method used) it becomes 0 (no
255071d4279SBram Moolenaar		  Input Method used).
256071d4279SBram Moolenaar		- If 'iminsert' has another value it becomes 2, thus the Input
257071d4279SBram Moolenaar		  Method is enabled.
258071d4279SBram Moolenaar		When set to 1, the value of the "b:keymap_name" variable, the
259071d4279SBram Moolenaar		'keymap' option or "<lang>" appears in the status line.
260071d4279SBram Moolenaar		The language mappings are normally used to type characters
261071d4279SBram Moolenaar		that are different from what the keyboard produces.  The
262071d4279SBram Moolenaar		'keymap' option can be used to install a whole number of them.
263071d4279SBram Moolenaar
264071d4279SBram Moolenaar						*i_CTRL-]*
26525c9c680SBram MoolenaarCTRL-]		Trigger abbreviation, without inserting a character.
266071d4279SBram Moolenaar
267071d4279SBram Moolenaar						*i_<Insert>*
26825c9c680SBram Moolenaar<Insert>	Toggle between Insert and Replace mode.
269071d4279SBram Moolenaar-----------------------------------------------------------------------
270071d4279SBram Moolenaar
271071d4279SBram Moolenaar						*i_backspacing*
272071d4279SBram MoolenaarThe effect of the <BS>, CTRL-W, and CTRL-U depend on the 'backspace' option
273071d4279SBram Moolenaar(unless 'revins' is set).  This is a comma separated list of items:
274071d4279SBram Moolenaar
275071d4279SBram Moolenaaritem	    action ~
276071d4279SBram Moolenaarindent	    allow backspacing over autoindent
277071d4279SBram Moolenaareol	    allow backspacing over end-of-line (join lines)
278071d4279SBram Moolenaarstart	    allow backspacing over the start position of insert; CTRL-W and
279071d4279SBram Moolenaar	    CTRL-U stop once at the start position
280071d4279SBram Moolenaar
281071d4279SBram MoolenaarWhen 'backspace' is empty, Vi compatible backspacing is used.  You cannot
282071d4279SBram Moolenaarbackspace over autoindent, before column 1 or before where insert started.
283071d4279SBram Moolenaar
284071d4279SBram MoolenaarFor backwards compatibility the values "0", "1" and "2" are also allowed, see
285071d4279SBram Moolenaar|'backspace'|.
286071d4279SBram Moolenaar
287071d4279SBram MoolenaarIf the 'backspace' option does contain "eol" and the cursor is in column 1
288071d4279SBram Moolenaarwhen one of the three keys is used, the current line is joined with the
289071d4279SBram Moolenaarprevious line.  This effectively deletes the <EOL> in front of the cursor.
290071d4279SBram Moolenaar
291071d4279SBram Moolenaar						*i_CTRL-V_digit*
292071d4279SBram MoolenaarWith CTRL-V the decimal, octal or hexadecimal value of a character can be
293071d4279SBram Moolenaarentered directly.  This way you can enter any character, except a line break
294071d4279SBram Moolenaar(<NL>, value 10).  There are five ways to enter the character value:
295071d4279SBram Moolenaar
296071d4279SBram Moolenaarfirst char	mode	     max nr of chars   max value ~
297071d4279SBram Moolenaar(none)		decimal		   3		255
298402d2feaSBram Moolenaaro or O		octal		   3		377	 (255)
299071d4279SBram Moolenaarx or X		hexadecimal	   2		ff	 (255)
300071d4279SBram Moolenaaru		hexadecimal	   4		ffff	 (65535)
301071d4279SBram MoolenaarU		hexadecimal	   8		7fffffff (2147483647)
302071d4279SBram Moolenaar
303071d4279SBram MoolenaarNormally you would type the maximum number of characters.  Thus to enter a
304071d4279SBram Moolenaarspace (value 32) you would type <C-V>032.  You can omit the leading zero, in
305071d4279SBram Moolenaarwhich case the character typed after the number must be a non-digit.  This
306071d4279SBram Moolenaarhappens for the other modes as well: As soon as you type a character that is
307071d4279SBram Moolenaarinvalid for the mode, the value before it will be used and the "invalid"
308071d4279SBram Moolenaarcharacter is dealt with in the normal way.
309071d4279SBram Moolenaar
310071d4279SBram MoolenaarIf you enter a value of 10, it will end up in the file as a 0.  The 10 is a
311071d4279SBram Moolenaar<NL>, which is used internally to represent the <Nul> character.  When writing
312071d4279SBram Moolenaarthe buffer to a file, the <NL> character is translated into <Nul>.  The <NL>
313071d4279SBram Moolenaarcharacter is written at the end of each line.  Thus if you want to insert a
314071d4279SBram Moolenaar<NL> character in a file you will have to make a line break.
315cb80aa2dSBram MoolenaarAlso see 'fileformat'.
316071d4279SBram Moolenaar
317071d4279SBram Moolenaar						*i_CTRL-X* *insert_expand*
318071d4279SBram MoolenaarCTRL-X enters a sub-mode where several commands can be used.  Most of these
319e2c453d3SBram Moolenaarcommands do keyword completion; see |ins-completion|.
320071d4279SBram Moolenaar
321071d4279SBram MoolenaarTwo commands can be used to scroll the window up or down, without exiting
322071d4279SBram Moolenaarinsert mode:
323071d4279SBram Moolenaar
324071d4279SBram Moolenaar						*i_CTRL-X_CTRL-E*
325071d4279SBram MoolenaarCTRL-X CTRL-E		scroll window one line up.
326d2cec5b0SBram Moolenaar			When doing completion look here: |complete_CTRL-E|
327071d4279SBram Moolenaar
328071d4279SBram Moolenaar						*i_CTRL-X_CTRL-Y*
329071d4279SBram MoolenaarCTRL-X CTRL-Y		scroll window one line down.
330d2cec5b0SBram Moolenaar			When doing completion look here: |complete_CTRL-Y|
331071d4279SBram Moolenaar
332071d4279SBram MoolenaarAfter CTRL-X is pressed, each CTRL-E (CTRL-Y) scrolls the window up (down) by
333071d4279SBram Moolenaarone line unless that would cause the cursor to move from its current position
334071d4279SBram Moolenaarin the file.  As soon as another key is pressed, CTRL-X mode is exited and
335071d4279SBram Moolenaarthat key is interpreted as in Insert mode.
336071d4279SBram Moolenaar
337071d4279SBram Moolenaar
338071d4279SBram Moolenaar==============================================================================
339071d4279SBram Moolenaar2. Special special keys				*ins-special-special*
340071d4279SBram Moolenaar
341071d4279SBram MoolenaarThe following keys are special.  They stop the current insert, do something,
342071d4279SBram Moolenaarand then restart insertion.  This means you can do something without getting
343071d4279SBram Moolenaarout of Insert mode.  This is very handy if you prefer to use the Insert mode
344071d4279SBram Moolenaarall the time, just like editors that don't have a separate Normal mode.  You
345071d4279SBram Moolenaarmay also want to set the 'backspace' option to "indent,eol,start" and set the
346071d4279SBram Moolenaar'insertmode' option.  You can use CTRL-O if you want to map a function key to
347071d4279SBram Moolenaara command.
348071d4279SBram Moolenaar
349071d4279SBram MoolenaarThe changes (inserted or deleted characters) before and after these keys can
350071d4279SBram Moolenaarbe undone separately.  Only the last change can be redone and always behaves
351071d4279SBram Moolenaarlike an "i" command.
352071d4279SBram Moolenaar
353071d4279SBram Moolenaarchar		action	~
354071d4279SBram Moolenaar-----------------------------------------------------------------------
355071d4279SBram Moolenaar<Up>		cursor one line up			     *i_<Up>*
356071d4279SBram Moolenaar<Down>		cursor one line down			     *i_<Down>*
357071d4279SBram MoolenaarCTRL-G <Up>	cursor one line up, insert start column	     *i_CTRL-G_<Up>*
358071d4279SBram MoolenaarCTRL-G k	cursor one line up, insert start column	     *i_CTRL-G_k*
359071d4279SBram MoolenaarCTRL-G CTRL-K	cursor one line up, insert start column	     *i_CTRL-G_CTRL-K*
360071d4279SBram MoolenaarCTRL-G <Down>	cursor one line down, insert start column    *i_CTRL-G_<Down>*
361071d4279SBram MoolenaarCTRL-G j	cursor one line down, insert start column    *i_CTRL-G_j*
362071d4279SBram MoolenaarCTRL-G CTRL-J	cursor one line down, insert start column    *i_CTRL-G_CTRL-J*
363071d4279SBram Moolenaar<Left>		cursor one character left		     *i_<Left>*
364071d4279SBram Moolenaar<Right>		cursor one character right		     *i_<Right>*
365071d4279SBram Moolenaar<S-Left>	cursor one word back (like "b" command)	     *i_<S-Left>*
366071d4279SBram Moolenaar<C-Left>	cursor one word back (like "b" command)	     *i_<C-Left>*
367071d4279SBram Moolenaar<S-Right>	cursor one word forward (like "w" command)   *i_<S-Right>*
368071d4279SBram Moolenaar<C-Right>	cursor one word forward (like "w" command)   *i_<C-Right>*
369071d4279SBram Moolenaar<Home>		cursor to first char in the line	     *i_<Home>*
370071d4279SBram Moolenaar<End>		cursor to after last char in the line	     *i_<End>*
371071d4279SBram Moolenaar<C-Home>	cursor to first char in the file	     *i_<C-Home>*
372071d4279SBram Moolenaar<C-End>		cursor to after last char in the file	     *i_<C-End>*
373071d4279SBram Moolenaar<LeftMouse>	cursor to position of mouse click	     *i_<LeftMouse>*
374071d4279SBram Moolenaar<S-Up>		move window one page up			     *i_<S-Up>*
375071d4279SBram Moolenaar<PageUp>	move window one page up			     *i_<PageUp>*
376071d4279SBram Moolenaar<S-Down>	move window one page down		     *i_<S-Down>*
377071d4279SBram Moolenaar<PageDown>	move window one page down		     *i_<PageDown>*
3788d9b40e7SBram Moolenaar<ScrollWheelDown>    move window three lines down	*i_<ScrollWheelDown>*
3798d9b40e7SBram Moolenaar<S-ScrollWheelDown>  move window one page down		*i_<S-ScrollWheelDown>*
3808d9b40e7SBram Moolenaar<ScrollWheelUp>      move window three lines up		*i_<ScrollWheelUp>*
3818d9b40e7SBram Moolenaar<S-ScrollWheelUp>    move window one page up		*i_<S-ScrollWheelUp>*
3828d9b40e7SBram Moolenaar<ScrollWheelLeft>    move window six columns left	*i_<ScrollWheelLeft>*
3838d9b40e7SBram Moolenaar<S-ScrollWheelLeft>  move window one page left		*i_<S-ScrollWheelLeft>*
3848d9b40e7SBram Moolenaar<ScrollWheelRight>   move window six columns right	*i_<ScrollWheelRight>*
3858d9b40e7SBram Moolenaar<S-ScrollWheelRight> move window one page right		*i_<S-ScrollWheelRight>*
386071d4279SBram MoolenaarCTRL-O		execute one command, return to Insert mode   *i_CTRL-O*
387488c6512SBram MoolenaarCTRL-\ CTRL-O	like CTRL-O but don't move the cursor	     *i_CTRL-\_CTRL-O*
388488c6512SBram MoolenaarCTRL-L		when 'insertmode' is set: go to Normal mode  *i_CTRL-L*
389071d4279SBram MoolenaarCTRL-G u	break undo sequence, start new change	     *i_CTRL-G_u*
3908b5f65a5SBram MoolenaarCTRL-G U	don't break undo with next left/right cursor *i_CTRL-G_U*
391191acfdeSBram Moolenaar		movement, if the cursor stays within the
392191acfdeSBram Moolenaar		same line
393071d4279SBram Moolenaar-----------------------------------------------------------------------
394071d4279SBram Moolenaar
395071d4279SBram MoolenaarNote: If the cursor keys take you out of Insert mode, check the 'noesckeys'
396071d4279SBram Moolenaaroption.
397071d4279SBram Moolenaar
398071d4279SBram MoolenaarThe CTRL-O command sometimes has a side effect: If the cursor was beyond the
399071d4279SBram Moolenaarend of the line, it will be put on the last character in the line.  In
400071d4279SBram Moolenaarmappings it's often better to use <Esc> (first put an "x" in the text, <Esc>
401488c6512SBram Moolenaarwill then always put the cursor on it).  Or use CTRL-\ CTRL-O, but then
402a3e6bc93SBram Moolenaarbeware of the cursor possibly being beyond the end of the line.  Note that the
403a3e6bc93SBram Moolenaarcommand following CTRL-\ CTRL-O can still move the cursor, it is not restored
404a3e6bc93SBram Moolenaarto its original position.
405071d4279SBram Moolenaar
4060536570fSBram MoolenaarThe CTRL-O command takes you to Normal mode.  If you then use a command enter
407d38b055aSBram MoolenaarInsert mode again it normally doesn't nest.  Thus when typing "a<C-O>a" and
408d38b055aSBram Moolenaarthen <Esc> takes you back to Normal mode, you do not need to type <Esc> twice.
409d38b055aSBram MoolenaarAn exception is when not typing the command, e.g. when executing a mapping or
410d38b055aSBram Moolenaarsourcing a script.  This makes mappings work that briefly switch to Insert
411d38b055aSBram Moolenaarmode.
4120536570fSBram Moolenaar
413071d4279SBram MoolenaarThe shifted cursor keys are not available on all terminals.
414071d4279SBram Moolenaar
415071d4279SBram MoolenaarAnother side effect is that a count specified before the "i" or "a" command is
416071d4279SBram Moolenaarignored.  That is because repeating the effect of the command after CTRL-O is
417071d4279SBram Moolenaartoo complicated.
418071d4279SBram Moolenaar
419071d4279SBram MoolenaarAn example for using CTRL-G u: >
420071d4279SBram Moolenaar
421071d4279SBram Moolenaar	:inoremap <C-H> <C-G>u<C-H>
422071d4279SBram Moolenaar
423071d4279SBram MoolenaarThis redefines the backspace key to start a new undo sequence.  You can now
424071d4279SBram Moolenaarundo the effect of the backspace key, without changing what you typed before
4255b435d67SBram Moolenaarthat, with CTRL-O u.  Another example: >
4265b435d67SBram Moolenaar
4275b435d67SBram Moolenaar	:inoremap <CR> <C-]><C-G>u<CR>
4285b435d67SBram Moolenaar
4295b435d67SBram MoolenaarThis breaks undo at each line break.  It also expands abbreviations before
4305b435d67SBram Moolenaarthis.
431071d4279SBram Moolenaar
4328b5f65a5SBram MoolenaarAn example for using CTRL-G U: >
4338b5f65a5SBram Moolenaar
4348b5f65a5SBram Moolenaar	inoremap <Left>  <C-G>U<Left>
4358b5f65a5SBram Moolenaar	inoremap <Right> <C-G>U<Right>
4368b5f65a5SBram Moolenaar	inoremap <expr> <Home> col('.') == match(getline('.'), '\S') + 1 ?
4378b5f65a5SBram Moolenaar	 \ repeat('<C-G>U<Left>', col('.') - 1) :
4388b5f65a5SBram Moolenaar	 \ (col('.') < match(getline('.'), '\S') ?
4398b5f65a5SBram Moolenaar	 \     repeat('<C-G>U<Right>', match(getline('.'), '\S') + 0) :
4408b5f65a5SBram Moolenaar	 \     repeat('<C-G>U<Left>', col('.') - 1 - match(getline('.'), '\S')))
4418b5f65a5SBram Moolenaar	inoremap <expr> <End> repeat('<C-G>U<Right>', col('$') - col('.'))
4428b5f65a5SBram Moolenaar	inoremap ( ()<C-G>U<Left>
4438b5f65a5SBram Moolenaar
4448b5f65a5SBram MoolenaarThis makes it possible to use the cursor keys in Insert mode, without breaking
4458b5f65a5SBram Moolenaarthe undo sequence and therefore using |.| (redo) will work as expected.
446d2f3a8b8SBram MoolenaarAlso entering a text like (with the "(" mapping from above):
4478b5f65a5SBram Moolenaar
4488b5f65a5SBram Moolenaar   Lorem ipsum (dolor
4498b5f65a5SBram Moolenaar
450d2f3a8b8SBram Moolenaarwill be repeatable by using |.| to the expected
4518b5f65a5SBram Moolenaar
4528b5f65a5SBram Moolenaar   Lorem ipsum (dolor)
4538b5f65a5SBram Moolenaar
454f4b8e57fSBram MoolenaarUsing CTRL-O splits undo: the text typed before and after it is undone
455f4b8e57fSBram Moolenaarseparately.  If you want to avoid this (e.g., in a mapping) you might be able
456f4b8e57fSBram Moolenaarto use CTRL-R = |i_CTRL-R|.  E.g., to call a function: >
457f4b8e57fSBram Moolenaar	:imap <F2> <C-R>=MyFunc()<CR>
458f4b8e57fSBram Moolenaar
459071d4279SBram MoolenaarWhen the 'whichwrap' option is set appropriately, the <Left> and <Right>
460071d4279SBram Moolenaarkeys on the first/last character in the line make the cursor wrap to the
461071d4279SBram Moolenaarprevious/next line.
462071d4279SBram Moolenaar
463071d4279SBram MoolenaarThe CTRL-G j and CTRL-G k commands can be used to insert text in front of a
464071d4279SBram Moolenaarcolumn.  Example: >
465071d4279SBram Moolenaar   int i;
466071d4279SBram Moolenaar   int j;
467071d4279SBram MoolenaarPosition the cursor on the first "int", type "istatic <C-G>j       ".  The
468071d4279SBram Moolenaarresult is: >
469071d4279SBram Moolenaar   static int i;
470071d4279SBram Moolenaar	  int j;
471071d4279SBram MoolenaarWhen inserting the same text in front of the column in every line, use the
472071d4279SBram MoolenaarVisual blockwise command "I" |v_b_I|.
473071d4279SBram Moolenaar
474071d4279SBram Moolenaar==============================================================================
475071d4279SBram Moolenaar3. 'textwidth' and 'wrapmargin' options			*ins-textwidth*
476071d4279SBram Moolenaar
477071d4279SBram MoolenaarThe 'textwidth' option can be used to automatically break a line before it
478071d4279SBram Moolenaargets too long.  Set the 'textwidth' option to the desired maximum line
479071d4279SBram Moolenaarlength.  If you then type more characters (not spaces or tabs), the
480071d4279SBram Moolenaarlast word will be put on a new line (unless it is the only word on the
481071d4279SBram Moolenaarline).  If you set 'textwidth' to 0, this feature is disabled.
482071d4279SBram Moolenaar
483071d4279SBram MoolenaarThe 'wrapmargin' option does almost the same.  The difference is that
484071d4279SBram Moolenaar'textwidth' has a fixed width while 'wrapmargin' depends on the width of the
485071d4279SBram Moolenaarscreen.  When using 'wrapmargin' this is equal to using 'textwidth' with a
486071d4279SBram Moolenaarvalue equal to (columns - 'wrapmargin'), where columns is the width of the
487071d4279SBram Moolenaarscreen.
488071d4279SBram Moolenaar
489071d4279SBram MoolenaarWhen 'textwidth' and 'wrapmargin' are both set, 'textwidth' is used.
490071d4279SBram Moolenaar
491071d4279SBram MoolenaarIf you don't really want to break the line, but view the line wrapped at a
492071d4279SBram Moolenaarconvenient place, see the 'linebreak' option.
493071d4279SBram Moolenaar
4941d2ba7faSBram MoolenaarThe line is only broken automatically when using Insert mode, or when
495071d4279SBram Moolenaarappending to a line.  When in replace mode and the line length is not
496071d4279SBram Moolenaarchanged, the line will not be broken.
497071d4279SBram Moolenaar
498071d4279SBram MoolenaarLong lines are broken if you enter a non-white character after the margin.
499071d4279SBram MoolenaarThe situations where a line will be broken can be restricted by adding
500071d4279SBram Moolenaarcharacters to the 'formatoptions' option:
501071d4279SBram Moolenaar"l"  Only break a line if it was not longer than 'textwidth' when the insert
502071d4279SBram Moolenaar     started.
503071d4279SBram Moolenaar"v"  Only break at a white character that has been entered during the
504071d4279SBram Moolenaar     current insert command.  This is mostly Vi-compatible.
505071d4279SBram Moolenaar"lv" Only break if the line was not longer than 'textwidth' when the insert
506071d4279SBram Moolenaar     started and only at a white character that has been entered during the
507071d4279SBram Moolenaar     current insert command.  Only differs from "l" when entering non-white
508071d4279SBram Moolenaar     characters while crossing the 'textwidth' boundary.
509071d4279SBram Moolenaar
5101d2ba7faSBram MoolenaarNormally an internal function will be used to decide where to break the line.
5111d2ba7faSBram MoolenaarIf you want to do it in a different way set the 'formatexpr' option to an
5121d2ba7faSBram Moolenaarexpression that will take care of the line break.
5131d2ba7faSBram Moolenaar
514071d4279SBram MoolenaarIf you want to format a block of text, you can use the "gq" operator.  Type
515071d4279SBram Moolenaar"gq" and a movement command to move the cursor to the end of the block.  In
516071d4279SBram Moolenaarmany cases, the command "gq}" will do what you want (format until the end of
517071d4279SBram Moolenaarparagraph).  Alternatively, you can use "gqap", which will format the whole
518071d4279SBram Moolenaarparagraph, no matter where the cursor currently is.  Or you can use Visual
519071d4279SBram Moolenaarmode: hit "v", move to the end of the block, and type "gq".  See also |gq|.
520071d4279SBram Moolenaar
521071d4279SBram Moolenaar==============================================================================
522071d4279SBram Moolenaar4. 'expandtab', 'smarttab' and 'softtabstop' options	*ins-expandtab*
523071d4279SBram Moolenaar
524071d4279SBram MoolenaarIf the 'expandtab' option is on, spaces will be used to fill the amount of
525071d4279SBram Moolenaarwhitespace of the tab.  If you want to enter a real <Tab>, type CTRL-V first
526071d4279SBram Moolenaar(use CTRL-Q when CTRL-V is mapped |i_CTRL-Q|).
527071d4279SBram MoolenaarThe 'expandtab' option is off by default.  Note that in Replace mode, a single
528071d4279SBram Moolenaarcharacter is replaced with several spaces.  The result of this is that the
529071d4279SBram Moolenaarnumber of characters in the line increases.  Backspacing will delete one
530071d4279SBram Moolenaarspace at a time.  The original character will be put back for only one space
53125c9c680SBram Moolenaarthat you backspace over (the last one).
532071d4279SBram Moolenaar
533071d4279SBram Moolenaar							*ins-smarttab*
534071d4279SBram MoolenaarWhen the 'smarttab' option is on, a <Tab> inserts 'shiftwidth' positions at
535071d4279SBram Moolenaarthe beginning of a line and 'tabstop' positions in other places.  This means
53630b65817SBram Moolenaarthat often spaces instead of a <Tab> character are inserted.  When 'smarttab'
537071d4279SBram Moolenaaris off, a <Tab> always inserts 'tabstop' positions, and 'shiftwidth' is only
53825c9c680SBram Moolenaarused for ">>" and the like.
539071d4279SBram Moolenaar
540071d4279SBram Moolenaar							*ins-softtabstop*
541071d4279SBram MoolenaarWhen the 'softtabstop' option is non-zero, a <Tab> inserts 'softtabstop'
542071d4279SBram Moolenaarpositions, and a <BS> used to delete white space, will delete 'softtabstop'
543071d4279SBram Moolenaarpositions.  This feels like 'tabstop' was set to 'softtabstop', but a real
544071d4279SBram Moolenaar<Tab> character still takes 'tabstop' positions, so your file will still look
545071d4279SBram Moolenaarcorrect when used by other applications.
546071d4279SBram Moolenaar
547071d4279SBram MoolenaarIf 'softtabstop' is non-zero, a <BS> will try to delete as much white space to
548071d4279SBram Moolenaarmove to the previous 'softtabstop' position, except when the previously
549071d4279SBram Moolenaarinserted character is a space, then it will only delete the character before
550071d4279SBram Moolenaarthe cursor.  Otherwise you cannot always delete a single character before the
551071d4279SBram Moolenaarcursor.  You will have to delete 'softtabstop' characters first, and then type
552071d4279SBram Moolenaarextra spaces to get where you want to be.
553071d4279SBram Moolenaar
554071d4279SBram Moolenaar==============================================================================
555071d4279SBram Moolenaar5. Replace mode				*Replace* *Replace-mode* *mode-replace*
556071d4279SBram Moolenaar
557071d4279SBram MoolenaarEnter Replace mode with the "R" command in normal mode.
558071d4279SBram Moolenaar
559071d4279SBram MoolenaarIn Replace mode, one character in the line is deleted for every character you
560071d4279SBram Moolenaartype.  If there is no character to delete (at the end of the line), the
561071d4279SBram Moolenaartyped character is appended (as in Insert mode).  Thus the number of
562071d4279SBram Moolenaarcharacters in a line stays the same until you get to the end of the line.
563071d4279SBram MoolenaarIf a <NL> is typed, a line break is inserted and no character is deleted.
564071d4279SBram Moolenaar
565071d4279SBram MoolenaarBe careful with <Tab> characters.  If you type a normal printing character in
566071d4279SBram Moolenaarits place, the number of characters is still the same, but the number of
567071d4279SBram Moolenaarcolumns will become smaller.
568071d4279SBram Moolenaar
569071d4279SBram MoolenaarIf you delete characters in Replace mode (with <BS>, CTRL-W, or CTRL-U), what
570071d4279SBram Moolenaarhappens is that you delete the changes.  The characters that were replaced
571071d4279SBram Moolenaarare restored.  If you had typed past the existing text, the characters you
572071d4279SBram Moolenaaradded are deleted.  This is effectively a character-at-a-time undo.
573071d4279SBram Moolenaar
574071d4279SBram MoolenaarIf the 'expandtab' option is on, a <Tab> will replace one character with
575071d4279SBram Moolenaarseveral spaces.  The result of this is that the number of characters in the
576071d4279SBram Moolenaarline increases.  Backspacing will delete one space at a time.  The original
577071d4279SBram Moolenaarcharacter will be put back for only one space that you backspace over (the
57825c9c680SBram Moolenaarlast one).
579071d4279SBram Moolenaar
580071d4279SBram Moolenaar==============================================================================
581071d4279SBram Moolenaar6. Virtual Replace mode		*vreplace-mode* *Virtual-Replace-mode*
582071d4279SBram Moolenaar
583071d4279SBram MoolenaarEnter Virtual Replace mode with the "gR" command in normal mode.
584db84e459SBram Moolenaar{not available when compiled without the |+vreplace| feature}
585071d4279SBram Moolenaar
586071d4279SBram MoolenaarVirtual Replace mode is similar to Replace mode, but instead of replacing
587071d4279SBram Moolenaaractual characters in the file, you are replacing screen real estate, so that
588071d4279SBram Moolenaarcharacters further on in the file never appear to move.
589071d4279SBram Moolenaar
590071d4279SBram MoolenaarSo if you type a <Tab> it may replace several normal characters, and if you
591071d4279SBram Moolenaartype a letter on top of a <Tab> it may not replace anything at all, since the
592071d4279SBram Moolenaar<Tab> will still line up to the same place as before.
593071d4279SBram Moolenaar
594071d4279SBram MoolenaarTyping a <NL> still doesn't cause characters later in the file to appear to
595071d4279SBram Moolenaarmove.  The rest of the current line will be replaced by the <NL> (that is,
596071d4279SBram Moolenaarthey are deleted), and replacing continues on the next line.  A new line is
597071d4279SBram MoolenaarNOT inserted unless you go past the end of the file.
598071d4279SBram Moolenaar
599071d4279SBram MoolenaarInteresting effects are seen when using CTRL-T and CTRL-D.  The characters
600071d4279SBram Moolenaarbefore the cursor are shifted sideways as normal, but characters later in the
601071d4279SBram Moolenaarline still remain still.  CTRL-T will hide some of the old line under the
602071d4279SBram Moolenaarshifted characters, but CTRL-D will reveal them again.
603071d4279SBram Moolenaar
604071d4279SBram MoolenaarAs with Replace mode, using <BS> etc will bring back the characters that were
605071d4279SBram Moolenaarreplaced.  This still works in conjunction with 'smartindent', CTRL-T and
606071d4279SBram MoolenaarCTRL-D, 'expandtab', 'smarttab', 'softtabstop', etc.
607071d4279SBram Moolenaar
608071d4279SBram MoolenaarIn 'list' mode, Virtual Replace mode acts as if it was not in 'list' mode,
609071d4279SBram Moolenaarunless "L" is in 'cpoptions'.
610071d4279SBram Moolenaar
61124ea3babSBram MoolenaarNote that the only situations for which characters beyond the cursor should
61224ea3babSBram Moolenaarappear to move are in List mode |'list'|, and occasionally when 'wrap' is set
61324ea3babSBram Moolenaar(and the line changes length to become shorter or wider than the width of the
61424ea3babSBram Moolenaarscreen).  In other cases spaces may be inserted to avoid following characters
61524ea3babSBram Moolenaarto move.
616071d4279SBram Moolenaar
617071d4279SBram MoolenaarThis mode is very useful for editing <Tab> separated columns in tables, for
618071d4279SBram Moolenaarentering new data while keeping all the columns aligned.
619071d4279SBram Moolenaar
620071d4279SBram Moolenaar==============================================================================
621071d4279SBram Moolenaar7. Insert mode completion				*ins-completion*
622071d4279SBram Moolenaar
6234be06f9eSBram MoolenaarIn Insert and Replace mode, there are several commands to complete part of a
624071d4279SBram Moolenaarkeyword or line that has been typed.  This is useful if you are using
625071d4279SBram Moolenaarcomplicated keywords (e.g., function names with capitals and underscores).
626071d4279SBram Moolenaar
627071d4279SBram MoolenaarCompletion can be done for:
628071d4279SBram Moolenaar
629071d4279SBram Moolenaar1. Whole lines						|i_CTRL-X_CTRL-L|
630071d4279SBram Moolenaar2. keywords in the current file				|i_CTRL-X_CTRL-N|
631071d4279SBram Moolenaar3. keywords in 'dictionary'				|i_CTRL-X_CTRL-K|
632071d4279SBram Moolenaar4. keywords in 'thesaurus', thesaurus-style		|i_CTRL-X_CTRL-T|
633071d4279SBram Moolenaar5. keywords in the current and included files		|i_CTRL-X_CTRL-I|
634071d4279SBram Moolenaar6. tags							|i_CTRL-X_CTRL-]|
635071d4279SBram Moolenaar7. file names						|i_CTRL-X_CTRL-F|
636071d4279SBram Moolenaar8. definitions or macros				|i_CTRL-X_CTRL-D|
637071d4279SBram Moolenaar9. Vim command-line					|i_CTRL-X_CTRL-V|
6384be06f9eSBram Moolenaar10. User defined completion				|i_CTRL-X_CTRL-U|
639f75a963eSBram Moolenaar11. omni completion					|i_CTRL-X_CTRL-O|
640488c6512SBram Moolenaar12. Spelling suggestions				|i_CTRL-X_s|
6416aa8cea4SBram Moolenaar13. keywords in 'complete'				|i_CTRL-N| |i_CTRL-P|
642071d4279SBram Moolenaar
643dca29d9cSzeertzjqAdditionally, |i_CTRL-X_CTRL-Z| stops completion without changing the text.
644dca29d9cSzeertzjq
6456aa8cea4SBram MoolenaarAll these, except CTRL-N and CTRL-P, are done in CTRL-X mode.  This is a
6466aa8cea4SBram Moolenaarsub-mode of Insert and Replace modes.  You enter CTRL-X mode by typing CTRL-X
6476aa8cea4SBram Moolenaarand one of the CTRL-X commands.  You exit CTRL-X mode by typing a key that is
6486aa8cea4SBram Moolenaarnot a valid CTRL-X mode command.  Valid keys are the CTRL-X command itself,
6496aa8cea4SBram MoolenaarCTRL-N (next), and CTRL-P (previous).
650071d4279SBram Moolenaar
651fd133323SBram MoolenaarTo get the current completion information, |complete_info()| can be used.
652071d4279SBram MoolenaarAlso see the 'infercase' option if you want to adjust the case of the match.
653071d4279SBram Moolenaar
654d2cec5b0SBram Moolenaar							*complete_CTRL-E*
655d2cec5b0SBram MoolenaarWhen completion is active you can use CTRL-E to stop it and go back to the
656551dbcc9SBram Moolenaaroriginally typed text.  The CTRL-E will not be inserted.
657d2cec5b0SBram Moolenaar
658d2cec5b0SBram Moolenaar							*complete_CTRL-Y*
659d2cec5b0SBram MoolenaarWhen the popup menu is displayed you can use CTRL-Y to stop completion and
660d2cec5b0SBram Moolenaaraccept the currently selected entry.  The CTRL-Y is not inserted.  Typing a
661d2cec5b0SBram Moolenaarspace, Enter, or some other unprintable character will leave completion mode
662d2cec5b0SBram Moolenaarand insert that typed character.
663d2cec5b0SBram Moolenaar
6649e54a0e7SBram MoolenaarWhen the popup menu is displayed there are a few more special keys, see
6659e54a0e7SBram Moolenaar|popupmenu-keys|.
6669e54a0e7SBram Moolenaar
667071d4279SBram MoolenaarNote: The keys that are valid in CTRL-X mode are not mapped.  This allows for
668071d4279SBram Moolenaar":map ^F ^X^F" to work (where ^F is CTRL-F and ^X is CTRL-X).  The key that
669071d4279SBram Moolenaarends CTRL-X mode (any key that is not a valid CTRL-X mode command) is mapped.
670071d4279SBram MoolenaarAlso, when doing completion with 'complete' mappings apply as usual.
671071d4279SBram Moolenaar
6727ceefb35SBram Moolenaar							*E578* *E565*
673ff06f283SBram MoolenaarNote: While completion is active Insert mode can't be used recursively and
674ff06f283SBram Moolenaarbuffer text cannot be changed.  Mappings that somehow invoke ":normal i.."
675ff06f283SBram Moolenaarwill generate an E565 error.
676f193fffdSBram Moolenaar
677071d4279SBram MoolenaarThe following mappings are suggested to make typing the completion commands
678071d4279SBram Moolenaara bit easier (although they will hide other commands): >
679071d4279SBram Moolenaar    :inoremap ^] ^X^]
680071d4279SBram Moolenaar    :inoremap ^F ^X^F
681071d4279SBram Moolenaar    :inoremap ^D ^X^D
682071d4279SBram Moolenaar    :inoremap ^L ^X^L
683071d4279SBram Moolenaar
684071d4279SBram MoolenaarAs a special case, typing CTRL-R to perform register insertion (see
685071d4279SBram Moolenaar|i_CTRL-R|) will not exit CTRL-X mode.  This is primarily to allow the use of
686071d4279SBram Moolenaarthe '=' register to call some function to determine the next operation.  If
687071d4279SBram Moolenaarthe contents of the register (or result of the '=' register evaluation) are
688071d4279SBram Moolenaarnot valid CTRL-X mode keys, then CTRL-X mode will be exited as if those keys
689071d4279SBram Moolenaarhad been typed.
690071d4279SBram Moolenaar
691071d4279SBram MoolenaarFor example, the following will map <Tab> to either actually insert a <Tab> if
692071d4279SBram Moolenaarthe current line is currently only whitespace, or start/continue a CTRL-N
693071d4279SBram Moolenaarcompletion operation: >
694071d4279SBram Moolenaar
695071d4279SBram Moolenaar	function! CleverTab()
696071d4279SBram Moolenaar	   if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
697071d4279SBram Moolenaar	      return "\<Tab>"
698071d4279SBram Moolenaar	   else
699071d4279SBram Moolenaar	      return "\<C-N>"
700b52073acSBram Moolenaar	   endif
701071d4279SBram Moolenaar	endfunction
702071d4279SBram Moolenaar	inoremap <Tab> <C-R>=CleverTab()<CR>
703071d4279SBram Moolenaar
704071d4279SBram Moolenaar
705071d4279SBram Moolenaar
706071d4279SBram MoolenaarCompleting whole lines					*compl-whole-line*
707071d4279SBram Moolenaar
708071d4279SBram Moolenaar							*i_CTRL-X_CTRL-L*
709071d4279SBram MoolenaarCTRL-X CTRL-L		Search backwards for a line that starts with the
71083bab71bSBram Moolenaar			same characters as those in the current line before
71183bab71bSBram Moolenaar			the cursor.  Indent is ignored.  The matching line is
712071d4279SBram Moolenaar			inserted in front of the cursor.
71383bab71bSBram Moolenaar			The 'complete' option is used to decide which buffers
7141d2ba7faSBram Moolenaar			are searched for a match.  Both loaded and unloaded
7151d2ba7faSBram Moolenaar			buffers are used.
716071d4279SBram Moolenaar	CTRL-L	or
717071d4279SBram Moolenaar	CTRL-P		Search backwards for next matching line.  This line
718071d4279SBram Moolenaar			replaces the previous matching line.
719071d4279SBram Moolenaar
720071d4279SBram Moolenaar	CTRL-N		Search forward for next matching line.  This line
721071d4279SBram Moolenaar			replaces the previous matching line.
722071d4279SBram Moolenaar
723071d4279SBram Moolenaar	CTRL-X CTRL-L	After expanding a line you can additionally get the
724071d4279SBram Moolenaar			line next to it by typing CTRL-X CTRL-L again, unless
7258f3f58f2SBram Moolenaar			a double CTRL-X is used.  Only works for loaded
7268f3f58f2SBram Moolenaar			buffers.
727071d4279SBram Moolenaar
728071d4279SBram MoolenaarCompleting keywords in current file			*compl-current*
729071d4279SBram Moolenaar
730071d4279SBram Moolenaar							*i_CTRL-X_CTRL-P*
731071d4279SBram Moolenaar							*i_CTRL-X_CTRL-N*
732071d4279SBram MoolenaarCTRL-X CTRL-N		Search forwards for words that start with the keyword
733071d4279SBram Moolenaar			in front of the cursor.  The found keyword is inserted
734071d4279SBram Moolenaar			in front of the cursor.
735071d4279SBram Moolenaar
736071d4279SBram MoolenaarCTRL-X CTRL-P		Search backwards for words that start with the keyword
737071d4279SBram Moolenaar			in front of the cursor.  The found keyword is inserted
738071d4279SBram Moolenaar			in front of the cursor.
739071d4279SBram Moolenaar
740071d4279SBram Moolenaar	CTRL-N		Search forward for next matching keyword.  This
741071d4279SBram Moolenaar			keyword replaces the previous matching keyword.
742071d4279SBram Moolenaar
743071d4279SBram Moolenaar	CTRL-P		Search backwards for next matching keyword.  This
744071d4279SBram Moolenaar			keyword replaces the previous matching keyword.
745071d4279SBram Moolenaar
746071d4279SBram Moolenaar	CTRL-X CTRL-N or
747071d4279SBram Moolenaar	CTRL-X CTRL-P	Further use of CTRL-X CTRL-N or CTRL-X CTRL-P will
748071d4279SBram Moolenaar			copy the words following the previous expansion in
749071d4279SBram Moolenaar			other contexts unless a double CTRL-X is used.
750071d4279SBram Moolenaar
751071d4279SBram MoolenaarIf there is a keyword in front of the cursor (a name made out of alphabetic
752071d4279SBram Moolenaarcharacters and characters in 'iskeyword'), it is used as the search pattern,
753071d4279SBram Moolenaarwith "\<" prepended (meaning: start of a word).  Otherwise "\<\k\k" is used
754071d4279SBram Moolenaaras search pattern (start of any keyword of at least two characters).
755071d4279SBram Moolenaar
756071d4279SBram MoolenaarIn Replace mode, the number of characters that are replaced depends on the
757071d4279SBram Moolenaarlength of the matched string.  This works like typing the characters of the
758071d4279SBram Moolenaarmatched string in Replace mode.
759071d4279SBram Moolenaar
760071d4279SBram MoolenaarIf there is not a valid keyword character before the cursor, any keyword of
761071d4279SBram Moolenaarat least two characters is matched.
762071d4279SBram Moolenaar	e.g., to get:
763071d4279SBram Moolenaar	    printf("(%g, %g, %g)", vector[0], vector[1], vector[2]);
764071d4279SBram Moolenaar	just type:
765071d4279SBram Moolenaar	    printf("(%g, %g, %g)", vector[0], ^P[1], ^P[2]);
766071d4279SBram Moolenaar
767f75a963eSBram MoolenaarThe search wraps around the end of the file, the value of 'wrapscan' is not
768f75a963eSBram Moolenaarused here.
769f75a963eSBram Moolenaar
770071d4279SBram MoolenaarMultiple repeats of the same completion are skipped; thus a different match
771071d4279SBram Moolenaarwill be inserted at each CTRL-N and CTRL-P (unless there is only one
772071d4279SBram Moolenaarmatching keyword).
773071d4279SBram Moolenaar
774071d4279SBram MoolenaarSingle character matches are never included, as they usually just get in
775071d4279SBram Moolenaarthe way of what you were really after.
776071d4279SBram Moolenaar	e.g., to get:
777071d4279SBram Moolenaar		printf("name = %s\n", name);
778071d4279SBram Moolenaar	just type:
779071d4279SBram Moolenaar		printf("name = %s\n", n^P);
780071d4279SBram Moolenaar	or even:
781071d4279SBram Moolenaar		printf("name = %s\n", ^P);
782071d4279SBram MoolenaarThe 'n' in '\n' is skipped.
783071d4279SBram Moolenaar
784071d4279SBram MoolenaarAfter expanding a word, you can use CTRL-X CTRL-P or CTRL-X CTRL-N to get the
785071d4279SBram Moolenaarword following the expansion in other contexts.  These sequences search for
786071d4279SBram Moolenaarthe text just expanded and further expand by getting an extra word.  This is
787071d4279SBram Moolenaaruseful if you need to repeat a sequence of complicated words.  Although CTRL-P
788071d4279SBram Moolenaarand CTRL-N look just for strings of at least two characters, CTRL-X CTRL-P and
789071d4279SBram MoolenaarCTRL-X CTRL-N can be used to expand words of just one character.
790071d4279SBram Moolenaar	e.g., to get:
791071d4279SBram Moolenaar		M&eacute;xico
792071d4279SBram Moolenaar	you can type:
793071d4279SBram Moolenaar		M^N^P^X^P^X^P
794071d4279SBram MoolenaarCTRL-N starts the expansion and then CTRL-P takes back the single character
795071d4279SBram Moolenaar"M", the next two CTRL-X CTRL-P's get the words "&eacute" and ";xico".
796071d4279SBram Moolenaar
797071d4279SBram MoolenaarIf the previous expansion was split, because it got longer than 'textwidth',
798071d4279SBram Moolenaarthen just the text in the current line will be used.
799071d4279SBram Moolenaar
800071d4279SBram MoolenaarIf the match found is at the end of a line, then the first word in the next
801071d4279SBram Moolenaarline will be inserted and the message "word from next line" displayed, if
802071d4279SBram Moolenaarthis word is accepted the next CTRL-X CTRL-P or CTRL-X CTRL-N will search
803071d4279SBram Moolenaarfor those lines starting with this word.
804071d4279SBram Moolenaar
805071d4279SBram Moolenaar
806071d4279SBram MoolenaarCompleting keywords in 'dictionary'			*compl-dictionary*
807071d4279SBram Moolenaar
808071d4279SBram Moolenaar							*i_CTRL-X_CTRL-K*
809071d4279SBram MoolenaarCTRL-X CTRL-K		Search the files given with the 'dictionary' option
810071d4279SBram Moolenaar			for words that start with the keyword in front of the
811071d4279SBram Moolenaar			cursor.  This is like CTRL-N, but only the dictionary
812071d4279SBram Moolenaar			files are searched, not the current file.  The found
813071d4279SBram Moolenaar			keyword is inserted in front of the cursor.  This
814071d4279SBram Moolenaar			could potentially be pretty slow, since all matches
815071d4279SBram Moolenaar			are found before the first match is used.  By default,
816071d4279SBram Moolenaar			the 'dictionary' option is empty.
817071d4279SBram Moolenaar			For suggestions where to find a list of words, see the
818071d4279SBram Moolenaar			'dictionary' option.
819071d4279SBram Moolenaar
820071d4279SBram Moolenaar	CTRL-K	or
821071d4279SBram Moolenaar	CTRL-N		Search forward for next matching keyword.  This
822071d4279SBram Moolenaar			keyword replaces the previous matching keyword.
823071d4279SBram Moolenaar
824071d4279SBram Moolenaar	CTRL-P		Search backwards for next matching keyword.  This
825071d4279SBram Moolenaar			keyword replaces the previous matching keyword.
826071d4279SBram Moolenaar
827f4d8b76dSBram Moolenaar
828f4d8b76dSBram MoolenaarCompleting words in 'thesaurus'				*compl-thesaurus*
829f4d8b76dSBram Moolenaar
830071d4279SBram Moolenaar							*i_CTRL-X_CTRL-T*
831071d4279SBram MoolenaarCTRL-X CTRL-T		Works as CTRL-X CTRL-K, but in a special way.  It uses
832071d4279SBram Moolenaar			the 'thesaurus' option instead of 'dictionary'.  If a
833071d4279SBram Moolenaar			match is found in the thesaurus file, all the
834071d4279SBram Moolenaar			remaining words on the same line are included as
835071d4279SBram Moolenaar			matches, even though they don't complete the word.
836071d4279SBram Moolenaar			Thus a word can be completely replaced.
837071d4279SBram Moolenaar
838071d4279SBram Moolenaar	CTRL-T	or
839071d4279SBram Moolenaar	CTRL-N		Search forward for next matching keyword.  This
840071d4279SBram Moolenaar			keyword replaces the previous matching keyword.
841071d4279SBram Moolenaar
842071d4279SBram Moolenaar	CTRL-P		Search backwards for next matching keyword.  This
843071d4279SBram Moolenaar			keyword replaces the previous matching keyword.
844071d4279SBram Moolenaar
845f4d8b76dSBram MoolenaarIn the file used by the 'thesaurus' option each line in the file should
846f4d8b76dSBram Moolenaarcontain words with similar meaning, separated by non-keyword characters (white
847f4d8b76dSBram Moolenaarspace is preferred).  Maximum line length is 510 bytes.
848f4d8b76dSBram Moolenaar
849f4d8b76dSBram MoolenaarFor an example, imagine the 'thesaurus' file has a line like this: >
850f4d8b76dSBram Moolenaar	angry furious mad enraged
851f4d8b76dSBram Moolenaar<Placing the cursor after the letters "ang" and typing CTRL-X CTRL-T would
852f4d8b76dSBram Moolenaarcomplete the word "angry"; subsequent presses would change the word to
853f4d8b76dSBram Moolenaar"furious", "mad" etc.
854f4d8b76dSBram Moolenaar
855f4d8b76dSBram MoolenaarOther uses include translation between two languages, or grouping API
856f4d8b76dSBram Moolenaarfunctions by keyword.
857f4d8b76dSBram Moolenaar
858f4d8b76dSBram MoolenaarAn English word list was added to this github issue:
859f4d8b76dSBram Moolenaarhttps://github.com/vim/vim/issues/629#issuecomment-443293282
860f4d8b76dSBram MoolenaarUnpack thesaurus_pkg.zip, put the thesaurus.txt file somewhere, e.g.
861f4d8b76dSBram Moolenaar~/.vim/thesaurus/english.txt, and the 'thesaurus' option to this file name.
862f4d8b76dSBram Moolenaar
863f4d8b76dSBram Moolenaar
864f4d8b76dSBram MoolenaarCompleting keywords with 'thesaurusfunc'		*compl-thesaurusfunc*
865f4d8b76dSBram Moolenaar
866f4d8b76dSBram MoolenaarIf the 'thesaurusfunc' option is set, then the user specified function is
867f4d8b76dSBram Moolenaarinvoked to get the list of completion matches and the 'thesaurus' option is
868f4d8b76dSBram Moolenaarnot used. See |complete-functions| for an explanation of how the function is
869f4d8b76dSBram Moolenaarinvoked and what it should return.
870f4d8b76dSBram Moolenaar
871f4d8b76dSBram MoolenaarHere is an example that uses the "aiksaurus" command (provided by Magnus
872f4d8b76dSBram MoolenaarGroß): >
873f4d8b76dSBram Moolenaar
874f4d8b76dSBram Moolenaar    func Thesaur(findstart, base)
875f4d8b76dSBram Moolenaar      if a:findstart
876*113cb513SBram Moolenaar    	return searchpos('\<', 'bnW', line('.'))[1] - 1
877*113cb513SBram Moolenaar      endif
878f4d8b76dSBram Moolenaar      let res = []
879f4d8b76dSBram Moolenaar      let h = ''
880*113cb513SBram Moolenaar      for l in systemlist('aiksaurus '.shellescape(a:base))
881f4d8b76dSBram Moolenaar	if l[:3] == '=== '
882*113cb513SBram Moolenaar	  let h = '('.substitute(l[4:], ' =*$', ')', '')
883*113cb513SBram Moolenaar	elseif l ==# 'Alphabetically similar known words are: '
884*113cb513SBram Moolenaar	  let h = "\U0001f52e"
885*113cb513SBram Moolenaar	elseif l[0] =~ '\a' || (h ==# "\U0001f52e" && l[0] ==# "\t")
886*113cb513SBram Moolenaar	  call extend(res, map(split(substitute(l, '^\t', '', ''), ', '), {_, val -> {'word': val, 'menu': h}}))
887f4d8b76dSBram Moolenaar	endif
888f4d8b76dSBram Moolenaar      endfor
889f4d8b76dSBram Moolenaar      return res
890f4d8b76dSBram Moolenaar    endfunc
891f4d8b76dSBram Moolenaar
892079ba76aSBram Moolenaar    if exists('+thesaurusfunc')
893f4d8b76dSBram Moolenaar      set thesaurusfunc=Thesaur
894f4d8b76dSBram Moolenaar    endif
895f4d8b76dSBram Moolenaar
896071d4279SBram Moolenaar
897071d4279SBram MoolenaarCompleting keywords in the current and included files	*compl-keyword*
898071d4279SBram Moolenaar
899071d4279SBram MoolenaarThe 'include' option is used to specify a line that contains an include file
900071d4279SBram Moolenaarname.  The 'path' option is used to search for include files.
901071d4279SBram Moolenaar
902071d4279SBram Moolenaar							*i_CTRL-X_CTRL-I*
903071d4279SBram MoolenaarCTRL-X CTRL-I		Search for the first keyword in the current and
904071d4279SBram Moolenaar			included files that starts with the same characters
905071d4279SBram Moolenaar			as those before the cursor.  The matched keyword is
906071d4279SBram Moolenaar			inserted in front of the cursor.
907071d4279SBram Moolenaar
908071d4279SBram Moolenaar	CTRL-N		Search forwards for next matching keyword.  This
909071d4279SBram Moolenaar			keyword replaces the previous matching keyword.
910071d4279SBram Moolenaar			Note: CTRL-I is the same as <Tab>, which is likely to
911071d4279SBram Moolenaar			be typed after a successful completion, therefore
912071d4279SBram Moolenaar			CTRL-I is not used for searching for the next match.
913071d4279SBram Moolenaar
914071d4279SBram Moolenaar	CTRL-P		Search backward for previous matching keyword.  This
915071d4279SBram Moolenaar			keyword replaces the previous matching keyword.
916071d4279SBram Moolenaar
917071d4279SBram Moolenaar	CTRL-X CTRL-I	Further use of CTRL-X CTRL-I will copy the words
918071d4279SBram Moolenaar			following the previous expansion in other contexts
919071d4279SBram Moolenaar			unless a double CTRL-X is used.
920071d4279SBram Moolenaar
921071d4279SBram MoolenaarCompleting tags						*compl-tag*
922071d4279SBram Moolenaar							*i_CTRL-X_CTRL-]*
923071d4279SBram MoolenaarCTRL-X CTRL-]		Search for the first tag that starts with the same
924071d4279SBram Moolenaar			characters as before the cursor.  The matching tag is
925071d4279SBram Moolenaar			inserted in front of the cursor.  Alphabetic
926071d4279SBram Moolenaar			characters and characters in 'iskeyword' are used
927071d4279SBram Moolenaar			to decide which characters are included in the tag
928071d4279SBram Moolenaar			name (same as for a keyword).  See also |CTRL-]|.
929071d4279SBram Moolenaar			The 'showfulltag' option can be used to add context
930071d4279SBram Moolenaar			from around the tag definition.
931071d4279SBram Moolenaar	CTRL-]	or
932071d4279SBram Moolenaar	CTRL-N		Search forwards for next matching tag.  This tag
933071d4279SBram Moolenaar			replaces the previous matching tag.
934071d4279SBram Moolenaar
935071d4279SBram Moolenaar	CTRL-P		Search backward for previous matching tag.  This tag
936071d4279SBram Moolenaar			replaces the previous matching tag.
937071d4279SBram Moolenaar
938071d4279SBram Moolenaar
939071d4279SBram MoolenaarCompleting file names					*compl-filename*
940071d4279SBram Moolenaar							*i_CTRL-X_CTRL-F*
941071d4279SBram MoolenaarCTRL-X CTRL-F		Search for the first file name that starts with the
942071d4279SBram Moolenaar			same characters as before the cursor.  The matching
943071d4279SBram Moolenaar			file name is inserted in front of the cursor.
944071d4279SBram Moolenaar			Alphabetic characters and characters in 'isfname'
945071d4279SBram Moolenaar			are used to decide which characters are included in
946071d4279SBram Moolenaar			the file name.  Note: the 'path' option is not used
947071d4279SBram Moolenaar			here (yet).
948071d4279SBram Moolenaar	CTRL-F	or
949071d4279SBram Moolenaar	CTRL-N		Search forwards for next matching file name.  This
950071d4279SBram Moolenaar			file name replaces the previous matching file name.
951071d4279SBram Moolenaar
952071d4279SBram Moolenaar	CTRL-P		Search backward for previous matching file name.
953071d4279SBram Moolenaar			This file name replaces the previous matching file
954071d4279SBram Moolenaar			name.
955071d4279SBram Moolenaar
956071d4279SBram Moolenaar
957071d4279SBram MoolenaarCompleting definitions or macros			*compl-define*
958071d4279SBram Moolenaar
959071d4279SBram MoolenaarThe 'define' option is used to specify a line that contains a definition.
960071d4279SBram MoolenaarThe 'include' option is used to specify a line that contains an include file
961071d4279SBram Moolenaarname.  The 'path' option is used to search for include files.
962071d4279SBram Moolenaar
963071d4279SBram Moolenaar							*i_CTRL-X_CTRL-D*
964071d4279SBram MoolenaarCTRL-X CTRL-D		Search in the current and included files for the
965071d4279SBram Moolenaar			first definition (or macro) name that starts with
966071d4279SBram Moolenaar			the same characters as before the cursor.  The found
967071d4279SBram Moolenaar			definition name is inserted in front of the cursor.
968071d4279SBram Moolenaar	CTRL-D	or
969071d4279SBram Moolenaar	CTRL-N		Search forwards for next matching macro name.  This
970071d4279SBram Moolenaar			macro name replaces the previous matching macro
971071d4279SBram Moolenaar			name.
972071d4279SBram Moolenaar
973071d4279SBram Moolenaar	CTRL-P		Search backward for previous matching macro name.
974071d4279SBram Moolenaar			This macro name replaces the previous matching macro
975071d4279SBram Moolenaar			name.
976071d4279SBram Moolenaar
977071d4279SBram Moolenaar	CTRL-X CTRL-D	Further use of CTRL-X CTRL-D will copy the words
978071d4279SBram Moolenaar			following the previous expansion in other contexts
979071d4279SBram Moolenaar			unless a double CTRL-X is used.
980071d4279SBram Moolenaar
981071d4279SBram Moolenaar
982071d4279SBram MoolenaarCompleting Vim commands					*compl-vim*
983071d4279SBram Moolenaar
984071d4279SBram MoolenaarCompletion is context-sensitive.  It works like on the Command-line.  It
9854be06f9eSBram Moolenaarcompletes an Ex command as well as its arguments.  This is useful when writing
9864be06f9eSBram Moolenaara Vim script.
987071d4279SBram Moolenaar
988071d4279SBram Moolenaar							*i_CTRL-X_CTRL-V*
989071d4279SBram MoolenaarCTRL-X CTRL-V		Guess what kind of item is in front of the cursor and
990071d4279SBram Moolenaar			find the first match for it.
991071d4279SBram Moolenaar			Note: When CTRL-V is mapped you can often use CTRL-Q
9923577c6faSBram Moolenaar			instead of |i_CTRL-Q|.
993071d4279SBram Moolenaar	CTRL-V	or
994071d4279SBram Moolenaar	CTRL-N		Search forwards for next match.  This match replaces
995071d4279SBram Moolenaar			the previous one.
996071d4279SBram Moolenaar
9973577c6faSBram Moolenaar	CTRL-P		Search backwards for previous match.  This match
998071d4279SBram Moolenaar			replaces the previous one.
999071d4279SBram Moolenaar
1000071d4279SBram Moolenaar	CTRL-X CTRL-V	Further use of CTRL-X CTRL-V will do the same as
1001071d4279SBram Moolenaar			CTRL-V.  This allows mapping a key to do Vim command
1002071d4279SBram Moolenaar			completion, for example: >
1003071d4279SBram Moolenaar				:imap <Tab> <C-X><C-V>
1004071d4279SBram Moolenaar
10054be06f9eSBram MoolenaarUser defined completion					*compl-function*
1006cfbc5ee4SBram Moolenaar
1007cfbc5ee4SBram MoolenaarCompletion is done by a function that can be defined by the user with the
1008280f126eSBram Moolenaar'completefunc' option.  See below for how the function is called and an
1009280f126eSBram Moolenaarexample |complete-functions|.
1010cfbc5ee4SBram Moolenaar
1011cfbc5ee4SBram Moolenaar							*i_CTRL-X_CTRL-U*
1012cfbc5ee4SBram MoolenaarCTRL-X CTRL-U		Guess what kind of item is in front of the cursor and
1013cfbc5ee4SBram Moolenaar			find the first match for it.
1014cfbc5ee4SBram Moolenaar	CTRL-U	or
1015cfbc5ee4SBram Moolenaar	CTRL-N		Use the next match.  This match replaces the previous
1016cfbc5ee4SBram Moolenaar			one.
1017cfbc5ee4SBram Moolenaar
1018cfbc5ee4SBram Moolenaar	CTRL-P		Use the previous match.  This match replaces the
1019cfbc5ee4SBram Moolenaar			previous one.
1020cfbc5ee4SBram Moolenaar
1021cfbc5ee4SBram Moolenaar
1022f75a963eSBram MoolenaarOmni completion						*compl-omni*
10234be06f9eSBram Moolenaar
1024e344beadSBram MoolenaarCompletion is done by a function that can be defined by the user with the
1025f75a963eSBram Moolenaar'omnifunc' option.  This is to be used for filetype-specific completion.
1026e344beadSBram Moolenaar
1027280f126eSBram MoolenaarSee below for how the function is called and an example |complete-functions|.
1028f75a963eSBram MoolenaarFor remarks about specific filetypes see |compl-omni-filetypes|.
10299c102387SBram MoolenaarMore completion scripts will appear, check www.vim.org.  Currently there is a
10309c102387SBram Moolenaarfirst version for C++.
10314be06f9eSBram Moolenaar
10324be06f9eSBram Moolenaar							*i_CTRL-X_CTRL-O*
10334be06f9eSBram MoolenaarCTRL-X CTRL-O		Guess what kind of item is in front of the cursor and
10344be06f9eSBram Moolenaar			find the first match for it.
10354be06f9eSBram Moolenaar	CTRL-O	or
10364be06f9eSBram Moolenaar	CTRL-N		Use the next match.  This match replaces the previous
10374be06f9eSBram Moolenaar			one.
10384be06f9eSBram Moolenaar
10394be06f9eSBram Moolenaar	CTRL-P		Use the previous match.  This match replaces the
10404be06f9eSBram Moolenaar			previous one.
10414be06f9eSBram Moolenaar
10424be06f9eSBram Moolenaar
1043488c6512SBram MoolenaarSpelling suggestions					*compl-spelling*
1044488c6512SBram Moolenaar
10455195e456SBram MoolenaarA word before or at the cursor is located and correctly spelled words are
10465195e456SBram Moolenaarsuggested to replace it.  If there is a badly spelled word in the line, before
10475195e456SBram Moolenaaror under the cursor, the cursor is moved to after it.  Otherwise the word just
10485195e456SBram Moolenaarbefore the cursor is used for suggestions, even though it isn't badly spelled.
10495195e456SBram Moolenaar
1050488c6512SBram MoolenaarNOTE: CTRL-S suspends display in many Unix terminals.  Use 's' instead.  Type
1051488c6512SBram MoolenaarCTRL-Q to resume displaying.
1052488c6512SBram Moolenaar
1053488c6512SBram Moolenaar						*i_CTRL-X_CTRL-S* *i_CTRL-X_s*
1054488c6512SBram MoolenaarCTRL-X CTRL-S   or
1055488c6512SBram MoolenaarCTRL-X s		Locate the word in front of the cursor and find the
1056488c6512SBram Moolenaar			first spell suggestion for it.
1057488c6512SBram Moolenaar	CTRL-S	or
1058488c6512SBram Moolenaar	CTRL-N		Use the next suggestion.  This replaces the previous
1059488c6512SBram Moolenaar			one.  Note that you can't use 's' here.
1060488c6512SBram Moolenaar
1061488c6512SBram Moolenaar	CTRL-P		Use the previous suggestion.  This replaces the
1062488c6512SBram Moolenaar			previous one.
1063488c6512SBram Moolenaar
1064488c6512SBram Moolenaar
1065071d4279SBram MoolenaarCompleting keywords from different sources		*compl-generic*
1066071d4279SBram Moolenaar
1067071d4279SBram Moolenaar							*i_CTRL-N*
1068071d4279SBram MoolenaarCTRL-N			Find next match for words that start with the
1069071d4279SBram Moolenaar			keyword in front of the cursor, looking in places
1070071d4279SBram Moolenaar			specified with the 'complete' option.  The found
1071071d4279SBram Moolenaar			keyword is inserted in front of the cursor.
1072071d4279SBram Moolenaar
1073071d4279SBram Moolenaar							*i_CTRL-P*
1074071d4279SBram MoolenaarCTRL-P			Find previous match for words that start with the
1075071d4279SBram Moolenaar			keyword in front of the cursor, looking in places
1076071d4279SBram Moolenaar			specified with the 'complete' option.  The found
1077071d4279SBram Moolenaar			keyword is inserted in front of the cursor.
1078071d4279SBram Moolenaar
1079071d4279SBram Moolenaar	CTRL-N		Search forward for next matching keyword.  This
1080071d4279SBram Moolenaar			keyword replaces the previous matching keyword.
1081071d4279SBram Moolenaar
1082071d4279SBram Moolenaar	CTRL-P		Search backwards for next matching keyword.  This
1083071d4279SBram Moolenaar			keyword replaces the previous matching keyword.
1084071d4279SBram Moolenaar
1085071d4279SBram Moolenaar	CTRL-X CTRL-N or
1086071d4279SBram Moolenaar	CTRL-X CTRL-P	Further use of CTRL-X CTRL-N or CTRL-X CTRL-P will
1087071d4279SBram Moolenaar			copy the words following the previous expansion in
1088071d4279SBram Moolenaar			other contexts unless a double CTRL-X is used.
1089071d4279SBram Moolenaar
1090578b49e4SBram Moolenaar
1091dca29d9cSzeertzjqStop completion						*compl-stop*
1092dca29d9cSzeertzjq
1093dca29d9cSzeertzjq							*i_CTRL-X_CTRL-Z*
1094dca29d9cSzeertzjqCTRL-X CTRL-Z		Stop completion without changing the text.
1095dca29d9cSzeertzjq
1096dca29d9cSzeertzjq
1097280f126eSBram MoolenaarFUNCTIONS FOR FINDING COMPLETIONS			*complete-functions*
1098280f126eSBram Moolenaar
1099160e994dSYegappan LakshmananThis applies to 'completefunc', 'thesaurusfunc' and 'omnifunc'.
1100280f126eSBram Moolenaar
11018b6144bdSBram MoolenaarThe function is called in two different ways:
11028b6144bdSBram Moolenaar- First the function is called to find the start of the text to be completed.
11038b6144bdSBram Moolenaar- Later the function is called to actually find the matches.
1104280f126eSBram Moolenaar
1105280f126eSBram MoolenaarOn the first invocation the arguments are:
1106280f126eSBram Moolenaar   a:findstart  1
1107280f126eSBram Moolenaar   a:base	empty
1108280f126eSBram Moolenaar
11098b6144bdSBram MoolenaarThe function must return the column where the completion starts.  It must be a
11108b6144bdSBram Moolenaarnumber between zero and the cursor column "col('.')".  This involves looking
11118b6144bdSBram Moolenaarat the characters just before the cursor and including those characters that
11128b6144bdSBram Moolenaarcould be part of the completed item.  The text between this column and the
1113fc65cabbSBram Moolenaarcursor column will be replaced with the matches.  If the returned value is
1114fc65cabbSBram Moolenaarlarger than the cursor column, the cursor column is used.
11158e52a593SBram Moolenaar
1116fc65cabbSBram MoolenaarNegative return values:
11178e52a593SBram Moolenaar   -2 	To cancel silently and stay in completion mode.
11188e52a593SBram Moolenaar   -3 	To cancel silently and leave completion mode.
1119fc65cabbSBram Moolenaar   Another negative value: completion starts at the cursor column
1120280f126eSBram Moolenaar
1121280f126eSBram MoolenaarOn the second invocation the arguments are:
1122280f126eSBram Moolenaar   a:findstart  0
11238b6144bdSBram Moolenaar   a:base	the text with which matches should match; the text that was
1124280f126eSBram Moolenaar		located in the first call (can be empty)
1125280f126eSBram Moolenaar
1126280f126eSBram MoolenaarThe function must return a List with the matching words.  These matches
1127280f126eSBram Moolenaarusually include the "a:base" text.  When there are no matches return an empty
112890df4b9dSBram MoolenaarList.  Note that the cursor may have moved since the first invocation, the
112990df4b9dSBram Moolenaartext may have been changed.
11305302d9ebSBram Moolenaar
11315302d9ebSBram MoolenaarIn order to return more information than the matching words, return a Dict
11325302d9ebSBram Moolenaarthat contains the List.  The Dict can have these items:
11335302d9ebSBram Moolenaar	words		The List of matching words (mandatory).
11345302d9ebSBram Moolenaar	refresh		A string to control re-invocation of the function
11355302d9ebSBram Moolenaar			(optional).
11365302d9ebSBram Moolenaar			The only value currently recognized is "always", the
11375302d9ebSBram Moolenaar			effect is that the function is called whenever the
11385302d9ebSBram Moolenaar			leading text is changed.
1139cee9bc2eSBram Moolenaar
1140cee9bc2eSBram MoolenaarIf you want to suppress the warning message for an empty result, return
1141314dd79cSBram Moolenaar|v:none|.  This is useful to implement asynchronous completion with
1142314dd79cSBram Moolenaar|complete()|.
1143cee9bc2eSBram Moolenaar
11445302d9ebSBram MoolenaarOther items are ignored.
11455302d9ebSBram Moolenaar
1146560979edSBram MoolenaarFor acting upon end of completion, see the |CompleteDonePre| and
1147560979edSBram Moolenaar|CompleteDone| autocommand event.
114830b65817SBram Moolenaar
11495302d9ebSBram MoolenaarFor example, the function can contain this: >
11505302d9ebSBram Moolenaar	let matches = ... list of words ...
11515302d9ebSBram Moolenaar	return {'words': matches, 'refresh': 'always'}
11525302d9ebSBram Moolenaar<
11535c4bab0fSBram Moolenaar						*complete-items*
11548b6144bdSBram MoolenaarEach list item can either be a string or a Dictionary.  When it is a string it
11558b6144bdSBram Moolenaaris used as the completion.  When it is a Dictionary it can contain these
11568b6144bdSBram Moolenaaritems:
1157910f66f9SBram Moolenaar	word		the text that will be inserted, mandatory
1158910f66f9SBram Moolenaar	abbr		abbreviation of "word"; when not empty it is used in
1159910f66f9SBram Moolenaar			the menu instead of "word"
11608dff818eSBram Moolenaar	menu		extra text for the popup menu, displayed after "word"
11618dff818eSBram Moolenaar			or "abbr"
1162910f66f9SBram Moolenaar	info		more information about the item, can be displayed in a
116362a0cb44SBram Moolenaar			preview or popup window
11648b6144bdSBram Moolenaar	kind		single letter indicating the type of completion
116591170f8aSBram Moolenaar	icase		when non-zero case is to be ignored when comparing
116691170f8aSBram Moolenaar			items to be equal; when omitted zero is used, thus
116791170f8aSBram Moolenaar			items that only differ in case are added
116873655cf0SBram Moolenaar	equal		when non-zero, always treat this item to be equal when
116973655cf0SBram Moolenaar			comparing. Which means, "equal=1" disables filtering
117073655cf0SBram Moolenaar			of this item.
11714a85b415SBram Moolenaar	dup		when non-zero this match will be added even when an
11724a85b415SBram Moolenaar			item with the same word is already present.
1173166af9bbSBram Moolenaar	empty		when non-zero this match will be added even when it is
1174166af9bbSBram Moolenaar			an empty string
11759b56a57cSBram Moolenaar	user_data 	custom data which is associated with the item and
11760892832bSBram Moolenaar			available in |v:completed_item|; it can be any type;
11770892832bSBram Moolenaar			defaults to an empty string
11788b6144bdSBram Moolenaar
117973655cf0SBram MoolenaarAll of these except "icase", "equal", "dup" and "empty" must be a string.  If
118073655cf0SBram Moolenaaran item does not meet these requirements then an error message is given and
118173655cf0SBram Moolenaarfurther items in the list are not used.  You can mix string and Dictionary
118273655cf0SBram Moolenaaritems in the returned list.
11838b6144bdSBram Moolenaar
11848b6144bdSBram MoolenaarThe "menu" item is used in the popup menu and may be truncated, thus it should
11850b598c2fSBram Moolenaarbe relatively short.  The "info" item can be longer, it will  be displayed in
118662a0cb44SBram Moolenaarthe preview window when "preview" appears in 'completeopt' or in a popup
118762a0cb44SBram Moolenaarwindow when "popup" appears in 'completeopt'.  In the preview window the
118862a0cb44SBram Moolenaar"info" item will also remain displayed after the popup menu has been removed.
118962a0cb44SBram MoolenaarThis is useful for function arguments.  Use a single space for "info" to
119062a0cb44SBram Moolenaarremove existing text in the preview window.  The size of the preview window is
119162a0cb44SBram Moolenaarthree lines, but 'previewheight' is used when it has a value of 1 or 2.
119262a0cb44SBram Moolenaar
119362a0cb44SBram Moolenaar						*complete-popup*
119462a0cb44SBram MoolenaarWhen "popup" is in 'completeopt' a popup window is used to display the "info".
119506fe74aeSBram MoolenaarThen the 'completepopup' option specifies the properties of the popup.  This
119606fe74aeSBram Moolenaaris used when the info popup is created.  The option is a comma separated list
119706fe74aeSBram Moolenaarof values:
119862a0cb44SBram Moolenaar	height		maximum height of the popup
119962a0cb44SBram Moolenaar	width		maximum width of the popup
12008fe1000eSBram Moolenaar	highlight	highlight group of the popup (default is PmenuSel)
1201258cef59SBram Moolenaar	align		"item" (default) or "menu"
1202258cef59SBram Moolenaar	border		"on" (default) or "off"
120362a0cb44SBram MoolenaarExample: >
120462a0cb44SBram Moolenaar	:set completepopup=height:10,width:60,highlight:InfoPopup
12058b6144bdSBram Moolenaar
120606fe74aeSBram MoolenaarWhen the "align" value is "item" then the popup is positioned close to the
1207258cef59SBram Moolenaarselected item.  Changing the selection will also move the popup.  When "align"
1208258cef59SBram Moolenaaris "menu" then the popup is aligned with the top of the menu if the menu is
1209258cef59SBram Moolenaarbelow the text, and the bottom of the menu otherwise.
1210258cef59SBram Moolenaar
121106fe74aeSBram MoolenaarAfter the info popup is created it can be found with |popup_findinfo()| and
121206fe74aeSBram Moolenaarproperties can be changed with |popup_setoptions()|.
121306fe74aeSBram Moolenaar
1214dca7abe7SBram Moolenaar						*complete-popuphidden*
1215dca7abe7SBram MoolenaarIf the information for the popup is obtained asynchronously, use "popuphidden"
121691359014SBram Moolenaarin 'completeopt'.  The info popup will then be initially hidden and
1217dca7abe7SBram Moolenaar|popup_show()| must be called once it has been filled with the info.  This can
1218dca7abe7SBram Moolenaarbe done with a |CompleteChanged| autocommand, something like this: >
1219dca7abe7SBram Moolenaar	set completeopt+=popuphidden
1220dca7abe7SBram Moolenaar	au CompleteChanged * call UpdateCompleteInfo()
1221dca7abe7SBram Moolenaar	func UpdateCompleteInfo()
1222dca7abe7SBram Moolenaar	  " Cancel any pending info fetch
1223dca7abe7SBram Moolenaar	  let item = v:event.completed_item
1224dca7abe7SBram Moolenaar	  " Start fetching info for the item then call ShowCompleteInfo(info)
1225dca7abe7SBram Moolenaar	endfunc
1226dca7abe7SBram Moolenaar	func ShowCompleteInfo(info)
1227dca7abe7SBram Moolenaar	  let id = popup_findinfo()
1228dca7abe7SBram Moolenaar	  if id
1229dca7abe7SBram Moolenaar	    call popup_settext(id, 'async info: ' .. a:info)
1230dca7abe7SBram Moolenaar	    call popup_show(id)
1231dca7abe7SBram Moolenaar	  endif
1232dca7abe7SBram Moolenaar	endfunc
1233dca7abe7SBram Moolenaar
1234dca7abe7SBram Moolenaar<						*complete-item-kind*
12358b6144bdSBram MoolenaarThe "kind" item uses a single letter to indicate the kind of completion.  This
12368b6144bdSBram Moolenaarmay be used to show the completion differently (different color or icon).
12378b6144bdSBram MoolenaarCurrently these types can be used:
12388b6144bdSBram Moolenaar	v	variable
12398b6144bdSBram Moolenaar	f	function or method
12400b598c2fSBram Moolenaar	m	member of a struct or class
12410b598c2fSBram Moolenaar	t	typedef
12420b598c2fSBram Moolenaar	d	#define or macro
1243280f126eSBram Moolenaar
1244280f126eSBram MoolenaarWhen searching for matches takes some time call |complete_add()| to add each
1245280f126eSBram Moolenaarmatch to the total list.  These matches should then not appear in the returned
1246280f126eSBram Moolenaarlist!  Call |complete_check()| now and then to allow the user to press a key
1247280f126eSBram Moolenaarwhile still searching for matches.  Stop searching when it returns non-zero.
1248280f126eSBram Moolenaar
12496aa57295SBram Moolenaar							*E840*
1250166af9bbSBram MoolenaarThe function is allowed to move the cursor, it is restored afterwards.
1251166af9bbSBram MoolenaarThe function is not allowed to move to another window or delete text.
1252280f126eSBram Moolenaar
1253280f126eSBram MoolenaarAn example that completes the names of the months: >
1254280f126eSBram Moolenaar	fun! CompleteMonths(findstart, base)
1255280f126eSBram Moolenaar	  if a:findstart
1256280f126eSBram Moolenaar	    " locate the start of the word
1257280f126eSBram Moolenaar	    let line = getline('.')
1258280f126eSBram Moolenaar	    let start = col('.') - 1
1259280f126eSBram Moolenaar	    while start > 0 && line[start - 1] =~ '\a'
1260280f126eSBram Moolenaar	      let start -= 1
1261280f126eSBram Moolenaar	    endwhile
1262280f126eSBram Moolenaar	    return start
1263280f126eSBram Moolenaar	  else
1264280f126eSBram Moolenaar	    " find months matching with "a:base"
1265280f126eSBram Moolenaar	    let res = []
1266280f126eSBram Moolenaar	    for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec")
1267280f126eSBram Moolenaar	      if m =~ '^' . a:base
1268280f126eSBram Moolenaar		call add(res, m)
1269280f126eSBram Moolenaar	      endif
1270280f126eSBram Moolenaar	    endfor
1271280f126eSBram Moolenaar	    return res
1272280f126eSBram Moolenaar	  endif
1273280f126eSBram Moolenaar	endfun
1274280f126eSBram Moolenaar	set completefunc=CompleteMonths
1275280f126eSBram Moolenaar<
1276280f126eSBram MoolenaarThe same, but now pretending searching for matches is slow: >
1277280f126eSBram Moolenaar	fun! CompleteMonths(findstart, base)
1278280f126eSBram Moolenaar	  if a:findstart
1279280f126eSBram Moolenaar	    " locate the start of the word
1280280f126eSBram Moolenaar	    let line = getline('.')
1281280f126eSBram Moolenaar	    let start = col('.') - 1
1282280f126eSBram Moolenaar	    while start > 0 && line[start - 1] =~ '\a'
1283280f126eSBram Moolenaar	      let start -= 1
1284280f126eSBram Moolenaar	    endwhile
1285280f126eSBram Moolenaar	    return start
1286280f126eSBram Moolenaar	  else
1287280f126eSBram Moolenaar	    " find months matching with "a:base"
1288280f126eSBram Moolenaar	    for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec")
1289280f126eSBram Moolenaar	      if m =~ '^' . a:base
1290280f126eSBram Moolenaar		call complete_add(m)
1291280f126eSBram Moolenaar	      endif
1292280f126eSBram Moolenaar	      sleep 300m	" simulate searching for next match
1293280f126eSBram Moolenaar	      if complete_check()
1294280f126eSBram Moolenaar		break
1295280f126eSBram Moolenaar	      endif
1296280f126eSBram Moolenaar	    endfor
1297280f126eSBram Moolenaar	    return []
1298280f126eSBram Moolenaar	  endif
1299280f126eSBram Moolenaar	endfun
1300280f126eSBram Moolenaar	set completefunc=CompleteMonths
1301280f126eSBram Moolenaar<
1302280f126eSBram Moolenaar
13031c7715dfSBram MoolenaarINSERT COMPLETION POPUP MENU				*ins-completion-menu*
1304ebefac63SBram Moolenaar							*popupmenu-completion*
13051c7715dfSBram MoolenaarVim can display the matches in a simplistic popup menu.
13061c7715dfSBram Moolenaar
13071c7715dfSBram MoolenaarThe menu is used when:
1308a2031823SBram Moolenaar- The 'completeopt' option contains "menu" or "menuone".
13091c7715dfSBram Moolenaar- The terminal supports at least 8 colors.
1310d68071d8SBram Moolenaar- There are at least two matches.  One if "menuone" is used.
13111c7715dfSBram Moolenaar
131256718730SBram MoolenaarThe 'pumheight' option can be used to set a maximum height.  The default is to
131356718730SBram Moolenaaruse all space available.
13149b56a57cSBram MoolenaarThe 'pumwidth' option can be used to set a minimum width.  The default is 15
13159b56a57cSBram Moolenaarcharacters.
131656718730SBram Moolenaar
1317779b74b2SBram MoolenaarThere are three states:
1318779b74b2SBram Moolenaar1. A complete match has been inserted, e.g., after using CTRL-N or CTRL-P.
1319779b74b2SBram Moolenaar2. A cursor key has been used to select another match.  The match was not
1320779b74b2SBram Moolenaar   inserted then, only the entry in the popup menu is highlighted.
1321779b74b2SBram Moolenaar3. Only part of a match has been inserted and characters were typed or the
1322779b74b2SBram Moolenaar   backspace key was used.  The list of matches was then adjusted for what is
1323779b74b2SBram Moolenaar   in front of the cursor.
1324c7453f52SBram Moolenaar
132580a94a58SBram MoolenaarYou normally start in the first state, with the first match being inserted.
13261d2ba7faSBram MoolenaarWhen "longest" is in 'completeopt' and there is more than one match you start
1327779b74b2SBram Moolenaarin the third state.
1328c7453f52SBram Moolenaar
1329779b74b2SBram MoolenaarIf you select another match, e.g., with CTRL-N or CTRL-P, you go to the first
1330779b74b2SBram Moolenaarstate.  This doesn't change the list of matches.
133180a94a58SBram Moolenaar
1332779b74b2SBram MoolenaarWhen you are back at the original text then you are in the third state.  To
1333a2031823SBram Moolenaarget there right away you can use a mapping that uses CTRL-P right after
1334a2031823SBram Moolenaarstarting the completion: >
1335a2031823SBram Moolenaar	:imap <F7> <C-N><C-P>
133676916e60SBram Moolenaar<
133776916e60SBram Moolenaar						*popupmenu-keys*
13381d2ba7faSBram MoolenaarIn the first state these keys have a special meaning:
13391d2ba7faSBram Moolenaar<BS> and CTRL-H   Delete one character, find the matches for the word before
13401d2ba7faSBram Moolenaar		  the cursor.  This reduces the list of matches, often to one
134180a94a58SBram Moolenaar		  entry, and switches to the second state.
1342779b74b2SBram MoolenaarAny non-special character:
1343779b74b2SBram Moolenaar		  Stop completion without changing the match and insert the
1344779b74b2SBram Moolenaar		  typed character.
13451d2ba7faSBram Moolenaar
1346779b74b2SBram MoolenaarIn the second and third state these keys have a special meaning:
13478b6144bdSBram Moolenaar<BS> and CTRL-H   Delete one character, find the matches for the shorter word
13488b6144bdSBram Moolenaar		  before the cursor.  This may find more matches.
13498b6144bdSBram MoolenaarCTRL-L		  Add one character from the current match, may reduce the
13501d2ba7faSBram Moolenaar		  number of matches.
135180a94a58SBram Moolenaarany printable, non-white character:
135280a94a58SBram Moolenaar		  Add this character and reduce the number of matches.
1353c7453f52SBram Moolenaar
1354779b74b2SBram MoolenaarIn all three states these can be used:
1355d2cec5b0SBram MoolenaarCTRL-Y		  Yes: Accept the currently selected match and stop completion.
13569964e468SBram MoolenaarCTRL-E		  End completion, go back to what was there before selecting a
13579964e468SBram Moolenaar		  match (what was typed or longest common string).
135880a94a58SBram Moolenaar<PageUp>	  Select a match several entries back, but don't insert it.
135980a94a58SBram Moolenaar<PageDown>	  Select a match several entries further, but don't insert it.
13601d2ba7faSBram Moolenaar<Up>		  Select the previous match, as if CTRL-P was used, but don't
136180a94a58SBram Moolenaar		  insert it.
13621d2ba7faSBram Moolenaar<Down>		  Select the next match, as if CTRL-N was used, but don't
136380a94a58SBram Moolenaar		  insert it.
13649964e468SBram Moolenaar<Space> or <Tab>  Stop completion without changing the match and insert the
1365779b74b2SBram Moolenaar		  typed character.
1366779b74b2SBram Moolenaar
1367044b68f4SBram MoolenaarThe behavior of the <Enter> key depends on the state you are in:
1368779b74b2SBram Moolenaarfirst state:	  Use the text as it is and insert a line break.
1369779b74b2SBram Moolenaarsecond state:	  Insert the currently selected match.
1370779b74b2SBram Moolenaarthird state:	  Use the text as it is and insert a line break.
1371779b74b2SBram Moolenaar
1372779b74b2SBram MoolenaarIn other words: If you used the cursor keys to select another entry in the
1373044b68f4SBram Moolenaarlist of matches then the <Enter> key inserts that match.  If you typed
1374044b68f4SBram Moolenaarsomething else then <Enter> inserts a line break.
13751d2ba7faSBram Moolenaar
13761c7715dfSBram Moolenaar
13771c7715dfSBram MoolenaarThe colors of the menu can be changed with these highlight groups:
13781c7715dfSBram MoolenaarPmenu		normal item  |hl-Pmenu|
13791c7715dfSBram MoolenaarPmenuSel	selected item  |hl-PmenuSel|
13801c7715dfSBram MoolenaarPmenuSbar	scrollbar  |hl-PmenuSbar|
13811c7715dfSBram MoolenaarPmenuThumb	thumb of the scrollbar  |hl-PmenuThumb|
13821c7715dfSBram Moolenaar
13831d2ba7faSBram MoolenaarThere are no special mappings for when the popup menu is visible.  However,
13841d2ba7faSBram Moolenaaryou can use an Insert mode mapping that checks the |pumvisible()| function to
13851d2ba7faSBram Moolenaardo something different.  Example: >
13861d2ba7faSBram Moolenaar	:inoremap <Down> <C-R>=pumvisible() ? "\<lt>C-N>" : "\<lt>Down>"<CR>
13871c7715dfSBram Moolenaar
13885c4bab0fSBram MoolenaarYou can use of <expr> in mapping to have the popup menu used when typing a
13895c4bab0fSBram Moolenaarcharacter and some condition is met.  For example, for typing a dot: >
13905c4bab0fSBram Moolenaar	inoremap <expr> . MayComplete()
13915c4bab0fSBram Moolenaar	func MayComplete()
13925c4bab0fSBram Moolenaar	    if (can complete)
13935c4bab0fSBram Moolenaar	      return ".\<C-X>\<C-O>"
13945c4bab0fSBram Moolenaar	    endif
13955c4bab0fSBram Moolenaar	    return '.'
13965c4bab0fSBram Moolenaar	endfunc
13975c4bab0fSBram Moolenaar
13985c4bab0fSBram MoolenaarSee |:map-<expr>| for more info.
13995c4bab0fSBram Moolenaar
14001d2ba7faSBram Moolenaar
14011d2ba7faSBram MoolenaarFILETYPE-SPECIFIC REMARKS FOR OMNI COMPLETION	    *compl-omni-filetypes*
14021d2ba7faSBram Moolenaar
14031d2ba7faSBram MoolenaarThe file used for {filetype} should be autoload/{filetype}complete.vim
14041d2ba7faSBram Moolenaarin 'runtimepath'.  Thus for "java" it is autoload/javacomplete.vim.
1405578b49e4SBram Moolenaar
1406a5792f58SBram Moolenaar
1407f75a963eSBram MoolenaarC							*ft-c-omni*
1408578b49e4SBram Moolenaar
1409f75a963eSBram MoolenaarCompletion of C code requires a tags file.  You should use Exuberant ctags,
1410f75a963eSBram Moolenaarbecause it adds extra information that is needed for completion.  You can find
14119964e468SBram Moolenaarit here: http://ctags.sourceforge.net/  Version 5.6 or later is recommended.
14129964e468SBram Moolenaar
1413f75a963eSBram MoolenaarFor version 5.5.4 you should add a patch that adds the "typename:" field:
1414578b49e4SBram Moolenaar	ftp://ftp.vim.org/pub/vim/unstable/patches/ctags-5.5.4.patch
14158b6144bdSBram MoolenaarA compiled .exe for MS-Windows can be found at:
14162f058491SBram Moolenaar	http://ctags.sourceforge.net/
14172f058491SBram Moolenaar	https://github.com/universal-ctags/ctags-win32
1418578b49e4SBram Moolenaar
1419578b49e4SBram MoolenaarIf you want to complete system functions you can do something like this.  Use
1420578b49e4SBram Moolenaarctags to generate a tags file for all the system header files: >
1421578b49e4SBram Moolenaar	% ctags -R -f ~/.vim/systags /usr/include /usr/local/include
1422578b49e4SBram MoolenaarIn your vimrc file add this tags file to the 'tags' option: >
1423578b49e4SBram Moolenaar	set tags+=~/.vim/systags
1424578b49e4SBram Moolenaar
1425578b49e4SBram MoolenaarWhen using CTRL-X CTRL-O after a name without any "." or "->" it is completed
1426578b49e4SBram Moolenaarfrom the tags file directly.  This works for any identifier, also function
1427578b49e4SBram Moolenaarnames.  If you want to complete a local variable name, which does not appear
1428578b49e4SBram Moolenaarin the tags file, use CTRL-P instead.
1429578b49e4SBram Moolenaar
1430578b49e4SBram MoolenaarWhen using CTRL-X CTRL-O after something that has "." or "->" Vim will attempt
1431578b49e4SBram Moolenaarto recognize the type of the variable and figure out what members it has.
1432578b49e4SBram MoolenaarThis means only members valid for the variable will be listed.
1433578b49e4SBram Moolenaar
1434f75a963eSBram MoolenaarWhen a member name already was complete, CTRL-X CTRL-O will add a "." or
1435f75a963eSBram Moolenaar"->" for composite types.
1436f75a963eSBram Moolenaar
1437578b49e4SBram MoolenaarVim doesn't include a C compiler, only the most obviously formatted
1438578b49e4SBram Moolenaardeclarations are recognized.  Preprocessor stuff may cause confusion.
1439578b49e4SBram MoolenaarWhen the same structure name appears in multiple places all possible members
1440578b49e4SBram Moolenaarare included.
1441578b49e4SBram Moolenaar
14426b730e11SBram Moolenaar
1443a5792f58SBram MoolenaarCSS							*ft-css-omni*
1444a5792f58SBram Moolenaar
1445a5792f58SBram MoolenaarComplete properties and their appropriate values according to CSS 2.1
1446a5792f58SBram Moolenaarspecification.
1447a5792f58SBram Moolenaar
1448a5792f58SBram Moolenaar
1449e2f98b95SBram MoolenaarHTML							*ft-html-omni*
1450e2f98b95SBram MoolenaarXHTML							*ft-xhtml-omni*
14516b730e11SBram Moolenaar
14521d2ba7faSBram MoolenaarCTRL-X CTRL-O provides completion of various elements of (X)HTML files.  It is
1453db6ea063SBram Moolenaardesigned to support writing of XHTML 1.0 Strict files but will also work for
14541d2ba7faSBram Moolenaarother versions of HTML. Features:
14556b730e11SBram Moolenaar
14561d2ba7faSBram Moolenaar- after "<" complete tag name depending on context (no div suggestion inside
14571d2ba7faSBram Moolenaar  of an a tag); '/>' indicates empty tags
14581d2ba7faSBram Moolenaar- inside of tag complete proper attributes (no width attribute for an a tag);
14591d2ba7faSBram Moolenaar  show also type of attribute; '*' indicates required attributes
14601d2ba7faSBram Moolenaar- when attribute has limited number of possible values help to complete them
1461a5792f58SBram Moolenaar- complete names of entities
14621e015460SBram Moolenaar- complete values of "class" and "id" attributes with data obtained from
14631d2ba7faSBram Moolenaar  <style> tag and included CSS files
14648b6144bdSBram Moolenaar- when completing value of "style" attribute or working inside of "style" tag
14651e015460SBram Moolenaar  switch to |ft-css-omni| completion
14661d2ba7faSBram Moolenaar- when completing values of events attributes or working inside of "script"
14671d2ba7faSBram Moolenaar  tag switch to |ft-javascript-omni| completion
14681e015460SBram Moolenaar- when used after "</" CTRL-X CTRL-O will close the last opened tag
14696b730e11SBram Moolenaar
1470a5792f58SBram MoolenaarNote: When used first time completion menu will be shown with little delay
1471a5792f58SBram Moolenaar- this is time needed for loading of data file.
14728b6144bdSBram MoolenaarNote: Completion may fail in badly formatted documents. In such case try to
14738b6144bdSBram Moolenaarrun |:make| command to detect formatting problems.
1474a5792f58SBram Moolenaar
1475a5792f58SBram Moolenaar
1476c1e37901SBram MoolenaarHTML flavor						*html-flavor*
1477c1e37901SBram Moolenaar
14789c102387SBram MoolenaarThe default HTML completion depends on the filetype.  For HTML files it is
14799c102387SBram MoolenaarHTML 4.01 Transitional ('filetype' is "html"), for XHTML it is XHTML 1.0
14809c102387SBram MoolenaarStrict ('filetype' is "xhtml").
1481c1e37901SBram Moolenaar
14829c102387SBram MoolenaarWhen doing completion outside of any other tag you will have possibility to
14839c102387SBram Moolenaarchoose DOCTYPE and the appropriate data file will be loaded and used for all
14849c102387SBram Moolenaarnext completions.
1485c1e37901SBram Moolenaar
14869c102387SBram MoolenaarMore about format of data file in |xml-omni-datafile|. Some of the data files
14879c102387SBram Moolenaarmay be found on the Vim website (|www|).
1488c1e37901SBram Moolenaar
14899c102387SBram MoolenaarNote that b:html_omni_flavor may point to a file with any XML data.  This
14909c102387SBram Moolenaarmakes possible to mix PHP (|ft-php-omni|) completion with any XML dialect
14919c102387SBram Moolenaar(assuming you have data file for it).  Without setting that variable XHTML 1.0
14929c102387SBram MoolenaarStrict will be used.
1493c1e37901SBram Moolenaar
1494c1e37901SBram Moolenaar
1495b8a7b560SBram MoolenaarJAVASCRIPT					       *ft-javascript-omni*
1496b8a7b560SBram Moolenaar
14978b6144bdSBram MoolenaarCompletion of most elements of JavaScript language and DOM elements.
1498b8a7b560SBram Moolenaar
1499b8a7b560SBram MoolenaarComplete:
1500b8a7b560SBram Moolenaar
1501b8a7b560SBram Moolenaar- variables
15021d2ba7faSBram Moolenaar- function name; show function arguments
1503b8a7b560SBram Moolenaar- function arguments
1504b8a7b560SBram Moolenaar- properties of variables trying to detect type of variable
15058b6144bdSBram Moolenaar- complete DOM objects and properties depending on context
1506b8a7b560SBram Moolenaar- keywords of language
1507b8a7b560SBram Moolenaar
15088b6144bdSBram MoolenaarCompletion works in separate JavaScript files (&ft==javascript), inside of
15098b6144bdSBram Moolenaar<script> tag of (X)HTML and in values of event attributes (including scanning
15109ba7e17dSBram Moolenaarof external files).
1511b8a7b560SBram Moolenaar
1512b8a7b560SBram MoolenaarDOM compatibility
1513b8a7b560SBram Moolenaar
1514b8a7b560SBram MoolenaarAt the moment (beginning of 2006) there are two main browsers - MS Internet
1515b8a7b560SBram MoolenaarExplorer and Mozilla Firefox. These two applications are covering over 90% of
1516b8a7b560SBram Moolenaarmarket. Theoretically standards are created by W3C organisation
1517b8a7b560SBram Moolenaar(http://www.w3c.org) but they are not always followed/implemented.
1518b8a7b560SBram Moolenaar
1519b8a7b560SBram Moolenaar		IE	FF	W3C  Omni completion ~
1520b8a7b560SBram Moolenaar		+/-	+/-	+    +		     ~
1521b8a7b560SBram Moolenaar		+	+	-    +		     ~
1522b8a7b560SBram Moolenaar		+	-	-    -		     ~
1523b8a7b560SBram Moolenaar		-	+	-    -		     ~
1524b8a7b560SBram Moolenaar
1525b8a7b560SBram MoolenaarRegardless from state of implementation in browsers but if element is defined
1526b8a7b560SBram Moolenaarin standards, completion plugin will place element in suggestion list. When
1527b8a7b560SBram Moolenaarboth major engines implemented element, even if this is not in standards it
1528b8a7b560SBram Moolenaarwill be suggested. All other elements are not placed in suggestion list.
1529b8a7b560SBram Moolenaar
1530b8a7b560SBram Moolenaar
1531362e1a30SBram MoolenaarPHP							*ft-php-omni*
1532362e1a30SBram Moolenaar
15339964e468SBram MoolenaarCompletion of PHP code requires a tags file for completion of data from
15349964e468SBram Moolenaarexternal files and for class aware completion. You should use Exuberant ctags
15359964e468SBram Moolenaarversion 5.5.4 or newer. You can find it here: http://ctags.sourceforge.net/
1536362e1a30SBram Moolenaar
1537362e1a30SBram MoolenaarScript completes:
1538362e1a30SBram Moolenaar
1539362e1a30SBram Moolenaar- after $ variables name
15400b598c2fSBram Moolenaar  - if variable was declared as object add "->", if tags file is available show
15410b598c2fSBram Moolenaar    name of class
1542910f66f9SBram Moolenaar  - after "->" complete only function and variable names specific for given
1543910f66f9SBram Moolenaar    class. To find class location and contents tags file is required. Because
1544910f66f9SBram Moolenaar    PHP isn't strongly typed language user can use @var tag to declare class: >
1545910f66f9SBram Moolenaar
1546910f66f9SBram Moolenaar	/* @var $myVar myClass */
1547910f66f9SBram Moolenaar	$myVar->
1548910f66f9SBram Moolenaar<
1549910f66f9SBram Moolenaar    Still, to find myClass contents tags file is required.
15500b598c2fSBram Moolenaar
1551551dbcc9SBram Moolenaar- function names with additional info:
1552362e1a30SBram Moolenaar  - in case of built-in functions list of possible arguments and after | type
1553362e1a30SBram Moolenaar    data returned by function
155406b5d516SBram Moolenaar  - in case of user function arguments and name of file where function was
1555362e1a30SBram Moolenaar    defined (if it is not current file)
1556362e1a30SBram Moolenaar
15570b598c2fSBram Moolenaar- constants names
15580b598c2fSBram Moolenaar- class names after "new" declaration
15590b598c2fSBram Moolenaar
15600b598c2fSBram Moolenaar
1561362e1a30SBram MoolenaarNote: when doing completion first time Vim will load all necessary data into
1562362e1a30SBram Moolenaarmemory. It may take several seconds. After next use of completion delay
15630b598c2fSBram Moolenaarshould not be noticeable.
1564362e1a30SBram Moolenaar
1565362e1a30SBram MoolenaarScript detects if cursor is inside <?php ?> tags. If it is outside it will
1566362e1a30SBram Moolenaarautomatically switch to HTML/CSS/JavaScript completion. Note: contrary to
1567362e1a30SBram Moolenaaroriginal HTML files completion of tags (and only tags) isn't context aware.
1568362e1a30SBram Moolenaar
1569362e1a30SBram Moolenaar
1570fc1421ebSBram MoolenaarRUBY							*ft-ruby-omni*
1571fc1421ebSBram Moolenaar
1572fc1421ebSBram MoolenaarCompletion of Ruby code requires that vim be built with |+ruby|.
1573fc1421ebSBram Moolenaar
1574fc1421ebSBram MoolenaarRuby completion will parse your buffer on demand in order to provide a list of
1575fc1421ebSBram Moolenaarcompletions.  These completions will be drawn from modules loaded by 'require'
1576fc1421ebSBram Moolenaarand modules defined in the current buffer.
1577fc1421ebSBram Moolenaar
1578fc1421ebSBram MoolenaarThe completions provided by CTRL-X CTRL-O are sensitive to the context:
1579fc1421ebSBram Moolenaar
1580fc1421ebSBram Moolenaar	  CONTEXT			   COMPLETIONS PROVIDED ~
1581fc1421ebSBram Moolenaar
1582fc1421ebSBram Moolenaar 1. Not inside a class definition    Classes, constants and globals
1583fc1421ebSBram Moolenaar
1584fc1421ebSBram Moolenaar 2. Inside a class definition	     Methods or constants defined in the class
1585fc1421ebSBram Moolenaar
1586fc1421ebSBram Moolenaar 3. After '.', '::' or ':'	     Methods applicable to the object being
1587fc1421ebSBram Moolenaar				       dereferenced
1588fc1421ebSBram Moolenaar
1589fc1421ebSBram Moolenaar 4. After ':' or ':foo'		     Symbol name (beginning with 'foo')
1590fc1421ebSBram Moolenaar
1591fc1421ebSBram MoolenaarNotes:
1592fc1421ebSBram Moolenaar - Vim will load/evaluate code in order to provide completions.  This may
15939964e468SBram Moolenaar   cause some code execution, which may be a concern. This is no longer
15949964e468SBram Moolenaar   enabled by default, to enable this feature add >
15959964e468SBram Moolenaar     let g:rubycomplete_buffer_loading = 1
15969964e468SBram Moolenaar<- In context 1 above, Vim can parse the entire buffer to add a list of
1597551dbcc9SBram Moolenaar   classes to the completion results. This feature is turned off by default,
1598551dbcc9SBram Moolenaar   to enable it add >
1599551dbcc9SBram Moolenaar     let g:rubycomplete_classes_in_global = 1
1600551dbcc9SBram Moolenaar<  to your vimrc
1601fc1421ebSBram Moolenaar - In context 2 above, anonymous classes are not supported.
1602fc1421ebSBram Moolenaar - In context 3 above, Vim will attempt to determine the methods supported by
1603fc1421ebSBram Moolenaar   the object.
1604fc1421ebSBram Moolenaar - Vim can detect and load the Rails environment for files within a rails
1605fc1421ebSBram Moolenaar   project. The feature is disabled by default, to enable it add >
1606fc1421ebSBram Moolenaar     let g:rubycomplete_rails = 1
1607551dbcc9SBram Moolenaar<  to your vimrc
1608fc1421ebSBram Moolenaar
1609fc1421ebSBram Moolenaar
16104770d09aSBram MoolenaarSYNTAX							*ft-syntax-omni*
16114770d09aSBram Moolenaar
16129964e468SBram MoolenaarVim has the ability to color syntax highlight nearly 500 languages.  Part of
16139964e468SBram Moolenaarthis highlighting includes knowing what keywords are part of a language.  Many
16149964e468SBram Moolenaarfiletypes already have custom completion scripts written for them, the
16159964e468SBram Moolenaarsyntaxcomplete plugin provides basic completion for all other filetypes.  It
16169964e468SBram Moolenaardoes this by populating the omni completion list with the text Vim already
16179964e468SBram Moolenaarknows how to color highlight.  It can be used for any filetype and provides a
16189964e468SBram Moolenaarminimal language-sensitive completion.
16194770d09aSBram Moolenaar
1620c06ac340SBram MoolenaarTo enable syntax code completion you can run: >
1621c06ac340SBram Moolenaar    setlocal omnifunc=syntaxcomplete#Complete
16224770d09aSBram Moolenaar
1623ec7944aaSBram MoolenaarYou can automate this by placing the following in your |.vimrc| (after any
1624c06ac340SBram Moolenaar":filetype" command): >
1625c06ac340SBram Moolenaar    if has("autocmd") && exists("+omnifunc")
16264770d09aSBram Moolenaar	autocmd Filetype *
1627c06ac340SBram Moolenaar		    \	if &omnifunc == "" |
1628c06ac340SBram Moolenaar		    \		setlocal omnifunc=syntaxcomplete#Complete |
16294770d09aSBram Moolenaar		    \	endif
1630c06ac340SBram Moolenaar    endif
16314770d09aSBram Moolenaar
1632c06ac340SBram MoolenaarThe above will set completion to this script only if a specific plugin does
1633c06ac340SBram Moolenaarnot already exist for that filetype.
1634c06ac340SBram Moolenaar
1635c06ac340SBram MoolenaarEach filetype can have a wide range of syntax items.  The plugin allows you to
1636c06ac340SBram Moolenaarcustomize which syntax groups to include or exclude from the list.  Let's have
1637c06ac340SBram Moolenaara look at the PHP filetype to see how this works.
1638c06ac340SBram Moolenaar
1639c06ac340SBram MoolenaarIf you edit a file called, index.php, run the following command: >
1640ec7944aaSBram Moolenaar    syntax list
1641c06ac340SBram Moolenaar
164206b5d516SBram MoolenaarThe first thing you will notice is that there are many different syntax groups.
164306b5d516SBram MoolenaarThe PHP language can include elements from different languages like HTML,
1644c06ac340SBram MoolenaarJavaScript and many more.  The syntax plugin will only include syntax groups
1645c06ac340SBram Moolenaarthat begin with the filetype, "php", in this case.  For example these syntax
1646c06ac340SBram Moolenaargroups are included by default with the PHP: phpEnvVar, phpIntVar,
1647c06ac340SBram MoolenaarphpFunctions.
1648c06ac340SBram Moolenaar
1649ec7944aaSBram MoolenaarIf you wish non-filetype syntax items to also be included, you can use a
165040962ec9SBram Moolenaarregular expression syntax (added in version 13.0 of
16516dc819b1SBram Moolenaarautoload/syntaxcomplete.vim) to add items.  Looking at the output from
165240962ec9SBram Moolenaar":syntax list" while editing a PHP file I can see some of these entries: >
1653ec7944aaSBram Moolenaar    htmlArg,htmlTag,htmlTagName,javaScriptStatement,javaScriptGlobalObjects
1654c06ac340SBram Moolenaar
1655ec7944aaSBram MoolenaarTo pick up any JavaScript and HTML keyword syntax groups while editing a PHP
1656ec7944aaSBram Moolenaarfile, you can use 3 different regexs, one for each language.  Or you can
1657ec7944aaSBram Moolenaarsimply restrict the include groups to a particular value, without using
1658ec7944aaSBram Moolenaara regex string: >
1659ec7944aaSBram Moolenaar    let g:omni_syntax_group_include_php = 'php\w\+,javaScript\w\+,html\w\+'
1660ec7944aaSBram Moolenaar    let g:omni_syntax_group_include_php = 'phpFunctions,phpMethods'
1661ec7944aaSBram Moolenaar<
1662ec7944aaSBram MoolenaarThe basic form of this variable is: >
1663ec7944aaSBram Moolenaar    let g:omni_syntax_group_include_{filetype} = 'regex,comma,separated'
1664ec7944aaSBram Moolenaar
1665ec7944aaSBram MoolenaarThe PHP language has an enormous number of items which it knows how to syntax
16669ba7e17dSBram Moolenaarhighlight.  These items will be available within the omni completion list.
1667ec7944aaSBram Moolenaar
1668ec7944aaSBram MoolenaarSome people may find this list unwieldy or are only interested in certain
1669ec7944aaSBram Moolenaaritems.  There are two ways to prune this list (if necessary).  If you find
1670ec7944aaSBram Moolenaarcertain syntax groups you do not wish displayed you can use two different
1671ec7944aaSBram Moolenaarmethods to identify these groups.  The first specifically lists the syntax
1672ec7944aaSBram Moolenaargroups by name.  The second uses a regular expression to identify both
1673ec7944aaSBram Moolenaarsyntax groups.  Simply add one the following to your vimrc: >
1674c06ac340SBram Moolenaar    let g:omni_syntax_group_exclude_php = 'phpCoreConstant,phpConstant'
1675ec7944aaSBram Moolenaar    let g:omni_syntax_group_exclude_php = 'php\w*Constant'
1676c06ac340SBram Moolenaar
1677c06ac340SBram MoolenaarAdd as many syntax groups to this list by comma separating them.  The basic
1678c06ac340SBram Moolenaarform of this variable is: >
1679ec7944aaSBram Moolenaar    let g:omni_syntax_group_exclude_{filetype} = 'regex,comma,separated'
1680c06ac340SBram Moolenaar
1681c06ac340SBram MoolenaarYou can create as many of these variables as you need, varying only the
1682c06ac340SBram Moolenaarfiletype at the end of the variable name.
16834770d09aSBram Moolenaar
16849964e468SBram MoolenaarThe plugin uses the isKeyword option to determine where word boundaries are
16859964e468SBram Moolenaarfor the syntax items.  For example, in the Scheme language completion should
16869964e468SBram Moolenaarinclude the "-", call-with-output-file.  Depending on your filetype, this may
16879964e468SBram Moolenaarnot provide the words you are expecting.  Setting the
16889964e468SBram Moolenaarg:omni_syntax_use_iskeyword option to 0 will force the syntax plugin to break
16899964e468SBram Moolenaaron word characters.   This can be controlled adding the following to your
16909964e468SBram Moolenaarvimrc: >
16919964e468SBram Moolenaar    let g:omni_syntax_use_iskeyword = 0
16929964e468SBram Moolenaar
16938b68277fSBram MoolenaarFor plugin developers, the plugin exposes a public function OmniSyntaxList.
16948b68277fSBram MoolenaarThis function can be used to request a List of syntax items.  When editing a
16958b68277fSBram MoolenaarSQL file (:e syntax.sql) you can use the ":syntax list" command to see the
16968b68277fSBram Moolenaarvarious groups and syntax items.  For example: >
16978b68277fSBram Moolenaar    syntax list
16988b68277fSBram Moolenaar
169940962ec9SBram MoolenaarYields data similar to this:
170040962ec9SBram Moolenaar    sqlOperator    xxx some prior all like and any escape exists in is not ~
170140962ec9SBram Moolenaar                       or intersect minus between distinct ~
170240962ec9SBram Moolenaar                       links to Operator ~
170340962ec9SBram Moolenaar    sqlType        xxx varbit varchar nvarchar bigint int uniqueidentifier ~
170440962ec9SBram Moolenaar                       date money long tinyint unsigned xml text smalldate ~
170540962ec9SBram Moolenaar                       double datetime nchar smallint numeric time bit char ~
170640962ec9SBram Moolenaar                       varbinary binary smallmoney ~
170740962ec9SBram Moolenaar                       image float integer timestamp real decimal ~
17088b68277fSBram Moolenaar
17098b68277fSBram MoolenaarThere are two syntax groups listed here: sqlOperator and sqlType.  To retrieve
17108b68277fSBram Moolenaara List of syntax items you can call OmniSyntaxList a number of different
17118b68277fSBram Moolenaarways.  To retrieve all syntax items regardless of syntax group:  >
17128b68277fSBram Moolenaar    echo OmniSyntaxList( [] )
17138b68277fSBram Moolenaar
17148b68277fSBram MoolenaarTo retrieve only the syntax items for the sqlOperator syntax group: >
17158b68277fSBram Moolenaar    echo OmniSyntaxList( ['sqlOperator'] )
17168b68277fSBram Moolenaar
17178b68277fSBram MoolenaarTo retrieve all syntax items for both the sqlOperator and sqlType groups: >
17188b68277fSBram Moolenaar    echo OmniSyntaxList( ['sqlOperator', 'sqlType'] )
17198b68277fSBram Moolenaar
1720ec7944aaSBram MoolenaarA regular expression can also be used: >
1721ec7944aaSBram Moolenaar    echo OmniSyntaxList( ['sql\w\+'] )
1722ec7944aaSBram Moolenaar
17238b68277fSBram MoolenaarFrom within a plugin, you would typically assign the output to a List: >
17248b68277fSBram Moolenaar    let myKeywords = []
17258b68277fSBram Moolenaar    let myKeywords = OmniSyntaxList( ['sqlKeyword'] )
17268b68277fSBram Moolenaar
17278b68277fSBram Moolenaar
1728e2f98b95SBram MoolenaarSQL							*ft-sql-omni*
1729e2f98b95SBram Moolenaar
1730e2f98b95SBram MoolenaarCompletion for the SQL language includes statements, functions, keywords.
1731e2f98b95SBram MoolenaarIt will also dynamically complete tables, procedures, views and column lists
1732e2f98b95SBram Moolenaarwith data pulled directly from within a database.  For detailed instructions
1733e2f98b95SBram Moolenaarand a tutorial see |omni-sql-completion|.
1734e2f98b95SBram Moolenaar
1735910f66f9SBram MoolenaarThe SQL completion plugin can be used in conjunction with other completion
17368f3f58f2SBram Moolenaarplugins.  For example, the PHP filetype has its own completion plugin.
1737910f66f9SBram MoolenaarSince PHP is often used to generate dynamic website by accessing a database,
1738910f66f9SBram Moolenaarthe SQL completion plugin can also be enabled.  This allows you to complete
1739910f66f9SBram MoolenaarPHP code and SQL code at the same time.
1740910f66f9SBram Moolenaar
1741e2f98b95SBram Moolenaar
1742a5792f58SBram MoolenaarXML							*ft-xml-omni*
1743a5792f58SBram Moolenaar
17449c102387SBram MoolenaarVim 7 provides a mechanism for context aware completion of XML files.  It
17459c102387SBram Moolenaardepends on a special |xml-omni-datafile| and two commands: |:XMLns| and
17469c102387SBram Moolenaar|:XMLent|.  Features are:
1747a5792f58SBram Moolenaar
17489c102387SBram Moolenaar- after "<" complete the tag name, depending on context
17499c102387SBram Moolenaar- inside of a tag complete proper attributes
17509c102387SBram Moolenaar- when an attribute has a limited number of possible values help to complete
1751a5792f58SBram Moolenaar  them
17529c102387SBram Moolenaar- complete names of entities (defined in |xml-omni-datafile| and in the
17539c102387SBram Moolenaar  current file with "<!ENTITY" declarations)
1754a5792f58SBram Moolenaar- when used after "</" CTRL-X CTRL-O will close the last opened tag
1755a5792f58SBram Moolenaar
1756a5792f58SBram MoolenaarFormat of XML data file					*xml-omni-datafile*
1757a5792f58SBram Moolenaar
17589c102387SBram MoolenaarXML data files are stored in the "autoload/xml" directory in 'runtimepath'.
17599c102387SBram MoolenaarVim distribution provides examples of data files in the
17609c102387SBram Moolenaar"$VIMRUNTIME/autoload/xml" directory.  They have a meaningful name which will
17619c102387SBram Moolenaarbe used in commands.  It should be a unique name which will not create
17629c102387SBram Moolenaarconflicts.  For example, the name xhtml10s.vim means it is the data file for
17639c102387SBram MoolenaarXHTML 1.0 Strict.
1764a5792f58SBram Moolenaar
17659c102387SBram MoolenaarEach file contains a variable with a name like g:xmldata_xhtml10s . It is
17669c102387SBram Moolenaara compound from two parts:
1767a5792f58SBram Moolenaar
17689c102387SBram Moolenaar1. "g:xmldata_"  general prefix, constant for all data files
17699c102387SBram Moolenaar2. "xhtml10s"    the name of the file and the name of the described XML
17709c102387SBram Moolenaar		 dialect; it will be used as an argument for the |:XMLns|
17719c102387SBram Moolenaar		 command
1772a5792f58SBram Moolenaar
1773a5792f58SBram MoolenaarPart two must be exactly the same as name of file.
1774a5792f58SBram Moolenaar
17759c102387SBram MoolenaarThe variable is a |Dictionary|.  Keys are tag names and each value is a two
17769c102387SBram Moolenaarelement |List|.  The first element of the List is also a List with the names
17779c102387SBram Moolenaarof possible children.  The second element is a |Dictionary| with the names of
17789c102387SBram Moolenaarattributes as keys and the possible values of attributes as values.  Example: >
1779a5792f58SBram Moolenaar
17809c102387SBram Moolenaar    let g:xmldata_crippled = {
17819c102387SBram Moolenaar    \ "vimxmlentities": ["amp", "lt", "gt", "apos", "quot"],
17829c102387SBram Moolenaar    \ 'vimxmlroot': ['tag1'],
17839c102387SBram Moolenaar    \ 'tag1':
17849c102387SBram Moolenaar    \ [ ['childoftag1a', 'childoftag1b'], {'attroftag1a': [],
17859c102387SBram Moolenaar    \ 'attroftag1b': ['valueofattr1', 'valueofattr2']}],
17869c102387SBram Moolenaar    \ 'childoftag1a':
17879c102387SBram Moolenaar    \ [ [], {'attrofchild': ['attrofchild']}],
17889c102387SBram Moolenaar    \ 'childoftag1b':
17899c102387SBram Moolenaar    \ [ ['childoftag1a'], {'attrofchild': []}],
17901d2ba7faSBram Moolenaar    \ "vimxmltaginfo": {
17919c102387SBram Moolenaar    \ 'tag1': ['Menu info', 'Long information visible in preview window']},
17929c102387SBram Moolenaar    \ 'vimxmlattrinfo': {
17939c102387SBram Moolenaar    \ 'attrofchild': ['Menu info', 'Long information visible in preview window']}}
1794a5792f58SBram Moolenaar
17959c102387SBram MoolenaarThis example would be put in the "autoload/xml/crippled.vim" file and could
17969c102387SBram Moolenaarhelp to write this file: >
1797a5792f58SBram Moolenaar
17989c102387SBram Moolenaar    <tag1 attroftag1b="valueofattr1">
17999c102387SBram Moolenaar        <childoftag1a attrofchild>
18009c102387SBram Moolenaar                &amp; &lt;
18019c102387SBram Moolenaar        </childoftag1a>
18029c102387SBram Moolenaar        <childoftag1b attrofchild="5">
18039c102387SBram Moolenaar            <childoftag1a>
18049c102387SBram Moolenaar                &gt; &apos; &quot;
18059c102387SBram Moolenaar            </childoftag1a>
18069c102387SBram Moolenaar        </childoftag1b>
18079c102387SBram Moolenaar    </tag1>
1808a5792f58SBram Moolenaar
18099c102387SBram MoolenaarIn the example four special elements are visible:
18109c102387SBram Moolenaar
18119c102387SBram Moolenaar1. "vimxmlentities" - a special key with List containing entities of this XML
1812a5792f58SBram Moolenaar   dialect.
18139c102387SBram Moolenaar2. If the list containing possible values of attributes has one element and
18149c102387SBram Moolenaar   this element is equal to the name of the attribute this attribute will be
18159c102387SBram Moolenaar   treated as boolean and inserted as 'attrname' and not as 'attrname="'
18169c102387SBram Moolenaar3. "vimxmltaginfo" - a special key with a Dictionary containing tag
18179c102387SBram Moolenaar   names as keys and two element List as values, for additional menu info and
18189c102387SBram Moolenaar   the long description.
18199c102387SBram Moolenaar4. "vimxmlattrinfo" - special key with Dictionary containing attribute names
18209c102387SBram Moolenaar   as keys and two element List as values, for additional menu info and long
18211d2ba7faSBram Moolenaar   description.
1822a5792f58SBram Moolenaar
18239c102387SBram MoolenaarNote: Tag names in the data file MUST not contain a namespace description.
18249c102387SBram MoolenaarCheck xsl.vim for an example.
18259c102387SBram MoolenaarNote: All data and functions are publicly available as global
18269c102387SBram Moolenaarvariables/functions and can be used for personal editing functions.
1827a5792f58SBram Moolenaar
18281d2ba7faSBram Moolenaar
1829c1e37901SBram MoolenaarDTD -> Vim							*dtd2vim*
1830c1e37901SBram Moolenaar
18319c102387SBram MoolenaarOn |www| is the script |dtd2vim| which parses DTD and creates an XML data file
1832c1e37901SBram Moolenaarfor Vim XML omni completion.
1833c1e37901SBram Moolenaar
1834c1e37901SBram Moolenaar    dtd2vim: http://www.vim.org/scripts/script.php?script_id=1462
1835c1e37901SBram Moolenaar
18369c102387SBram MoolenaarCheck the beginning of that file for usage details.
18379c102387SBram MoolenaarThe script requires perl and:
1838c1e37901SBram Moolenaar
1839c1e37901SBram Moolenaar    perlSGML: http://savannah.nongnu.org/projects/perlsgml
1840c1e37901SBram Moolenaar
1841c1e37901SBram Moolenaar
1842a5792f58SBram MoolenaarCommands
1843a5792f58SBram Moolenaar
1844a5792f58SBram Moolenaar:XMLns {name} [{namespace}]					*:XMLns*
1845a5792f58SBram Moolenaar
1846a5792f58SBram MoolenaarVim has to know which data file should be used and with which namespace.  For
18479c102387SBram Moolenaarloading of the data file and connecting data with the proper namespace use
18489c102387SBram Moolenaar|:XMLns| command.  The first (obligatory) argument is the name of the data
18499c102387SBram Moolenaar(xhtml10s, xsl).  The second argument is the code of namespace (h, xsl).  When
18509c102387SBram Moolenaarused without a second argument the dialect will be used as default - without
18519c102387SBram Moolenaarnamespace declaration.  For example to use XML completion in .xsl files: >
1852a5792f58SBram Moolenaar
1853a5792f58SBram Moolenaar	:XMLns xhtml10s
1854a5792f58SBram Moolenaar	:XMLns xsl xsl
1855a5792f58SBram Moolenaar
1856a5792f58SBram Moolenaar
1857a5792f58SBram Moolenaar:XMLent {name}							*:XMLent*
1858a5792f58SBram Moolenaar
18599c102387SBram MoolenaarBy default entities will be completed from the data file of the default
18609c102387SBram Moolenaarnamespace.  The XMLent command should be used in case when there is no default
18619c102387SBram Moolenaarnamespace: >
1862a5792f58SBram Moolenaar
1863a5792f58SBram Moolenaar	:XMLent xhtml10s
1864a5792f58SBram Moolenaar
1865a5792f58SBram MoolenaarUsage
1866a5792f58SBram Moolenaar
18679c102387SBram MoolenaarWhile used in this situation (after declarations from previous part, | is
1868a5792f58SBram Moolenaarcursor position): >
1869a5792f58SBram Moolenaar
1870a5792f58SBram Moolenaar	<|
1871a5792f58SBram Moolenaar
18729c102387SBram MoolenaarWill complete to an appropriate XHTML tag, and in this situation: >
1873a5792f58SBram Moolenaar
1874a5792f58SBram Moolenaar	<xsl:|
1875a5792f58SBram Moolenaar
18769c102387SBram MoolenaarWill complete to an appropriate XSL tag.
1877a5792f58SBram Moolenaar
18789c102387SBram Moolenaar
18799c102387SBram MoolenaarThe script xmlcomplete.vim, provided through the |autoload| mechanism,
18809c102387SBram Moolenaarhas the xmlcomplete#GetLastOpenTag() function which can be used in XML files
18819c102387SBram Moolenaarto get the name of the last open tag (b:unaryTagsStack has to be defined): >
18826b730e11SBram Moolenaar
1883a5792f58SBram Moolenaar	:echo xmlcomplete#GetLastOpenTag("b:unaryTagsStack")
1884bfd8fc05SBram Moolenaar
18856b730e11SBram Moolenaar
18861e015460SBram Moolenaar
1887071d4279SBram Moolenaar==============================================================================
1888071d4279SBram Moolenaar8. Insert mode commands					*inserting*
1889071d4279SBram Moolenaar
1890071d4279SBram MoolenaarThe following commands can be used to insert new text into the buffer.  They
1891071d4279SBram Moolenaarcan all be undone and repeated with the "." command.
1892071d4279SBram Moolenaar
1893071d4279SBram Moolenaar							*a*
1894071d4279SBram Moolenaara			Append text after the cursor [count] times.  If the
1895071d4279SBram Moolenaar			cursor is in the first column of an empty line Insert
1896071d4279SBram Moolenaar			starts there.  But not when 'virtualedit' is set!
1897071d4279SBram Moolenaar
1898071d4279SBram Moolenaar							*A*
1899071d4279SBram MoolenaarA			Append text at the end of the line [count] times.
19001d59aa1fSBram Moolenaar			For using "A" in Visual block mode see |v_b_A|.
1901071d4279SBram Moolenaar
1902071d4279SBram Moolenaar<insert>	or				*i* *insert* *<Insert>*
1903071d4279SBram Moolenaari			Insert text before the cursor [count] times.
1904071d4279SBram Moolenaar			When using CTRL-O in Insert mode |i_CTRL-O| the count
1905071d4279SBram Moolenaar			is not supported.
1906071d4279SBram Moolenaar
1907071d4279SBram Moolenaar							*I*
1908071d4279SBram MoolenaarI			Insert text before the first non-blank in the line
1909071d4279SBram Moolenaar			[count] times.
19104399ef47SBram Moolenaar			When the 'H' flag is present in 'cpoptions' and the
19114399ef47SBram Moolenaar			line only contains blanks, insert start just before
19124399ef47SBram Moolenaar			the last blank.
19131d59aa1fSBram Moolenaar			For using "I" in Visual block mode see |v_b_I|.
1914071d4279SBram Moolenaar
1915071d4279SBram Moolenaar							*gI*
191625c9c680SBram MoolenaargI			Insert text in column 1 [count] times.
1917071d4279SBram Moolenaar
1918071d4279SBram Moolenaar							*gi*
1919071d4279SBram Moolenaargi			Insert text in the same position as where Insert mode
1920071d4279SBram Moolenaar			was stopped last time in the current buffer.
1921071d4279SBram Moolenaar			This uses the |'^| mark.  It's different from "`^i"
1922071d4279SBram Moolenaar			when the mark is past the end of the line.
1923071d4279SBram Moolenaar			The position is corrected for inserted/deleted lines,
1924071d4279SBram Moolenaar			but NOT for inserted/deleted characters.
1925071d4279SBram Moolenaar			When the |:keepjumps| command modifier is used the |'^|
192669a7cb47SBram Moolenaar			mark won't be changed.
1927071d4279SBram Moolenaar
1928071d4279SBram Moolenaar							*o*
1929071d4279SBram Moolenaaro			Begin a new line below the cursor and insert text,
1930a6c27c47SBram Moolenaar			repeat [count] times.
19314399ef47SBram Moolenaar			When the '#' flag is in 'cpoptions' the count is
19324399ef47SBram Moolenaar			ignored.
1933071d4279SBram Moolenaar
1934071d4279SBram Moolenaar							*O*
1935071d4279SBram MoolenaarO			Begin a new line above the cursor and insert text,
1936a6c27c47SBram Moolenaar			repeat [count] times.
19374399ef47SBram Moolenaar			When the '#' flag is in 'cpoptions' the count is
19384399ef47SBram Moolenaar			ignored.
1939071d4279SBram Moolenaar
1940071d4279SBram MoolenaarThese commands are used to start inserting text.  You can end insert mode with
1941071d4279SBram Moolenaar<Esc>.  See |mode-ins-repl| for the other special characters in Insert mode.
1942071d4279SBram MoolenaarThe effect of [count] takes place after Insert mode is exited.
1943071d4279SBram Moolenaar
1944071d4279SBram MoolenaarWhen 'autoindent' is on, the indent for a new line is obtained from the
1945071d4279SBram Moolenaarprevious line.  When 'smartindent' or 'cindent' is on, the indent for a line
1946071d4279SBram Moolenaaris automatically adjusted for C programs.
1947071d4279SBram Moolenaar
1948071d4279SBram Moolenaar'textwidth' can be set to the maximum width for a line.  When a line becomes
1949071d4279SBram Moolenaartoo long when appending characters a line break is automatically inserted.
1950071d4279SBram Moolenaar
1951071d4279SBram Moolenaar
1952071d4279SBram Moolenaar==============================================================================
1953071d4279SBram Moolenaar9. Ex insert commands					*inserting-ex*
1954071d4279SBram Moolenaar
1955071d4279SBram Moolenaar							*:a* *:append*
1956df177f67SBram Moolenaar:{range}a[ppend][!]	Insert several lines of text below the specified
1957071d4279SBram Moolenaar			line.  If the {range} is missing, the text will be
1958071d4279SBram Moolenaar			inserted after the current line.
1959df177f67SBram Moolenaar			Adding [!] toggles 'autoindent' for the time this
1960df177f67SBram Moolenaar			command is executed.
1961071d4279SBram Moolenaar
1962071d4279SBram Moolenaar							*:i* *:in* *:insert*
1963df177f67SBram Moolenaar:{range}i[nsert][!]	Insert several lines of text above the specified
1964071d4279SBram Moolenaar			line.  If the {range} is missing, the text will be
1965071d4279SBram Moolenaar			inserted before the current line.
1966df177f67SBram Moolenaar			Adding [!] toggles 'autoindent' for the time this
1967df177f67SBram Moolenaar			command is executed.
1968071d4279SBram Moolenaar
1969071d4279SBram MoolenaarThese two commands will keep on asking for lines, until you type a line
1970071d4279SBram Moolenaarcontaining only a ".".  Watch out for lines starting with a backslash, see
1971071d4279SBram Moolenaar|line-continuation|.
19728f3f58f2SBram Moolenaar
19734a74803eSBram MoolenaarWhen in Ex mode (see |-e|) a backslash at the end of the line can be used to
19744a74803eSBram Moolenaarinsert a NUL character.  To be able to have a line ending in a backslash use
19754a74803eSBram Moolenaartwo backslashes.  This means that the number of backslashes is halved, but
19764a74803eSBram Moolenaaronly at the end of the line.
19774a74803eSBram Moolenaar
19788f3f58f2SBram MoolenaarNOTE: These commands cannot be used with |:global| or |:vglobal|.
19798f3f58f2SBram Moolenaar":append" and ":insert" don't work properly in between ":if" and
198006fb435aSBram Moolenaar":endif", ":for" and ":endfor", ":while" and ":endwhile".
1981071d4279SBram Moolenaar
1982071d4279SBram Moolenaar							*:start* *:startinsert*
1983071d4279SBram Moolenaar:star[tinsert][!]	Start Insert mode just after executing this command.
1984071d4279SBram Moolenaar			Works like typing "i" in Normal mode.  When the ! is
1985071d4279SBram Moolenaar			included it works like "A", append to the line.
1986071d4279SBram Moolenaar			Otherwise insertion starts at the cursor position.
1987071d4279SBram Moolenaar			Note that when using this command in a function or
1988071d4279SBram Moolenaar			script, the insertion only starts after the function
1989071d4279SBram Moolenaar			or script is finished.
199087e25fdfSBram Moolenaar			This command does not work from |:normal|.
1991071d4279SBram Moolenaar
1992071d4279SBram Moolenaar							*:stopi* *:stopinsert*
1993071d4279SBram Moolenaar:stopi[nsert]		Stop Insert mode as soon as possible.  Works like
1994071d4279SBram Moolenaar			typing <Esc> in Insert mode.
1995071d4279SBram Moolenaar			Can be used in an autocommand, example: >
1996071d4279SBram Moolenaar				:au BufEnter scratch stopinsert
1997325b7a2fSBram Moolenaar<
1998325b7a2fSBram Moolenaar					*replacing-ex* *:startreplace*
1999325b7a2fSBram Moolenaar:startr[eplace][!]	Start Replace mode just after executing this command.
2000325b7a2fSBram Moolenaar			Works just like typing "R" in Normal mode.  When the
2001325b7a2fSBram Moolenaar			! is included it acts just like "$R" had been typed
2002325b7a2fSBram Moolenaar			(ie. begin replace mode at the end-of-line).  Other-
2003325b7a2fSBram Moolenaar			wise replacement begins at the cursor position.
2004325b7a2fSBram Moolenaar			Note that when using this command in a function or
2005325b7a2fSBram Moolenaar			script that the replacement will only start after
2006325b7a2fSBram Moolenaar			the function or script is finished.
2007071d4279SBram Moolenaar
200861da4986SBram Moolenaar							*:startgreplace*
200961da4986SBram Moolenaar:startg[replace][!]	Just like |:startreplace|, but use Virtual Replace
201061da4986SBram Moolenaar			mode, like with |gR|.
201161da4986SBram Moolenaar
2012071d4279SBram Moolenaar==============================================================================
2013071d4279SBram Moolenaar10. Inserting a file					*inserting-file*
2014071d4279SBram Moolenaar
2015071d4279SBram Moolenaar							*:r* *:re* *:read*
2016910f66f9SBram Moolenaar:r[ead] [++opt] [name]
2017910f66f9SBram Moolenaar			Insert the file [name] (default: current file) below
2018071d4279SBram Moolenaar			the cursor.
2019910f66f9SBram Moolenaar			See |++opt| for the possible values of [++opt].
2020071d4279SBram Moolenaar
2021910f66f9SBram Moolenaar:{range}r[ead] [++opt] [name]
2022910f66f9SBram Moolenaar			Insert the file [name] (default: current file) below
2023071d4279SBram Moolenaar			the specified line.
2024910f66f9SBram Moolenaar			See |++opt| for the possible values of [++opt].
2025071d4279SBram Moolenaar
2026071d4279SBram Moolenaar							*:r!* *:read!*
20270187ca0bSBram Moolenaar:[range]r[ead] [++opt] !{cmd}
20280187ca0bSBram Moolenaar			Execute {cmd} and insert its standard output below
20299964e468SBram Moolenaar			the cursor or the specified line.  A temporary file is
20309964e468SBram Moolenaar			used to store the output of the command which is then
20319964e468SBram Moolenaar			read into the buffer.  'shellredir' is used to save
20329964e468SBram Moolenaar			the output of the command, which can be set to include
20339964e468SBram Moolenaar			stderr or not.  {cmd} is executed like with ":!{cmd}",
20349964e468SBram Moolenaar			any '!' is replaced with the previous command |:!|.
20350187ca0bSBram Moolenaar			See |++opt| for the possible values of [++opt].
2036071d4279SBram Moolenaar
2037071d4279SBram MoolenaarThese commands insert the contents of a file, or the output of a command,
2038071d4279SBram Moolenaarinto the buffer.  They can be undone.  They cannot be repeated with the "."
2039071d4279SBram Moolenaarcommand.  They work on a line basis, insertion starts below the line in which
2040071d4279SBram Moolenaarthe cursor is, or below the specified line.  To insert text above the first
2041071d4279SBram Moolenaarline use the command ":0r {name}".
2042071d4279SBram Moolenaar
2043071d4279SBram MoolenaarAfter the ":read" command, the cursor is left on the first non-blank in the
2044071d4279SBram Moolenaarfirst new line.  Unless in Ex mode, then the cursor is left on the last new
2045071d4279SBram Moolenaarline (sorry, this is Vi compatible).
2046071d4279SBram Moolenaar
2047071d4279SBram MoolenaarIf a file name is given with ":r", it becomes the alternate file.  This can be
2048071d4279SBram Moolenaarused, for example, when you want to edit that file instead: ":e! #".  This can
2049071d4279SBram Moolenaarbe switched off by removing the 'a' flag from the 'cpoptions' option.
2050071d4279SBram Moolenaar
2051910f66f9SBram MoolenaarOf the [++opt] arguments one is specifically for ":read", the ++edit argument.
2052910f66f9SBram MoolenaarThis is useful when the ":read" command is actually used to read a file into
2053910f66f9SBram Moolenaarthe buffer as if editing that file.  Use this command in an empty buffer: >
2054910f66f9SBram Moolenaar	:read ++edit filename
2055910f66f9SBram MoolenaarThe effect is that the 'fileformat', 'fileencoding', 'bomb', etc. options are
2056910f66f9SBram Moolenaarset to what has been detected for "filename".  Note that a single empty line
2057910f66f9SBram Moolenaarremains, you may want to delete it.
2058910f66f9SBram Moolenaar
2059071d4279SBram Moolenaar							*file-read*
2060071d4279SBram MoolenaarThe 'fileformat' option sets the <EOL> style for a file:
2061071d4279SBram Moolenaar'fileformat'    characters	   name				~
2062071d4279SBram Moolenaar  "dos"		<CR><NL> or <NL>   DOS format
2063071d4279SBram Moolenaar  "unix"	<NL>		   Unix format
2064071d4279SBram Moolenaar  "mac"		<CR>		   Mac format
2065071d4279SBram MoolenaarPreviously 'textmode' was used.  It is obsolete now.
2066071d4279SBram Moolenaar
2067071d4279SBram MoolenaarIf 'fileformat' is "dos", a <CR> in front of an <NL> is ignored and a CTRL-Z
2068071d4279SBram Moolenaarat the end of the file is ignored.
2069071d4279SBram Moolenaar
2070071d4279SBram MoolenaarIf 'fileformat' is "mac", a <NL> in the file is internally represented by a
2071071d4279SBram Moolenaar<CR>.  This is to avoid confusion with a <NL> which is used to represent a
2072071d4279SBram Moolenaar<NUL>.  See |CR-used-for-NL|.
2073071d4279SBram Moolenaar
2074071d4279SBram MoolenaarIf the 'fileformats' option is not empty Vim tries to recognize the type of
2075071d4279SBram Moolenaar<EOL> (see |file-formats|).  However, the 'fileformat' option will not be
2076071d4279SBram Moolenaarchanged, the detected format is only used while reading the file.
2077071d4279SBram MoolenaarA similar thing happens with 'fileencodings'.
2078071d4279SBram Moolenaar
20798024f936SBram MoolenaarOn non-Win32 systems the message "[dos format]" is shown if a file is read in
20808024f936SBram MoolenaarDOS format, to remind you that something unusual is done.
20815666fcd0SBram MoolenaarOn Macintosh and Win32 the message "[unix format]" is shown if a file is read
20825666fcd0SBram Moolenaarin Unix format.
20838024f936SBram MoolenaarOn non-Macintosh systems, the message "[mac format]" is shown if a file is
2084071d4279SBram Moolenaarread in Mac format.
2085071d4279SBram Moolenaar
2086071d4279SBram MoolenaarAn example on how to use ":r !": >
2087071d4279SBram Moolenaar	:r !uuencode binfile binfile
2088071d4279SBram MoolenaarThis command reads "binfile", uuencodes it and reads it into the current
2089071d4279SBram Moolenaarbuffer.  Useful when you are editing e-mail and want to include a binary
2090071d4279SBram Moolenaarfile.
2091071d4279SBram Moolenaar
2092071d4279SBram Moolenaar							*read-messages*
2093071d4279SBram MoolenaarWhen reading a file Vim will display a message with information about the read
2094071d4279SBram Moolenaarfile.  In the table is an explanation for some of the items.  The others are
2095071d4279SBram Moolenaarself explanatory.  Using the long or the short version depends on the
2096071d4279SBram Moolenaar'shortmess' option.
2097071d4279SBram Moolenaar
2098071d4279SBram Moolenaar	long		short		meaning ~
2099071d4279SBram Moolenaar	[readonly]	{RO}		the file is write protected
2100071d4279SBram Moolenaar	[fifo/socket]			using a stream
2101071d4279SBram Moolenaar	[fifo]				using a fifo stream
2102071d4279SBram Moolenaar	[socket]			using a socket stream
2103071d4279SBram Moolenaar	[CR missing]			reading with "dos" 'fileformat' and a
2104071d4279SBram Moolenaar					NL without a preceding CR was found.
2105071d4279SBram Moolenaar	[NL found]			reading with "mac" 'fileformat' and a
2106071d4279SBram Moolenaar					NL was found (could be "unix" format)
2107071d4279SBram Moolenaar	[long lines split]		at least one line was split in two
2108071d4279SBram Moolenaar	[NOT converted]			conversion from 'fileencoding' to
2109071d4279SBram Moolenaar					'encoding' was desired but not
2110071d4279SBram Moolenaar					possible
2111071d4279SBram Moolenaar	[converted]			conversion from 'fileencoding' to
2112071d4279SBram Moolenaar					'encoding' done
2113071d4279SBram Moolenaar	[crypted]			file was decrypted
2114071d4279SBram Moolenaar	[READ ERRORS]			not all of the file could be read
2115071d4279SBram Moolenaar
2116071d4279SBram Moolenaar
211791f84f6eSBram Moolenaar vim:tw=78:ts=8:noet:ft=help:norl:
2118