cmdline.txt 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. *cmdline.txt* For Vim version 9.0. Last change: 2022 Nov 11
  2. VIM REFERENCE MANUAL by Bram Moolenaar
  3. *Cmdline-mode* *Command-line-mode*
  4. Command-line mode *Cmdline* *Command-line* *mode-cmdline* *:*
  5. Command-line mode is used to enter Ex commands (":"), search patterns
  6. ("/" and "?"), and filter commands ("!").
  7. Basic command line editing is explained in chapter 20 of the user manual
  8. |usr_20.txt|.
  9. 1. Command-line editing |cmdline-editing|
  10. 2. Command-line completion |cmdline-completion|
  11. 3. Ex command-lines |cmdline-lines|
  12. 4. Ex command-line ranges |cmdline-ranges|
  13. 5. Ex command-line flags |ex-flags|
  14. 6. Ex special characters |cmdline-special|
  15. 7. Command-line window |cmdline-window|
  16. ==============================================================================
  17. 1. Command-line editing *cmdline-editing*
  18. Normally characters are inserted in front of the cursor position. You can
  19. move around in the command-line with the left and right cursor keys. With the
  20. <Insert> key, you can toggle between inserting and overstriking characters.
  21. Note that if your keyboard does not have working cursor keys or any of the
  22. other special keys, you can use ":cnoremap" to define another key for them.
  23. For example, to define tcsh style editing keys: *tcsh-style* >
  24. :cnoremap <C-A> <Home>
  25. :cnoremap <C-F> <Right>
  26. :cnoremap <C-B> <Left>
  27. :cnoremap <Esc>b <S-Left>
  28. :cnoremap <Esc>f <S-Right>
  29. (<> notation |<>|; type all this literally)
  30. *cmdline-too-long*
  31. When the command line is getting longer than what fits on the screen, only the
  32. part that fits will be shown. The cursor can only move in this visible part,
  33. thus you cannot edit beyond that.
  34. *cmdline-history* *history*
  35. The command-lines that you enter are remembered in a history table. You can
  36. recall them with the up and down cursor keys. There are actually five
  37. history tables:
  38. - one for ':' commands
  39. - one for search strings
  40. - one for expressions
  41. - one for input lines, typed for the |input()| function.
  42. - one for debug mode commands
  43. These are completely separate. Each history can only be accessed when
  44. entering the same type of line.
  45. Use the 'history' option to set the number of lines that are remembered
  46. (default: 50).
  47. Notes:
  48. - When you enter a command-line that is exactly the same as an older one, the
  49. old one is removed (to avoid repeated commands moving older commands out of
  50. the history).
  51. - Only commands that are typed are remembered. Ones that completely come from
  52. mappings are not put in the history.
  53. - All searches are put in the search history, including the ones that come
  54. from commands like "*" and "#". But for a mapping, only the last search is
  55. remembered (to avoid that long mappings trash the history).
  56. {not available when compiled without the |+cmdline_hist| feature}
  57. There is an automatic completion of names on the command-line; see
  58. |cmdline-completion|.
  59. *c_CTRL-V*
  60. CTRL-V Insert next non-digit literally. Up to three digits form the
  61. decimal value of a single byte. The non-digit and the three
  62. digits are not considered for mapping. This works the same
  63. way as in Insert mode (see above, |i_CTRL-V|).
  64. Note: Under MS-Windows CTRL-V is often mapped to paste text.
  65. Use CTRL-Q instead then.
  66. When |modifyOtherKeys| is enabled then special Escape sequence
  67. is converted back to what it was without |modifyOtherKeys|,
  68. unless the Shift key is also pressed.
  69. *c_CTRL-Q*
  70. CTRL-Q Same as CTRL-V. But with some terminals it is used for
  71. control flow, it doesn't work then.
  72. CTRL-SHIFT-V *c_CTRL-SHIFT-V* *c_CTRL-SHIFT-Q*
  73. CTRL-SHIFT-Q Works just like CTRL-V, unless |modifyOtherKeys| is active,
  74. then it inserts the Escape sequence for a key with modifiers.
  75. In the GUI the |key-notation| is inserted without simplifying.
  76. *c_<Left>* *c_Left*
  77. <Left> cursor left
  78. *c_<Right>* *c_Right*
  79. <Right> cursor right
  80. *c_<S-Left>*
  81. <S-Left> or <C-Left> *c_<C-Left>*
  82. cursor one WORD left
  83. *c_<S-Right>*
  84. <S-Right> or <C-Right> *c_<C-Right>*
  85. cursor one WORD right
  86. CTRL-B or <Home> *c_CTRL-B* *c_<Home>* *c_Home*
  87. cursor to beginning of command-line
  88. CTRL-E or <End> *c_CTRL-E* *c_<End>* *c_End*
  89. cursor to end of command-line
  90. *c_<LeftMouse>*
  91. <LeftMouse> Move the cursor to the position of the mouse click.
  92. *c_<MiddleMouse>*
  93. <MiddleMouse> Paste the contents of the clipboard (for X11 the primary
  94. selection). This is similar to using CTRL-R *, but no CR
  95. characters are inserted between lines.
  96. CTRL-H *c_<BS>* *c_CTRL-H* *c_BS*
  97. <BS> Delete the character in front of the cursor (see |:fixdel| if
  98. your <BS> key does not do what you want).
  99. *c_<Del>* *c_Del*
  100. <Del> Delete the character under the cursor (at end of line:
  101. character before the cursor) (see |:fixdel| if your <Del>
  102. key does not do what you want).
  103. *c_CTRL-W*
  104. CTRL-W Delete the |word| before the cursor. This depends on the
  105. 'iskeyword' option.
  106. *c_CTRL-U*
  107. CTRL-U Remove all characters between the cursor position and
  108. the beginning of the line. Previous versions of vim
  109. deleted all characters on the line. If that is the
  110. preferred behavior, add the following to your .vimrc: >
  111. :cnoremap <C-U> <C-E><C-U>
  112. <
  113. *c_<Insert>* *c_Insert*
  114. <Insert> Toggle between insert and overstrike.
  115. {char1} <BS> {char2} or *c_digraph*
  116. CTRL-K {char1} {char2} *c_CTRL-K*
  117. enter digraph (see |digraphs|). When {char1} is a special
  118. key, the code for that key is inserted in <> form.
  119. CTRL-R {register} *c_CTRL-R* *c_<C-R>*
  120. Insert the contents of a numbered or named register. Between
  121. typing CTRL-R and the second character '"' will be displayed
  122. to indicate that you are expected to enter the name of a
  123. register.
  124. The text is inserted as if you typed it, but mappings and
  125. abbreviations are not used. Command-line completion through
  126. 'wildchar' is not triggered though. And characters that end
  127. the command line are inserted literally (<Esc>, <CR>, <NL>,
  128. <C-C>). A <BS> or CTRL-W could still end the command line
  129. though, and remaining characters will then be interpreted in
  130. another mode, which might not be what you intended.
  131. Special registers:
  132. '"' the unnamed register, containing the text of
  133. the last delete or yank
  134. '%' the current file name
  135. '#' the alternate file name
  136. '*' the clipboard contents (X11: primary selection)
  137. '+' the clipboard contents
  138. '/' the last search pattern
  139. ':' the last command-line
  140. '-' the last small (less than a line) delete
  141. '.' the last inserted text
  142. *c_CTRL-R_=*
  143. '=' the expression register: you are prompted to
  144. enter an expression (see |expression|)
  145. (doesn't work at the expression prompt; some
  146. things such as changing the buffer or current
  147. window are not allowed to avoid side effects)
  148. When the result is a |List| the items are used
  149. as lines. They can have line breaks inside
  150. too.
  151. When the result is a Float it's automatically
  152. converted to a String.
  153. Note that when you only want to move the
  154. cursor and not insert anything, you must make
  155. sure the expression evaluates to an empty
  156. string. E.g.: >
  157. <C-R><C-R>=setcmdpos(2)[-1]<CR>
  158. < See |registers| about registers.
  159. Implementation detail: When using the |expression| register
  160. and invoking setcmdpos(), this sets the position before
  161. inserting the resulting string. Use CTRL-R CTRL-R to set the
  162. position afterwards.
  163. CTRL-R CTRL-F *c_CTRL-R_CTRL-F* *c_<C-R>_<C-F>*
  164. CTRL-R CTRL-P *c_CTRL-R_CTRL-P* *c_<C-R>_<C-P>*
  165. CTRL-R CTRL-W *c_CTRL-R_CTRL-W* *c_<C-R>_<C-W>*
  166. CTRL-R CTRL-A *c_CTRL-R_CTRL-A* *c_<C-R>_<C-A>*
  167. CTRL-R CTRL-L *c_CTRL-R_CTRL-L* *c_<C-R>_<C-L>*
  168. Insert the object under the cursor:
  169. CTRL-F the Filename under the cursor
  170. CTRL-P the Filename under the cursor, expanded with
  171. 'path' as in |gf|
  172. CTRL-W the Word under the cursor
  173. CTRL-A the WORD under the cursor; see |WORD|
  174. CTRL-L the line under the cursor
  175. When 'incsearch' is set the cursor position at the end of the
  176. currently displayed match is used. With CTRL-W the part of
  177. the word that was already typed is not inserted again.
  178. *c_CTRL-R_CTRL-R* *c_<C-R>_<C-R>*
  179. *c_CTRL-R_CTRL-O* *c_<C-R>_<C-O>*
  180. CTRL-R CTRL-R {register CTRL-F CTRL-P CTRL-W CTRL-A CTRL-L}
  181. CTRL-R CTRL-O {register CTRL-F CTRL-P CTRL-W CTRL-A CTRL-L}
  182. Insert register or object under the cursor. Works like
  183. |c_CTRL-R| but inserts the text literally. For example, if
  184. register a contains "xy^Hz" (where ^H is a backspace),
  185. "CTRL-R a" will insert "xz" while "CTRL-R CTRL-R a" will
  186. insert "xy^Hz".
  187. CTRL-\ e {expr} *c_CTRL-\_e*
  188. Evaluate {expr} and replace the whole command line with the
  189. result. You will be prompted for the expression, type <Enter>
  190. to finish it. It's most useful in mappings though. See
  191. |expression|.
  192. See |c_CTRL-R_=| for inserting the result of an expression.
  193. Useful functions are |getcmdtype()|, |getcmdline()| and
  194. |getcmdpos()|.
  195. The cursor position is unchanged, except when the cursor was
  196. at the end of the line, then it stays at the end.
  197. |setcmdpos()| can be used to set the cursor position.
  198. The |sandbox| is used for evaluating the expression to avoid
  199. nasty side effects.
  200. Example: >
  201. :cmap <F7> <C-\>eAppendSome()<CR>
  202. :func AppendSome()
  203. :let cmd = getcmdline() .. " Some()"
  204. :" place the cursor on the )
  205. :call setcmdpos(strlen(cmd))
  206. :return cmd
  207. :endfunc
  208. < This doesn't work recursively, thus not when already editing
  209. an expression. But it is possible to use in a mapping.
  210. *c_CTRL-Y*
  211. CTRL-Y When there is a modeless selection, copy the selection into
  212. the clipboard. |modeless-selection|
  213. If there is no selection CTRL-Y is inserted as a character.
  214. CTRL-M or CTRL-J *c_CTRL-M* *c_CTRL-J* *c_<NL>* *c_<CR>* *c_CR*
  215. <CR> or <NL> start entered command
  216. CTRL-[ *c_CTRL-[* *c_<Esc>* *c_Esc*
  217. <Esc> When typed and 'x' not present in 'cpoptions', quit
  218. Command-line mode without executing. In macros or when 'x'
  219. present in 'cpoptions', start entered command.
  220. Note: If your <Esc> key is hard to hit on your keyboard, train
  221. yourself to use CTRL-[.
  222. *c_CTRL-C*
  223. CTRL-C quit command-line without executing
  224. *c_<Up>* *c_Up*
  225. <Up> recall older command-line from history, whose beginning
  226. matches the current command-line (see below).
  227. {not available when compiled without the |+cmdline_hist|
  228. feature}
  229. *c_<Down>* *c_Down*
  230. <Down> recall more recent command-line from history, whose beginning
  231. matches the current command-line (see below).
  232. {not available when compiled without the |+cmdline_hist|
  233. feature}
  234. *c_<S-Up>* *c_<PageUp>*
  235. <S-Up> or <PageUp>
  236. recall older command-line from history
  237. {not available when compiled without the |+cmdline_hist|
  238. feature}
  239. *c_<S-Down>* *c_<PageDown>*
  240. <S-Down> or <PageDown>
  241. recall more recent command-line from history
  242. {not available when compiled without the |+cmdline_hist|
  243. feature}
  244. CTRL-D command-line completion (see |cmdline-completion|)
  245. 'wildchar' option
  246. command-line completion (see |cmdline-completion|)
  247. CTRL-N command-line completion (see |cmdline-completion|)
  248. CTRL-P command-line completion (see |cmdline-completion|)
  249. CTRL-A command-line completion (see |cmdline-completion|)
  250. CTRL-L command-line completion (see |cmdline-completion|)
  251. *c_CTRL-_*
  252. CTRL-_ a - switch between Hebrew and English keyboard mode, which is
  253. private to the command-line and not related to hkmap.
  254. This is useful when Hebrew text entry is required in the
  255. command-line, searches, abbreviations, etc. Applies only if
  256. Vim is compiled with the |+rightleft| feature and the
  257. 'allowrevins' option is set.
  258. See |rileft.txt|.
  259. b - switch between Farsi and English keyboard mode, which is
  260. private to the command-line and not related to fkmap. In
  261. Farsi keyboard mode the characters are inserted in reverse
  262. insert manner. This is useful when Farsi text entry is
  263. required in the command-line, searches, abbreviations, etc.
  264. Applies only if Vim is compiled with the |+farsi| feature.
  265. See |farsi.txt|.
  266. *c_CTRL-^*
  267. CTRL-^ Toggle the use of language |:lmap| mappings and/or Input
  268. Method.
  269. When typing a pattern for a search command and 'imsearch' is
  270. not -1, VAL is the value of 'imsearch', otherwise VAL is the
  271. value of 'iminsert'.
  272. When language mappings are defined:
  273. - If VAL is 1 (langmap mappings used) it becomes 0 (no langmap
  274. mappings used).
  275. - If VAL was not 1 it becomes 1, thus langmap mappings are
  276. enabled.
  277. When no language mappings are defined:
  278. - If VAL is 2 (Input Method is used) it becomes 0 (no input
  279. method used)
  280. - If VAL has another value it becomes 2, thus the Input Method
  281. is enabled.
  282. These language mappings are normally used to type characters
  283. that are different from what the keyboard produces. The
  284. 'keymap' option can be used to install a whole number of them.
  285. When entering a command line, langmap mappings are switched
  286. off, since you are expected to type a command. After
  287. switching it on with CTRL-^, the new state is not used again
  288. for the next command or Search pattern.
  289. *c_CTRL-]*
  290. CTRL-] Trigger abbreviation, without inserting a character.
  291. For Emacs-style editing on the command-line see |emacs-keys|.
  292. The <Up> and <Down> keys take the current command-line as a search string.
  293. The beginning of the next/previous command-lines are compared with this
  294. string. The first line that matches is the new command-line. When typing
  295. these two keys repeatedly, the same string is used again. For example, this
  296. can be used to find the previous substitute command: Type ":s" and then <Up>.
  297. The same could be done by typing <S-Up> a number of times until the desired
  298. command-line is shown. (Note: the shifted arrow keys do not work on all
  299. terminals)
  300. *:his* *:history*
  301. :his[tory] Print the history of last entered commands.
  302. {not available when compiled without the |+cmdline_hist|
  303. feature}
  304. :his[tory] [{name}] [{first}][, [{last}]]
  305. List the contents of history {name} which can be:
  306. c[md] or : command-line history
  307. s[earch] or / or ? search string history
  308. e[xpr] or = expression register history
  309. i[nput] or @ input line history
  310. d[ebug] or > debug command history
  311. a[ll] all of the above
  312. If the numbers {first} and/or {last} are given, the respective
  313. range of entries from a history is listed. These numbers can
  314. be specified in the following form:
  315. *:history-indexing*
  316. A positive number represents the absolute index of an entry
  317. as it is given in the first column of a :history listing.
  318. This number remains fixed even if other entries are deleted.
  319. A negative number means the relative position of an entry,
  320. counted from the newest entry (which has index -1) backwards.
  321. Examples:
  322. List entries 6 to 12 from the search history: >
  323. :history / 6,12
  324. <
  325. List the penultimate entry from all histories: >
  326. :history all -2
  327. <
  328. List the most recent two entries from all histories: >
  329. :history all -2,
  330. :keepp[atterns] {command} *:keepp* *:keeppatterns*
  331. Execute {command}, without adding anything to the search
  332. history
  333. ==============================================================================
  334. 2. Command-line completion *cmdline-completion*
  335. When editing the command-line, a few commands can be used to complete the
  336. word before the cursor. This is available for:
  337. - Command names: At the start of the command-line.
  338. - Tags: Only after the ":tag" command.
  339. - File names: Only after a command that accepts a file name or a setting for
  340. an option that can be set to a file name. This is called file name
  341. completion.
  342. - Shell command names: After ":!cmd", ":r !cmd" and ":w !cmd". $PATH is used.
  343. - Options: Only after the ":set" command.
  344. - Mappings: Only after a ":map" or similar command.
  345. - Variable and function names: Only after a ":if", ":call" or similar command.
  346. The number of help item matches is limited (currently to 300) to avoid a long
  347. delay when there are very many matches.
  348. These are the commands that can be used:
  349. *c_CTRL-D*
  350. CTRL-D List names that match the pattern in front of the cursor.
  351. When showing file names, directories are highlighted (see
  352. 'highlight' option). Names where 'suffixes' matches are moved
  353. to the end.
  354. The 'wildoptions' option can be set to "tagfile" to list the
  355. file of matching tags.
  356. *c_CTRL-I* *c_wildchar* *c_<Tab>*
  357. 'wildchar' option
  358. A match is done on the pattern in front of the cursor. The
  359. match (if there are several, the first match) is inserted
  360. in place of the pattern. (Note: does not work inside a
  361. macro, because <Tab> or <Esc> are mostly used as 'wildchar',
  362. and these have a special meaning in some macros.) When typed
  363. again and there were multiple matches, the next
  364. match is inserted. After the last match, the first is used
  365. again (wrap around).
  366. The behavior can be changed with the 'wildmode' option.
  367. *c_<S-Tab>*
  368. <S-Tab> Like 'wildchar' or <Tab>, but begin with the last match and
  369. then go to the previous match.
  370. <S-Tab> does not work everywhere.
  371. *c_CTRL-N*
  372. CTRL-N After using 'wildchar' which got multiple matches, go to next
  373. match. Otherwise recall more recent command-line from history.
  374. *c_CTRL-P*
  375. CTRL-P After using 'wildchar' which got multiple matches, go to
  376. previous match. Otherwise recall older command-line from
  377. history.
  378. *c_CTRL-A*
  379. CTRL-A All names that match the pattern in front of the cursor are
  380. inserted.
  381. *c_CTRL-L*
  382. CTRL-L A match is done on the pattern in front of the cursor. If
  383. there is one match, it is inserted in place of the pattern.
  384. If there are multiple matches the longest common part is
  385. inserted in place of the pattern. If the result is shorter
  386. than the pattern, no completion is done.
  387. */_CTRL-L*
  388. When 'incsearch' is set, entering a search pattern for "/" or
  389. "?" and the current match is displayed then CTRL-L will add
  390. one character from the end of the current match. If
  391. 'ignorecase' and 'smartcase' are set and the command line has
  392. no uppercase characters, the added character is converted to
  393. lowercase.
  394. *c_CTRL-G* */_CTRL-G*
  395. CTRL-G When 'incsearch' is set, entering a search pattern for "/" or
  396. "?" and the current match is displayed then CTRL-G will move
  397. to the next match (does not take |search-offset| into account)
  398. Use CTRL-T to move to the previous match. Hint: on a regular
  399. keyboard T is above G.
  400. *c_CTRL-T* */_CTRL-T*
  401. CTRL-T When 'incsearch' is set, entering a search pattern for "/" or
  402. "?" and the current match is displayed then CTRL-T will move
  403. to the previous match (does not take |search-offset| into
  404. account).
  405. Use CTRL-G to move to the next match. Hint: on a regular
  406. keyboard T is above G.
  407. The 'wildchar' option defaults to <Tab> (CTRL-E when in Vi compatible mode; in
  408. a previous version <Esc> was used). In the pattern standard wildcards '*' and
  409. '?' are accepted when matching file names. '*' matches any string, '?'
  410. matches exactly one character.
  411. When repeating 'wildchar' or CTRL-N you cycle through the matches, eventually
  412. ending up back to what was typed. If the first match is not what you wanted,
  413. you can use <S-Tab> or CTRL-P to go straight back to what you typed.
  414. The 'wildignorecase' option can be set to ignore case in filenames.
  415. The 'wildmenu' option can be set to show the matches just above the command
  416. line.
  417. If you like tcsh's autolist completion, you can use this mapping:
  418. :cnoremap X <C-L><C-D>
  419. (Where X is the command key to use, <C-L> is CTRL-L and <C-D> is CTRL-D)
  420. This will find the longest match and then list all matching files.
  421. If you like tcsh's autolist completion, you can use the 'wildmode' option to
  422. emulate it. For example, this mimics autolist=ambiguous:
  423. :set wildmode=longest,list
  424. This will find the longest match with the first 'wildchar', then list all
  425. matching files with the next.
  426. *complete-script-local-functions*
  427. When completing user function names, prepend "s:" to find script-local
  428. functions.
  429. *suffixes*
  430. For file name completion you can use the 'suffixes' option to set a priority
  431. between files with almost the same name. If there are multiple matches,
  432. those files with an extension that is in the 'suffixes' option are ignored.
  433. The default is ".bak,~,.o,.h,.info,.swp,.obj", which means that files ending
  434. in ".bak", "~", ".o", ".h", ".info", ".swp" and ".obj" are sometimes ignored.
  435. An empty entry, two consecutive commas, match a file name that does not
  436. contain a ".", thus has no suffix. This is useful to ignore "prog" and prefer
  437. "prog.c".
  438. Examples:
  439. pattern: files: match: ~
  440. test* test.c test.h test.o test.c
  441. test* test.h test.o test.h and test.o
  442. test* test.i test.h test.c test.i and test.c
  443. It is impossible to ignore suffixes with two dots.
  444. If there is more than one matching file (after ignoring the ones matching
  445. the 'suffixes' option) the first file name is inserted. You can see that
  446. there is only one match when you type 'wildchar' twice and the completed
  447. match stays the same. You can get to the other matches by entering
  448. 'wildchar', CTRL-N or CTRL-P. All files are included, also the ones with
  449. extensions matching the 'suffixes' option.
  450. To completely ignore files with some extension use 'wildignore'.
  451. To match only files that end at the end of the typed text append a "$". For
  452. example, to match only files that end in ".c": >
  453. :e *.c$
  454. This will not match a file ending in ".cpp". Without the "$" it does match.
  455. The old value of an option can be obtained by hitting 'wildchar' just after
  456. the '='. For example, typing 'wildchar' after ":set dir=" will insert the
  457. current value of 'dir'. This overrules file name completion for the options
  458. that take a file name.
  459. If you would like using <S-Tab> for CTRL-P in an xterm, put this command in
  460. your .cshrc: >
  461. xmodmap -e "keysym Tab = Tab Find"
  462. And this in your .vimrc: >
  463. :cmap <Esc>[1~ <C-P>
  464. ==============================================================================
  465. 3. Ex command-lines *cmdline-lines*
  466. The Ex commands have a few specialties:
  467. *:quote* *:comment*
  468. '"' at the start of a line causes the whole line to be ignored. '"'
  469. after a command causes the rest of the line to be ignored. This can be used
  470. to add comments. Example: >
  471. :set ai "set 'autoindent' option
  472. It is not possible to add a comment to a shell command ":!cmd" or to the
  473. ":map" command and a few others (mainly commands that expect expressions)
  474. that see the '"' as part of their argument:
  475. :argdo
  476. :autocmd
  477. :bufdo
  478. :cexpr (and the like)
  479. :cdo (and the like)
  480. :command
  481. :cscope (and the like)
  482. :debug
  483. :display
  484. :echo (and the like)
  485. :elseif
  486. :execute
  487. :folddoopen
  488. :folddoclosed
  489. :for
  490. :grep (and the like)
  491. :help (and the like)
  492. :if
  493. :let
  494. :make
  495. :map (and the like including :abbrev commands)
  496. :menu (and the like)
  497. :mkspell
  498. :normal
  499. :ownsyntax
  500. :popup
  501. :promptfind (and the like)
  502. :registers
  503. :return
  504. :sort
  505. :syntax
  506. :tabdo
  507. :tearoff
  508. :vimgrep (and the like)
  509. :while
  510. :windo
  511. *:bar* *:\bar*
  512. '|' can be used to separate commands, so you can give multiple commands in one
  513. line. If you want to use '|' in an argument, precede it with '\'.
  514. These commands see the '|' as their argument, and can therefore not be
  515. followed by another Vim command:
  516. :argdo
  517. :autocmd
  518. :bufdo
  519. :cdo
  520. :cfdo
  521. :command
  522. :cscope
  523. :debug
  524. :eval
  525. :folddoopen
  526. :folddoclosed
  527. :function
  528. :global
  529. :help
  530. :helpfind
  531. :helpgrep
  532. :lcscope
  533. :ldo
  534. :lfdo
  535. :lhelpgrep
  536. :make
  537. :normal
  538. :perl
  539. :perldo
  540. :promptfind
  541. :promptrepl
  542. :pyfile
  543. :python
  544. :registers
  545. :read !
  546. :scscope
  547. :sign
  548. :tcl
  549. :tcldo
  550. :tclfile
  551. :terminal
  552. :vglobal
  553. :windo
  554. :write !
  555. :[range]!
  556. a user defined command without the "-bar" argument |:command|
  557. Note that this is confusing (inherited from Vi): With ":g" the '|' is included
  558. in the command, with ":s" it is not.
  559. To be able to use another command anyway, use the ":execute" command.
  560. Example (append the output of "ls" and jump to the first line): >
  561. :execute 'r !ls' | '[
  562. There is one exception: When the 'b' flag is present in 'cpoptions', with the
  563. ":map" and ":abbr" commands and friends CTRL-V needs to be used instead of
  564. '\'. You can also use "<Bar>" instead. See also |map_bar|.
  565. Examples: >
  566. :!ls | wc view the output of two commands
  567. :r !ls | wc insert the same output in the text
  568. :%g/foo/p|> moves all matching lines one shiftwidth
  569. :%s/foo/bar/|> moves one line one shiftwidth
  570. :map q 10^V| map "q" to "10|"
  571. :map q 10\| map \ l map "q" to "10\" and map "\" to "l"
  572. (when 'b' is present in 'cpoptions')
  573. You can also use <NL> to separate commands in the same way as with '|'. To
  574. insert a <NL> use CTRL-V CTRL-J. "^@" will be shown. Using '|' is the
  575. preferred method. But for external commands a <NL> must be used, because a
  576. '|' is included in the external command. To avoid the special meaning of <NL>
  577. it must be preceded with a backslash. Example: >
  578. :r !date<NL>-join
  579. This reads the current date into the file and joins it with the previous line.
  580. Note that when the command before the '|' generates an error, the following
  581. commands will not be executed.
  582. Because of Vi compatibility the following strange commands are supported: >
  583. :| print current line (like ":p")
  584. :3| print line 3 (like ":3p")
  585. :3 goto line 3
  586. A colon is allowed between the range and the command name. It is ignored
  587. (this is Vi compatible). For example: >
  588. :1,$:s/pat/string
  589. When the character '%' or '#' is used where a file name is expected, they are
  590. expanded to the current and alternate file name (see the chapter "editing
  591. files" |:_%| |:_#|).
  592. Embedded spaces in file names are allowed on the Amiga if one file name is
  593. expected as argument. Trailing spaces will be ignored, unless escaped with a
  594. backslash or CTRL-V. Note that the ":next" command uses spaces to separate
  595. file names. Escape the spaces to include them in a file name. Example: >
  596. :next foo\ bar goes\ to school\
  597. starts editing the three files "foo bar", "goes to" and "school ".
  598. When you want to use the special characters '"' or '|' in a command, or want
  599. to use '%' or '#' in a file name, precede them with a backslash. The
  600. backslash is not required in a range and in the ":substitute" command.
  601. See also |`=|.
  602. *:_!*
  603. The '!' (bang) character after an Ex command makes the command behave in a
  604. different way. The '!' should be placed immediately after the command, without
  605. any blanks in between. If you insert blanks the '!' will be seen as an
  606. argument for the command, which has a different meaning. For example:
  607. :w! name write the current buffer to file "name", overwriting
  608. any existing file
  609. :w !name send the current buffer as standard input to command
  610. "name"
  611. ==============================================================================
  612. 4. Ex command-line ranges *cmdline-ranges* *[range]* *E16*
  613. Some Ex commands accept a line range in front of them. This is noted as
  614. [range]. It consists of one or more line specifiers, separated with ',' or
  615. ';'.
  616. The basics are explained in section |10.3| of the user manual.
  617. In |Vim9| script a range needs to be prefixed with a colon to avoid ambiguity
  618. with continuation lines. For example, "+" can be used for a range but is also
  619. a continuation of an expression: >
  620. var result = start
  621. + print
  622. If the "+" is a range then it must be prefixed with a colon: >
  623. var result = start
  624. :+ print
  625. <
  626. *:,* *:;*
  627. When separated with ';' the cursor position will be set to that line
  628. before interpreting the next line specifier. This doesn't happen for ','.
  629. Examples: >
  630. 4,/this line/
  631. < from line 4 till match with "this line" after the cursor line. >
  632. 5;/that line/
  633. < from line 5 till match with "that line" after line 5.
  634. The default line specifier for most commands is the cursor position, but the
  635. commands ":write" and ":global" have the whole file (1,$) as default.
  636. If more line specifiers are given than required for the command, the first
  637. one(s) will be ignored.
  638. Line numbers may be specified with: *:range* *{address}*
  639. {number} an absolute line number *E1247*
  640. . the current line *:.*
  641. $ the last line in the file *:$*
  642. % equal to 1,$ (the entire file) *:%*
  643. 't position of mark t (lowercase) *:'*
  644. 'T position of mark T (uppercase); when the mark is in
  645. another file it cannot be used in a range
  646. /{pattern}[/] the next line where {pattern} matches *:/*
  647. also see |:range-pattern| below
  648. ?{pattern}[?] the previous line where {pattern} matches *:?*
  649. also see |:range-pattern| below
  650. \/ the next line where the previously used search
  651. pattern matches
  652. \? the previous line where the previously used search
  653. pattern matches
  654. \& the next line where the previously used substitute
  655. pattern matches
  656. *:range-offset*
  657. Each may be followed (several times) by '+' or '-' and an optional number.
  658. This number is added or subtracted from the preceding line number. If the
  659. number is omitted, 1 is used. If there is nothing before the '+' or '-' then
  660. the current line is used.
  661. *:range-closed-fold*
  662. When a line number after the comma is in a closed fold it is adjusted to the
  663. last line of the fold, thus the whole fold is included.
  664. When a number is added this is done after the adjustment to the last line of
  665. the fold. This means these lines are additionally included in the range. For
  666. example: >
  667. :3,4+2print
  668. On this text:
  669. 1 one ~
  670. 2 two ~
  671. 3 three ~
  672. 4 four FOLDED ~
  673. 5 five FOLDED ~
  674. 6 six ~
  675. 7 seven ~
  676. 8 eight ~
  677. Where lines four and five are a closed fold, ends up printing lines 3 to 7.
  678. The 7 comes from the "4" in the range, which is adjusted to the end of the
  679. closed fold, which is 5, and then the offset 2 is added.
  680. An example for subtracting (which isn't very useful): >
  681. :2,4-1print
  682. On this text:
  683. 1 one ~
  684. 2 two ~
  685. 3 three FOLDED~
  686. 4 four FOLDED ~
  687. 5 five FOLDED ~
  688. 6 six FOLDED ~
  689. 7 seven ~
  690. 8 eight ~
  691. Where lines three to six are a closed fold, ends up printing lines 2 to 6.
  692. The 6 comes from the "4" in the range, which is adjusted to the end of the
  693. closed fold, which is 6, and then 1 is subtracted, then this is still in the
  694. closed fold and the last line of that fold is used, which is 6.
  695. *:range-pattern*
  696. The "/" and "?" after {pattern} are required to separate the pattern from
  697. anything that follows.
  698. The "/" and "?" may be preceded with another address. The search starts from
  699. there. The difference from using ';' is that the cursor isn't moved.
  700. Examples: >
  701. /pat1//pat2/ Find line containing "pat2" after line containing
  702. "pat1", without moving the cursor.
  703. 7;/pat2/ Find line containing "pat2", after line 7, leaving
  704. the cursor in line 7.
  705. The {number} must be between 0 and the number of lines in the file. When
  706. using a 0 (zero) this is interpreted as a 1 by most commands. Commands that
  707. use it as a count do use it as a zero (|:tag|, |:pop|, etc). Some commands
  708. interpret the zero as "before the first line" (|:read|, search pattern, etc).
  709. Examples: >
  710. .+3 three lines below the cursor
  711. /that/+1 the line below the next line containing "that"
  712. .,$ from current line until end of file
  713. 0;/that the first line containing "that", also matches in the
  714. first line.
  715. 1;/that the first line after line 1 containing "that"
  716. Some commands allow for a count after the command. This count is used as the
  717. number of lines to be used, starting with the line given in the last line
  718. specifier (the default is the cursor line). The commands that accept a count
  719. are the ones that use a range but do not have a file name argument (because
  720. a file name can also be a number). The count cannot be negative.
  721. Examples: >
  722. :s/x/X/g 5 substitute 'x' by 'X' in the current line and four
  723. following lines
  724. :23d 4 delete lines 23, 24, 25 and 26
  725. Folds and Range
  726. When folds are active the line numbers are rounded off to include the whole
  727. closed fold. See |fold-behavior|.
  728. Reverse Range *E493*
  729. A range should have the lower line number first. If this is not the case, Vim
  730. will ask you if it should swap the line numbers.
  731. Backwards range given, OK to swap ~
  732. This is not done within the global command ":g".
  733. You can use ":silent" before a command to avoid the question, the range will
  734. always be swapped then.
  735. Count and Range *N:*
  736. When giving a count before entering ":", this is translated into: >
  737. :.,.+(count - 1)
  738. In words: The "count" lines at and after the cursor. Example: To delete
  739. three lines: >
  740. 3:d<CR> is translated into: .,.+2d<CR>
  741. <
  742. Visual Mode and Range
  743. *v_:*
  744. {Visual}: Starts a command-line with the Visual selected lines as a
  745. range. The code `:'<,'>` is used for this range, which makes
  746. it possible to select a similar line from the command-line
  747. history for repeating a command on different Visually selected
  748. lines.
  749. :* *:star* *:star-visual-range*
  750. When Visual mode was already ended, a short way to use the
  751. Visual area for a range is `:*`. This requires that "*" does
  752. not appear in 'cpo', see |cpo-star|. Otherwise you will have
  753. to type `:'<,'>`
  754. For when "*" is in 'cpo' see |:star-compatible|.
  755. ==============================================================================
  756. 5. Ex command-line flags *ex-flags*
  757. These flags are supported by a selection of Ex commands. They print the line
  758. that the cursor ends up after executing the command:
  759. l output like for |:list|
  760. # add line number
  761. p output like for |:print|
  762. The flags can be combined, thus "l#" uses both a line number and |:list| style
  763. output.
  764. ==============================================================================
  765. 6. Ex special characters *cmdline-special*
  766. Note: These are special characters in the executed command line. If you want
  767. to insert special things while typing you can use the CTRL-R command. For
  768. example, "%" stands for the current file name, while CTRL-R % inserts the
  769. current file name right away. See |c_CTRL-R|.
  770. Note: If you want to avoid the effects of special characters in a Vim script
  771. you may want to use |fnameescape()|. Also see |`=|.
  772. In Ex commands, at places where a file name can be used, the following
  773. characters have a special meaning. These can also be used in the expression
  774. function |expand()|.
  775. % Is replaced with the current file name. *:_%* *c_%*
  776. # Is replaced with the alternate file name. *:_#* *c_#*
  777. This is remembered for every window.
  778. #n (where n is a number) is replaced with *:_#0* *:_#n*
  779. the file name of buffer n. "#0" is the same as "#". *c_#n*
  780. ## Is replaced with all names in the argument list *:_##* *c_##*
  781. concatenated, separated by spaces. Each space in a name
  782. is preceded with a backslash.
  783. #<n (where n is a number > 0) is replaced with old *:_#<* *c_#<*
  784. file name n. See |:oldfiles| or |v:oldfiles| to get the
  785. number. *E809*
  786. {only when compiled with the |+eval| and |+viminfo| features}
  787. In |Vim9-script| # is used to start a comment, use %% for the alternate file
  788. name:
  789. % Is replaced with the current file name.
  790. %% Is replaced with the alternate file name. *:_%%* *c_%%*
  791. %%n (where n is a number) is replaced with *:_%%0* *:_%%n*
  792. the file name of buffer n. "%%0" is the same as "%%". *c_%%n*
  793. %%% Is replaced with all names in the argument *:_%%%* *c_%%%#*
  794. list concatenated, separated by spaces.
  795. %%<n (where n is a number > 0) is replaced with old *:_%%<* *c_%%<*
  796. file name n.
  797. Note that these, except "#<n", give the file name as it was typed. If an
  798. absolute path is needed (when using the file name from a different directory),
  799. you need to add ":p". See |filename-modifiers|.
  800. The "#<n" item returns an absolute path, but it will start with "~/" for files
  801. below your home directory.
  802. Note that backslashes are inserted before spaces, so that the command will
  803. correctly interpret the file name. But this doesn't happen for shell
  804. commands. For those you probably have to use quotes (this fails for files
  805. that contain a quote and wildcards): >
  806. :!ls "%"
  807. :r !spell "%"
  808. To avoid the special meaning of '%' and '#' insert a backslash before it.
  809. Detail: The special meaning is always escaped when there is a backslash before
  810. it, no matter how many backslashes.
  811. you type: result ~
  812. # alternate.file
  813. \# #
  814. \\# \#
  815. Also see |`=|.
  816. *E499* *E500*
  817. Note: these are typed literally, they are not special keys!
  818. *:<cword>* *<cword>*
  819. <cword> is replaced with the word under the cursor (like |star|)
  820. *:<cWORD>* *<cWORD>*
  821. <cWORD> is replaced with the WORD under the cursor (see |WORD|)
  822. *:<cexpr>* *<cexpr>*
  823. <cexpr> is replaced with the word under the cursor, including more
  824. to form a C expression. E.g., when the cursor is on "arg"
  825. of "ptr->arg" then the result is "ptr->arg"; when the
  826. cursor is on "]" of "list[idx]" then the result is
  827. "list[idx]". This is used for |v:beval_text|.
  828. *:<cfile>* *<cfile>*
  829. <cfile> is replaced with the path name under the cursor (like what
  830. |gf| uses)
  831. *:<afile>* *<afile>*
  832. <afile> When executing autocommands, is replaced with the file name
  833. of the buffer being manipulated, or the file for a read or
  834. write. *E495*
  835. *:<abuf>* *<abuf>*
  836. <abuf> When executing autocommands, is replaced with the currently
  837. effective buffer number (for ":r file" and ":so file" it is
  838. the current buffer, the file being read/sourced is not in a
  839. buffer). *E496*
  840. *:<amatch>* *<amatch>*
  841. <amatch> When executing autocommands, is replaced with the match for
  842. which this autocommand was executed. *E497*
  843. It differs from <afile> when the file name isn't used to
  844. match with (for FileType, Syntax and SpellFileMissing
  845. events).
  846. When the match is with a file name, it is expanded to the
  847. full path.
  848. *:<sfile>* *<sfile>*
  849. <sfile> When executing a `:source` command, is replaced with the
  850. file name of the sourced file. *E498*
  851. When executing a legacy function, is replaced with the call
  852. stack, as with <stack> (this is for backwards
  853. compatibility, using <stack> or <script> is preferred).
  854. In Vim9 script using <sfile> in a function gives error
  855. *E1245* .
  856. Note that filename-modifiers are useless when <sfile> is
  857. not used inside a script.
  858. *:<stack>* *<stack>*
  859. <stack> is replaced with the call stack, using
  860. "function {function-name}[{lnum}]" for a function line
  861. and "script {file-name}[{lnum}]" for a script line, and
  862. ".." in between items. E.g.:
  863. "function {function-name1}[{lnum}]..{function-name2}[{lnum}]"
  864. If there is no call stack you get error *E489* .
  865. *:<script>* *<script>*
  866. <script> When executing a `:source` command, is replaced with the file
  867. name of the sourced file. When executing a function, is
  868. replaced with the file name of the script where it is
  869. defined.
  870. If the file name cannot be determined you get error *E1274* .
  871. *:<slnum>* *<slnum>*
  872. <slnum> When executing a `:source` command, is replaced with the
  873. line number. *E842*
  874. When executing a function it's the line number relative to
  875. the start of the function.
  876. *:<sflnum>* *<sflnum>*
  877. <sflnum> When executing a script, is replaced with the line number.
  878. It differs from <slnum> in that <sflnum> is replaced with
  879. the script line number in any situation. *E961*
  880. *:<client>* *<client>*
  881. <client> is replaced with the {clinetid} of the last received
  882. message in |server2client()|
  883. *filename-modifiers*
  884. *:_%:* *::8* *::p* *::.* *::~* *::h* *::t* *::r* *::e* *::s* *::gs* *::S*
  885. *%:8* *%:p* *%:.* *%:~* *%:h* *%:t* *%:r* *%:e* *%:s* *%:gs* *%:S*
  886. The file name modifiers can be used after "%", "#", "#n", "<cfile>", "<sfile>",
  887. "<afile>" or "<abuf>". They are also used with the |fnamemodify()| function.
  888. These modifiers can be given, in this order:
  889. :p Make file name a full path. Must be the first modifier. Also
  890. changes "~/" (and "~user/" for Unix and VMS) to the path for
  891. the home directory. If the name is a directory a path
  892. separator is added at the end. For a file name that does not
  893. exist and does not have an absolute path the result is
  894. unpredictable. On MS-Windows an 8.3 filename is expanded to
  895. the long name.
  896. :8 Converts the path to 8.3 short format (currently only on
  897. MS-Windows). Will act on as much of a path that is an
  898. existing path.
  899. :~ Reduce file name to be relative to the home directory, if
  900. possible. File name is unmodified if it is not below the home
  901. directory.
  902. :. Reduce file name to be relative to current directory, if
  903. possible. File name is unmodified if it is not below the
  904. current directory.
  905. For maximum shortness, use ":~:.".
  906. :h Head of the file name (the last component and any separators
  907. removed). Cannot be used with :e, :r or :t.
  908. Can be repeated to remove several components at the end.
  909. When the file name ends in a path separator, only the path
  910. separator is removed. Thus ":p:h" on a directory name results
  911. on the directory name itself (without trailing slash).
  912. When the file name is an absolute path (starts with "/" for
  913. Unix; "x:\" for Win32; "drive:" for Amiga), that part is not
  914. removed. When there is no head (path is relative to current
  915. directory) the result is empty.
  916. :t Tail of the file name (last component of the name). Must
  917. precede any :r or :e.
  918. :r Root of the file name (the last extension removed). When
  919. there is only an extension (file name that starts with '.',
  920. e.g., ".vimrc"), it is not removed. Can be repeated to remove
  921. several extensions (last one first).
  922. :e Extension of the file name. Only makes sense when used alone.
  923. When there is no extension the result is empty.
  924. When there is only an extension (file name that starts with
  925. '.'), the result is empty. Can be repeated to include more
  926. extensions. If there are not enough extensions (but at least
  927. one) as much as possible are included.
  928. :s?pat?sub?
  929. Substitute the first occurrence of "pat" with "sub". This
  930. works like the |:s| command. "pat" is a regular expression.
  931. Any character can be used for '?', but it must not occur in
  932. "pat" or "sub".
  933. After this, the previous modifiers can be used again. For
  934. example ":p", to make a full path after the substitution.
  935. :gs?pat?sub?
  936. Substitute all occurrences of "pat" with "sub". Otherwise
  937. this works like ":s".
  938. :S Escape special characters for use with a shell command (see
  939. |shellescape()|). Must be the last one. Examples: >
  940. :!dir <cfile>:S
  941. :call system('chmod +w -- ' . expand('%:S'))
  942. Examples, when the file name is "src/version.c", current dir
  943. "/home/mool/vim": >
  944. :p /home/mool/vim/src/version.c
  945. :p:. src/version.c
  946. :p:~ ~/vim/src/version.c
  947. :h src
  948. :p:h /home/mool/vim/src
  949. :p:h:h /home/mool/vim
  950. :t version.c
  951. :p:t version.c
  952. :r src/version
  953. :p:r /home/mool/vim/src/version
  954. :t:r version
  955. :e c
  956. :s?version?main? src/main.c
  957. :s?version?main?:p /home/mool/vim/src/main.c
  958. :p:gs?/?\\? \home\mool\vim\src\version.c
  959. Examples, when the file name is "src/version.c.gz": >
  960. :p /home/mool/vim/src/version.c.gz
  961. :e gz
  962. :e:e c.gz
  963. :e:e:e c.gz
  964. :e:e:r c
  965. :r src/version.c
  966. :r:e c
  967. :r:r src/version
  968. :r:r:r src/version
  969. <
  970. *extension-removal* *:_%<*
  971. If a "<" is appended to "%", "#", "#n" or "CTRL-V p" the extension of the file
  972. name is removed (everything after and including the last '.' in the file
  973. name). This is included for backwards compatibility with version 3.0, the
  974. ":r" form is preferred. Examples: >
  975. % current file name
  976. %< current file name without extension
  977. # alternate file name for current window
  978. #< idem, without extension
  979. #31 alternate file number 31
  980. #31< idem, without extension
  981. <cword> word under the cursor
  982. <cWORD> WORD under the cursor (see |WORD|)
  983. <cfile> path name under the cursor
  984. <cfile>< idem, without extension
  985. Note: Where a file name is expected wildcards expansion is done. On Unix the
  986. shell is used for this, unless it can be done internally (for speed).
  987. Unless in |restricted-mode|, backticks work also, like in >
  988. :n `echo *.c`
  989. But expansion is only done if there are any wildcards before expanding the
  990. '%', '#', etc.. This avoids expanding wildcards inside a file name. If you
  991. want to expand the result of <cfile>, add a wildcard character to it.
  992. Examples: (alternate file name is "?readme?")
  993. command expands to ~
  994. :e # :e ?readme?
  995. :e `ls #` :e {files matching "?readme?"}
  996. :e #.* :e {files matching "?readme?.*"}
  997. :cd <cfile> :cd {file name under cursor}
  998. :cd <cfile>* :cd {file name under cursor plus "*" and then expanded}
  999. Also see |`=|.
  1000. When the expanded argument contains a "!" and it is used for a shell command
  1001. (":!cmd", ":r !cmd" or ":w !cmd"), the "!" is escaped with a backslash to
  1002. avoid it being expanded into a previously used command. When the 'shell'
  1003. option contains "sh", this is done twice, to avoid the shell trying to expand
  1004. the "!".
  1005. *filename-backslash*
  1006. For filesystems that use a backslash as directory separator (MS-Windows), it's
  1007. a bit difficult to recognize a backslash that is used to escape the special
  1008. meaning of the next character. The general rule is: If the backslash is
  1009. followed by a normal file name character, it does not have a special meaning.
  1010. Therefore "\file\foo" is a valid file name, you don't have to type the
  1011. backslash twice.
  1012. An exception is the '$' sign. It is a valid character in a file name. But
  1013. to avoid a file name like "$home" to be interpreted as an environment variable,
  1014. it needs to be preceded by a backslash. Therefore you need to use "/\$home"
  1015. for the file "$home" in the root directory. A few examples:
  1016. FILE NAME INTERPRETED AS ~
  1017. $home expanded to value of environment var $home
  1018. \$home file "$home" in current directory
  1019. /\$home file "$home" in root directory
  1020. \\$home file "\\", followed by expanded $home
  1021. Also see |`=|.
  1022. ==============================================================================
  1023. 7. Command-line window *cmdline-window* *cmdwin*
  1024. *command-line-window*
  1025. In the command-line window the command line can be edited just like editing
  1026. text in any window. It is a special kind of window, because you cannot leave
  1027. it in a normal way.
  1028. OPEN *c_CTRL-F* *q:* *q/* *q?*
  1029. There are two ways to open the command-line window:
  1030. 1. From Command-line mode, use the key specified with the 'cedit' option.
  1031. The default is CTRL-F when 'compatible' is not set.
  1032. 2. From Normal mode, use the "q:", "q/" or "q?" command.
  1033. This starts editing an Ex command-line ("q:") or search string ("q/" or
  1034. "q?"). Note that this is not possible while recording is in progress (the
  1035. "q" stops recording then).
  1036. When the window opens it is filled with the command-line history. The last
  1037. line contains the command as typed so far. The left column will show a
  1038. character that indicates the type of command-line being edited, see
  1039. |cmdwin-char|.
  1040. Vim will be in Normal mode when the editor is opened, except when 'insertmode'
  1041. is set.
  1042. *E1292*
  1043. Once a command-line window is open it is not possible to open another one.
  1044. The height of the window is specified with 'cmdwinheight' (or smaller if there
  1045. is no room). The window is always full width and is positioned just above the
  1046. command-line.
  1047. EDIT
  1048. You can now use commands to move around and edit the text in the window. Both
  1049. in Normal mode and Insert mode.
  1050. It is possible to use ":", "/" and other commands that use the command-line,
  1051. but it's not possible to open another command-line window then. There is no
  1052. nesting.
  1053. *E11* *E1188*
  1054. The command-line window is not a normal window. It is not possible to move to
  1055. another window or edit another buffer. All commands that would do this are
  1056. disabled in the command-line window. Of course it _is_ possible to execute
  1057. any command that you entered in the command-line window. Other text edits are
  1058. discarded when closing the window.
  1059. CLOSE *E199*
  1060. There are several ways to leave the command-line window:
  1061. <CR> Execute the command-line under the cursor. Works both in
  1062. Insert and in Normal mode.
  1063. CTRL-C Continue in Command-line mode. The command-line under the
  1064. cursor is used as the command-line. Works both in Insert and
  1065. in Normal mode. There is no redraw, thus the window will
  1066. remain visible.
  1067. :quit Discard the command line and go back to Normal mode.
  1068. ":close", CTRL-W c, ":exit", ":xit" and CTRL-\ CTRL-N also
  1069. work.
  1070. :qall Quit Vim, unless there are changes in some buffer.
  1071. :qall! Quit Vim, discarding changes to any buffer.
  1072. Once the command-line window is closed the old window sizes are restored. The
  1073. executed command applies to the window and buffer where the command-line was
  1074. started from. This works as if the command-line window was not there, except
  1075. that there will be an extra screen redraw.
  1076. The buffer used for the command-line window is deleted. Any changes to lines
  1077. other than the one that is executed with <CR> are lost.
  1078. If you would like to execute the command under the cursor and then have the
  1079. command-line window open again, you may find this mapping useful: >
  1080. :autocmd CmdwinEnter * map <buffer> <F5> <CR>q:
  1081. VARIOUS
  1082. The command-line window cannot be used:
  1083. - when there already is a command-line window (no nesting)
  1084. - for entering an encryption key or when using inputsecret()
  1085. Some options are set when the command-line window is opened:
  1086. 'filetype' "vim", when editing an Ex command-line; this starts Vim syntax
  1087. highlighting if it was enabled
  1088. 'rightleft' off
  1089. 'modifiable' on
  1090. 'buftype' "nofile"
  1091. 'swapfile' off
  1092. It is allowed to write the buffer contents to a file. This is an easy way to
  1093. save the command-line history and read it back later.
  1094. If the 'wildchar' option is set to <Tab>, and the command-line window is used
  1095. for an Ex command, then two mappings will be added to use <Tab> for completion
  1096. in the command-line window, like this: >
  1097. :inoremap <buffer> <Tab> <C-X><C-V>
  1098. :nnoremap <buffer> <Tab> a<C-X><C-V>
  1099. Note that hitting <Tab> in Normal mode will do completion on the next
  1100. character. That way it works at the end of the line.
  1101. If you don't want these mappings, disable them with: >
  1102. au CmdwinEnter [:>] iunmap <Tab>
  1103. au CmdwinEnter [:>] nunmap <Tab>
  1104. You could put these lines in your vimrc file.
  1105. While in the command-line window you cannot use the mouse to put the cursor in
  1106. another window, or drag statuslines of other windows. You can drag the
  1107. statusline of the command-line window itself and the statusline above it.
  1108. Thus you can resize the command-line window, but not others.
  1109. The |getcmdwintype()| function returns the type of the command-line being
  1110. edited as described in |cmdwin-char|.
  1111. AUTOCOMMANDS
  1112. Two autocommand events are used: |CmdwinEnter| and |CmdwinLeave|. You can use
  1113. the Cmdwin events to do settings specifically for the command-line window.
  1114. Be careful not to cause side effects!
  1115. Example: >
  1116. :au CmdwinEnter : let b:cpt_save = &cpt | set cpt=.
  1117. :au CmdwinLeave : let &cpt = b:cpt_save
  1118. This sets 'complete' to use completion in the current window for |i_CTRL-N|.
  1119. Another example: >
  1120. :au CmdwinEnter [/?] startinsert
  1121. This will make Vim start in Insert mode in the command-line window.
  1122. *cmdwin-char*
  1123. The character used for the pattern indicates the type of command-line:
  1124. : normal Ex command
  1125. > debug mode command |debug-mode|
  1126. / forward search string
  1127. ? backward search string
  1128. = expression for "= |expr-register|
  1129. @ string for |input()|
  1130. - text for |:insert| or |:append|
  1131. vim:tw=78:ts=8:noet:ft=help:norl: