insert.txt 84 KB

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