insert.txt 86 KB

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