autocmd.txt 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694
  1. *autocmd.txt* Nvim
  2. VIM REFERENCE MANUAL by Bram Moolenaar
  3. Automatic commands *autocmd* *autocommand*
  4. For a basic explanation, see section |40.3| in the user manual.
  5. Type |gO| to see the table of contents.
  6. ==============================================================================
  7. 1. Introduction *autocmd-intro*
  8. You can specify commands to be executed automatically when reading or writing
  9. a file, when entering or leaving a buffer or window, and when exiting Vim.
  10. For example, you can create an autocommand to set the 'cindent' option for
  11. files matching `*.c`. You can also use autocommands to implement advanced
  12. features, such as editing compressed files (see |gzip-example|). The usual
  13. place to put autocommands is in your vimrc file.
  14. *E203* *E204* *E143* *E855* *E937* *E952*
  15. WARNING: Using autocommands is very powerful, and may lead to unexpected side
  16. effects. Be careful not to destroy your text.
  17. - It's a good idea to do some testing on an expendable copy of a file first.
  18. For example: If you use autocommands to decompress a file when starting to
  19. edit it, make sure that the autocommands for compressing when writing work
  20. correctly.
  21. - Be prepared for an error halfway through (e.g., disk full). Vim will mostly
  22. be able to undo the changes to the buffer, but you may have to clean up the
  23. changes to other files by hand (e.g., compress a file that has been
  24. decompressed).
  25. - If the BufRead* events allow you to edit a compressed file, the FileRead*
  26. events should do the same (this makes recovery possible in some rare cases).
  27. It's a good idea to use the same autocommands for the File* and Buf* events
  28. when possible.
  29. ==============================================================================
  30. 2. Defining autocommands *autocmd-define*
  31. *:au* *:autocmd*
  32. :au[tocmd] [group] {event} {aupat} [++once] [++nested] {cmd}
  33. Add {cmd} to the list of commands that Vim will
  34. execute automatically on {event} for a file matching
  35. {aupat} |autocmd-pattern|.
  36. Note: A quote character is seen as argument to the
  37. :autocmd and won't start a comment.
  38. Nvim always adds {cmd} after existing autocommands so
  39. they execute in the order in which they were defined.
  40. See |autocmd-nested| for [++nested].
  41. *autocmd-once*
  42. If [++once] is supplied the command is executed once,
  43. then removed ("one shot").
  44. The special pattern <buffer> or <buffer=N> defines a buffer-local autocommand.
  45. See |autocmd-buflocal|.
  46. Note: The ":autocmd" command can only be followed by another command when the
  47. "|" appears where the pattern is expected. This works: >
  48. :augroup mine | au! BufRead | augroup END
  49. But this sees "augroup" as part of the defined command: >
  50. :augroup mine | au! BufRead * | augroup END
  51. :augroup mine | au BufRead * set tw=70 | augroup END
  52. Instead you can put the group name into the command: >
  53. :au! mine BufRead *
  54. :au mine BufRead * set tw=70
  55. Or use `:execute`: >
  56. :augroup mine | exe "au! BufRead *" | augroup END
  57. :augroup mine | exe "au BufRead * set tw=70" | augroup END
  58. < *autocmd-expand*
  59. Note that special characters (e.g., "%", "<cword>") in the ":autocmd"
  60. arguments are not expanded when the autocommand is defined. These will be
  61. expanded when the Event is recognized, and the {cmd} is executed. The only
  62. exception is that "<sfile>" is expanded when the autocmd is defined. Example:
  63. >
  64. :au BufNewFile,BufRead *.html so <sfile>:h/html.vim
  65. Here Vim expands <sfile> to the name of the file containing this line.
  66. `:autocmd` adds to the list of autocommands regardless of whether they are
  67. already present. When your .vimrc file is sourced twice, the autocommands
  68. will appear twice. To avoid this, define your autocommands in a group, so
  69. that you can easily clear them: >
  70. augroup vimrc
  71. " Remove all vimrc autocommands
  72. autocmd!
  73. au BufNewFile,BufRead *.html so <sfile>:h/html.vim
  74. augroup END
  75. If you don't want to remove all autocommands, you can instead use a variable
  76. to ensure that Vim includes the autocommands only once: >
  77. :if !exists("autocommands_loaded")
  78. : let autocommands_loaded = 1
  79. : au ...
  80. :endif
  81. When the [group] argument is not given, Vim uses the current group (as defined
  82. with ":augroup"); otherwise, Vim uses the group defined with [group]. Note
  83. that [group] must have been defined before. You cannot define a new group
  84. with ":au group ..."; use ":augroup" for that.
  85. While testing autocommands, you might find the 'verbose' option to be useful: >
  86. :set verbose=9
  87. This setting makes Vim echo the autocommands as it executes them.
  88. When defining an autocommand in a script, it will be able to call functions
  89. local to the script and use mappings local to the script. When the event is
  90. triggered and the command executed, it will run in the context of the script
  91. it was defined in. This matters if |<SID>| is used in a command.
  92. When executing the commands, the message from one command overwrites a
  93. previous message. This is different from when executing the commands
  94. manually. Mostly the screen will not scroll up, thus there is no hit-enter
  95. prompt. When one command outputs two messages this can happen anyway.
  96. ==============================================================================
  97. 3. Removing autocommands *autocmd!* *autocmd-remove*
  98. :au[tocmd]! [group] {event} {aupat} [++once] [++nested] {cmd}
  99. Remove all autocommands associated with {event} and
  100. {aupat}, and add the command {cmd}.
  101. See |autocmd-once| for [++once].
  102. See |autocmd-nested| for [++nested].
  103. :au[tocmd]! [group] {event} {aupat}
  104. Remove all autocommands associated with {event} and
  105. {aupat}.
  106. :au[tocmd]! [group] * {aupat}
  107. Remove all autocommands associated with {aupat} for
  108. all events.
  109. :au[tocmd]! [group] {event}
  110. Remove ALL autocommands for {event}.
  111. Warning: You should not do this without a group for
  112. |BufRead| and other common events, it can break
  113. plugins, syntax highlighting, etc.
  114. :au[tocmd]! [group] Remove ALL autocommands.
  115. Note: a quote will be seen as argument to the :autocmd
  116. and won't start a comment.
  117. Warning: You should normally not do this without a
  118. group, it breaks plugins, syntax highlighting, etc.
  119. When the [group] argument is not given, Vim uses the current group (as defined
  120. with ":augroup"); otherwise, Vim uses the group defined with [group].
  121. ==============================================================================
  122. 4. Listing autocommands *autocmd-list*
  123. :au[tocmd] [group] {event} {aupat}
  124. Show the autocommands associated with {event} and
  125. {aupat}.
  126. :au[tocmd] [group] * {aupat}
  127. Show the autocommands associated with {aupat} for all
  128. events.
  129. :au[tocmd] [group] {event}
  130. Show all autocommands for {event}.
  131. :au[tocmd] [group] Show all autocommands.
  132. If you provide the [group] argument, Vim lists only the autocommands for
  133. [group]; otherwise, Vim lists the autocommands for ALL groups. Note that this
  134. argument behavior differs from that for defining and removing autocommands.
  135. In order to list buffer-local autocommands, use a pattern in the form <buffer>
  136. or <buffer=N>. See |autocmd-buflocal|.
  137. *:autocmd-verbose*
  138. When 'verbose' is non-zero, listing an autocommand will also display where it
  139. was last defined. Example: >
  140. :verbose autocmd BufEnter
  141. FileExplorer BufEnter
  142. * call s:LocalBrowse(expand("<amatch>"))
  143. Last set from /usr/share/vim/vim-7.0/plugin/NetrwPlugin.vim
  144. <
  145. See |:verbose-cmd| for more information.
  146. ==============================================================================
  147. 5. Events *autocmd-events* *E215* *E216*
  148. You can specify a comma-separated list of event names. No white space can be
  149. used in this list. The command applies to all the events in the list.
  150. For READING FILES there are four kinds of events possible:
  151. BufNewFile starting to edit a non-existent file
  152. BufReadPre BufReadPost starting to edit an existing file
  153. FilterReadPre FilterReadPost read the temp file with filter output
  154. FileReadPre FileReadPost any other file read
  155. Vim uses only one of these four kinds when reading a file. The "Pre" and
  156. "Post" events are both triggered, before and after reading the file.
  157. Note that the autocommands for the "*ReadPre" events and all the Filter events
  158. are not allowed to change the current buffer (you will get an error message if
  159. this happens). This is to prevent the file to be read into the wrong buffer.
  160. Note that the 'modified' flag is reset AFTER executing the BufReadPost
  161. and BufNewFile autocommands. But when the 'modified' option was set by the
  162. autocommands, this doesn't happen.
  163. You can use the 'eventignore' option to ignore a number of events or all
  164. events.
  165. *events* *{event}*
  166. Nvim recognizes the following events. Names are case-insensitive.
  167. *BufAdd*
  168. BufAdd After adding a new buffer or existing unlisted
  169. buffer to the buffer list (except during
  170. startup, see |VimEnter|), or renaming a listed
  171. buffer.
  172. Before |BufEnter|.
  173. NOTE: Current buffer "%" is not the target
  174. buffer "<afile>", "<abuf>". |<buffer=abuf>|
  175. *BufDelete*
  176. BufDelete Before deleting a buffer from the buffer list.
  177. The BufUnload may be called first (if the
  178. buffer was loaded).
  179. Also used just before a buffer in the buffer
  180. list is renamed.
  181. NOTE: Current buffer "%" is not the target
  182. buffer "<afile>", "<abuf>". |<buffer=abuf>|
  183. Do not change to another buffer.
  184. *BufEnter*
  185. BufEnter After entering (visiting, switching-to) a new
  186. or existing buffer. Useful for setting
  187. filetype options. Compare |BufNew| which
  188. does not trigger for existing buffers.
  189. After |BufAdd|.
  190. After |BufReadPost|.
  191. *BufFilePost*
  192. BufFilePost After changing the name of the current buffer
  193. with the ":file" or ":saveas" command.
  194. *BufFilePre*
  195. BufFilePre Before changing the name of the current buffer
  196. with the ":file" or ":saveas" command.
  197. *BufHidden*
  198. BufHidden Before a buffer becomes hidden: when there are
  199. no longer windows that show the buffer, but
  200. the buffer is not unloaded or deleted.
  201. Not used for ":qa" or ":q" when exiting Vim.
  202. NOTE: Current buffer "%" is not the target
  203. buffer "<afile>", "<abuf>". |<buffer=abuf>|
  204. *BufLeave*
  205. BufLeave Before leaving to another buffer. Also when
  206. leaving or closing the current window and the
  207. new current window is not for the same buffer.
  208. Not used for ":qa" or ":q" when exiting Vim.
  209. *BufModifiedSet*
  210. BufModifiedSet After the `'modified'` value of a buffer has
  211. been changed.
  212. *BufNew*
  213. BufNew After creating a new buffer (except during
  214. startup, see |VimEnter|) or renaming an
  215. existing buffer. Unlike |BufEnter|, visiting
  216. (switching to) an existing buffer will not
  217. trigger this again.
  218. NOTE: Current buffer "%" is not the target
  219. buffer "<afile>", "<abuf>". |<buffer=abuf>|
  220. See also |BufAdd|, |BufNewFile|.
  221. *BufNewFile*
  222. BufNewFile When starting to edit a file that doesn't
  223. exist. Can be used to read in a skeleton
  224. file.
  225. *BufRead* *BufReadPost*
  226. BufRead or BufReadPost When starting to edit a new buffer, after
  227. reading the file into the buffer, before
  228. processing modelines. See |BufWinEnter| to do
  229. something after processing modelines.
  230. Also triggered:
  231. - when writing an unnamed buffer in a way that
  232. the buffer gets a name
  233. - after successfully recovering a file
  234. - for the "filetypedetect" group when
  235. executing ":filetype detect"
  236. Not triggered:
  237. - for the `:read file` command
  238. - when the file doesn't exist
  239. *BufReadCmd*
  240. BufReadCmd Before starting to edit a new buffer. Should
  241. read the file into the buffer. |Cmd-event|
  242. *BufReadPre* *E200* *E201*
  243. BufReadPre When starting to edit a new buffer, before
  244. reading the file into the buffer. Not used
  245. if the file doesn't exist.
  246. *BufUnload*
  247. BufUnload Before unloading a buffer, when the text in
  248. the buffer is going to be freed.
  249. After BufWritePost.
  250. Before BufDelete.
  251. Triggers for all loaded buffers when Vim is
  252. going to exit.
  253. NOTE: Current buffer "%" is not the target
  254. buffer "<afile>", "<abuf>". |<buffer=abuf>|
  255. Do not switch buffers or windows!
  256. Not triggered when exiting and v:dying is 2 or
  257. more.
  258. *BufWinEnter*
  259. BufWinEnter After a buffer is displayed in a window. This
  260. may be when the buffer is loaded (after
  261. processing modelines) or when a hidden buffer
  262. is displayed (and is no longer hidden).
  263. Not triggered for |:split| without arguments,
  264. since the buffer does not change, or :split
  265. with a file already open in a window.
  266. Triggered for ":split" with the name of the
  267. current buffer, since it reloads that buffer.
  268. *BufWinLeave*
  269. BufWinLeave Before a buffer is removed from a window.
  270. Not when it's still visible in another window.
  271. Also triggered when exiting.
  272. Before BufUnload, BufHidden.
  273. NOTE: Current buffer "%" is not the target
  274. buffer "<afile>", "<abuf>". |<buffer=abuf>|
  275. Not triggered when exiting and v:dying is 2 or
  276. more.
  277. *BufWipeout*
  278. BufWipeout Before completely deleting a buffer. The
  279. BufUnload and BufDelete events may be called
  280. first (if the buffer was loaded and was in the
  281. buffer list). Also used just before a buffer
  282. is renamed (also when it's not in the buffer
  283. list).
  284. NOTE: Current buffer "%" is not the target
  285. buffer "<afile>", "<abuf>". |<buffer=abuf>|
  286. Do not change to another buffer.
  287. *BufWrite* *BufWritePre*
  288. BufWrite or BufWritePre Before writing the whole buffer to a file.
  289. *BufWriteCmd*
  290. BufWriteCmd Before writing the whole buffer to a file.
  291. Should do the writing of the file and reset
  292. 'modified' if successful, unless '+' is in
  293. 'cpo' and writing to another file |cpo-+|.
  294. The buffer contents should not be changed.
  295. When the command resets 'modified' the undo
  296. information is adjusted to mark older undo
  297. states as 'modified', like |:write| does.
  298. |Cmd-event|
  299. *BufWritePost*
  300. BufWritePost After writing the whole buffer to a file
  301. (should undo the commands for BufWritePre).
  302. *ChanInfo*
  303. ChanInfo State of channel changed, for instance the
  304. client of a RPC channel described itself.
  305. Sets these |v:event| keys:
  306. info as from |nvim_get_chan_info()|
  307. *ChanOpen*
  308. ChanOpen Just after a channel was opened.
  309. Sets these |v:event| keys:
  310. info as from |nvim_get_chan_info()|
  311. *CmdUndefined*
  312. CmdUndefined When a user command is used but it isn't
  313. defined. Useful for defining a command only
  314. when it's used. The pattern is matched
  315. against the command name. Both <amatch> and
  316. <afile> expand to the command name.
  317. NOTE: Autocompletion won't work until the
  318. command is defined. An alternative is to
  319. always define the user command and have it
  320. invoke an autoloaded function. See |autoload|.
  321. *CmdlineChanged*
  322. CmdlineChanged After a change was made to the text inside
  323. command line. Be careful not to mess up the
  324. command line, it may cause Vim to lock up.
  325. <afile> expands to the |cmdline-char|.
  326. *CmdlineEnter*
  327. CmdlineEnter After entering the command-line (including
  328. non-interactive use of ":" in a mapping: use
  329. |<Cmd>| instead to avoid this).
  330. The pattern is matched against |cmdline-char|.
  331. <afile> expands to the |cmdline-char|.
  332. Sets these |v:event| keys:
  333. cmdlevel
  334. cmdtype
  335. *CmdlineLeave*
  336. CmdlineLeave Before leaving the command-line (including
  337. non-interactive use of ":" in a mapping: use
  338. |<Cmd>| instead to avoid this).
  339. <afile> expands to the |cmdline-char|.
  340. Sets these |v:event| keys:
  341. abort (mutable)
  342. cmdlevel
  343. cmdtype
  344. Note: `abort` can only be changed from false
  345. to true: cannot execute an already aborted
  346. cmdline by changing it to false.
  347. *CmdwinEnter*
  348. CmdwinEnter After entering the command-line window.
  349. Useful for setting options specifically for
  350. this special type of window.
  351. <afile> expands to a single character,
  352. indicating the type of command-line.
  353. |cmdwin-char|
  354. *CmdwinLeave*
  355. CmdwinLeave Before leaving the command-line window.
  356. Useful to clean up any global setting done
  357. with CmdwinEnter.
  358. <afile> expands to a single character,
  359. indicating the type of command-line.
  360. |cmdwin-char|
  361. *ColorScheme*
  362. ColorScheme After loading a color scheme. |:colorscheme|
  363. Not triggered if the color scheme is not
  364. found.
  365. The pattern is matched against the
  366. colorscheme name. <afile> can be used for the
  367. name of the actual file where this option was
  368. set, and <amatch> for the new colorscheme
  369. name.
  370. *ColorSchemePre*
  371. ColorSchemePre Before loading a color scheme. |:colorscheme|
  372. Useful to setup removing things added by a
  373. color scheme, before another one is loaded.
  374. CompleteChanged *CompleteChanged*
  375. After each time the Insert mode completion
  376. menu changed. Not fired on popup menu hide,
  377. use |CompleteDonePre| or |CompleteDone| for
  378. that.
  379. Sets these |v:event| keys:
  380. completed_item See |complete-items|.
  381. height nr of items visible
  382. width screen cells
  383. row top screen row
  384. col leftmost screen column
  385. size total nr of items
  386. scrollbar TRUE if visible
  387. Non-recursive (event cannot trigger itself).
  388. Cannot change the text. |textlock|
  389. The size and position of the popup are also
  390. available by calling |pum_getpos()|.
  391. *CompleteDonePre*
  392. CompleteDonePre After Insert mode completion is done. Either
  393. when something was completed or abandoning
  394. completion. |ins-completion|
  395. |complete_info()| can be used, the info is
  396. cleared after triggering CompleteDonePre.
  397. The |v:completed_item| variable contains
  398. information about the completed item.
  399. *CompleteDone*
  400. CompleteDone After Insert mode completion is done. Either
  401. when something was completed or abandoning
  402. completion. |ins-completion|
  403. |complete_info()| cannot be used, the info is
  404. cleared before triggering CompleteDone. Use
  405. CompleteDonePre if you need it.
  406. |v:completed_item| gives the completed item.
  407. Sets these |v:event| keys:
  408. complete_word The word that was
  409. selected, empty if
  410. abandoned complete.
  411. complete_type |complete_info_mode|
  412. reason Reason for completion being
  413. done. Can be one of:
  414. - "accept": completion was
  415. accepted using |complete_CTRL-Y|.
  416. - "cancel": completion was cancelled
  417. using |complete_CTRL-E|, pressing
  418. a non-keyword character, or
  419. triggering a new completion.
  420. *CursorHold*
  421. CursorHold When the user doesn't press a key for the time
  422. specified with 'updatetime'. Not triggered
  423. until the user has pressed a key (i.e. doesn't
  424. fire every 'updatetime' ms if you leave Vim to
  425. make some coffee. :) See |CursorHold-example|
  426. for previewing tags.
  427. This event is only triggered in Normal mode.
  428. It is not triggered when waiting for a command
  429. argument to be typed, or a movement after an
  430. operator.
  431. While recording the CursorHold event is not
  432. triggered. |q|
  433. *<CursorHold>*
  434. Internally the autocommand is triggered by the
  435. <CursorHold> key. In an expression mapping
  436. |getchar()| may see this character.
  437. Note: Interactive commands cannot be used for
  438. this event. There is no hit-enter prompt,
  439. the screen is updated directly (when needed).
  440. Note: In the future there will probably be
  441. another option to set the time.
  442. Hint: to force an update of the status lines
  443. use: >
  444. :let &ro = &ro
  445. <
  446. *CursorHoldI*
  447. CursorHoldI Like CursorHold, but in Insert mode. Not
  448. triggered when waiting for another key, e.g.
  449. after CTRL-V, and not in CTRL-X mode
  450. |insert_expand|.
  451. *CursorMoved*
  452. CursorMoved After the cursor was moved in Normal or Visual
  453. mode or to another window. Also when the text
  454. of the cursor line has been changed, e.g. with
  455. "x", "rx" or "p".
  456. Not always triggered when there is typeahead,
  457. while executing commands in a script file, or
  458. when an operator is pending.
  459. For an example see |match-parens|.
  460. Note: Cannot be skipped with |:noautocmd|.
  461. Careful: This is triggered very often, don't
  462. do anything that the user does not expect or
  463. that is slow.
  464. *CursorMovedC*
  465. CursorMovedC After the cursor was moved in the command
  466. line. Be careful not to mess up the command
  467. line, it may cause Vim to lock up.
  468. <afile> expands to the |cmdline-char|.
  469. *CursorMovedI*
  470. CursorMovedI After the cursor was moved in Insert mode.
  471. Not triggered when the popup menu is visible.
  472. Otherwise the same as CursorMoved.
  473. *DiffUpdated*
  474. DiffUpdated After diffs have been updated. Depending on
  475. what kind of diff is being used (internal or
  476. external) this can be triggered on every
  477. change or when doing |:diffupdate|.
  478. *DirChanged*
  479. DirChanged After the |current-directory| was changed.
  480. The pattern can be:
  481. "window" to trigger on `:lcd`
  482. "tabpage" to trigger on `:tcd`
  483. "global" to trigger on `:cd`
  484. "auto" to trigger on 'autochdir'.
  485. Sets these |v:event| keys:
  486. cwd: current working directory
  487. scope: "global", "tabpage", "window"
  488. changed_window: v:true if we fired the event
  489. switching window (or tab)
  490. <afile> is set to the new directory name.
  491. Non-recursive (event cannot trigger itself).
  492. *DirChangedPre*
  493. DirChangedPre When the |current-directory| is going to be
  494. changed, as with |DirChanged|.
  495. The pattern is like with |DirChanged|.
  496. Sets these |v:event| keys:
  497. directory: new working directory
  498. scope: "global", "tabpage", "window"
  499. changed_window: v:true if we fired the event
  500. switching window (or tab)
  501. <afile> is set to the new directory name.
  502. Non-recursive (event cannot trigger itself).
  503. *ExitPre*
  504. ExitPre When using `:quit`, `:wq` in a way it makes
  505. Vim exit, or using `:qall`, just after
  506. |QuitPre|. Can be used to close any
  507. non-essential window. Exiting may still be
  508. cancelled if there is a modified buffer that
  509. isn't automatically saved, use |VimLeavePre|
  510. for really exiting.
  511. See also |QuitPre|, |WinClosed|.
  512. *FileAppendCmd*
  513. FileAppendCmd Before appending to a file. Should do the
  514. appending to the file. Use the '[ and ']
  515. marks for the range of lines. |Cmd-event|
  516. *FileAppendPost*
  517. FileAppendPost After appending to a file.
  518. *FileAppendPre*
  519. FileAppendPre Before appending to a file. Use the '[ and ']
  520. marks for the range of lines.
  521. *FileChangedRO*
  522. FileChangedRO Before making the first change to a read-only
  523. file. Can be used to checkout the file from
  524. a source control system. Not triggered when
  525. the change was caused by an autocommand.
  526. Triggered when making the first change in
  527. a buffer or the first change after 'readonly'
  528. was set, just before the change is applied to
  529. the text.
  530. WARNING: If the autocommand moves the cursor
  531. the effect of the change is undefined.
  532. *E788*
  533. Cannot switch buffers. You can reload the
  534. buffer but not edit another one.
  535. *E881*
  536. If the number of lines changes saving for undo
  537. may fail and the change will be aborted.
  538. *FileChangedShell*
  539. FileChangedShell When Vim notices that the modification time of
  540. a file has changed since editing started.
  541. Also when the file attributes of the file
  542. change or when the size of the file changes.
  543. |timestamp|
  544. Triggered for each changed file, after:
  545. - executing a shell command
  546. - |:checktime|
  547. - |FocusGained|
  548. Not used when 'autoread' is set and the buffer
  549. was not changed. If a FileChangedShell
  550. autocommand exists the warning message and
  551. prompt is not given.
  552. |v:fcs_reason| indicates what happened. Set
  553. |v:fcs_choice| to control what happens next.
  554. NOTE: Current buffer "%" is not the target
  555. buffer "<afile>" and "<abuf>". |<buffer=abuf>|
  556. *E246* *E811*
  557. Cannot switch, jump to or delete buffers.
  558. Non-recursive (event cannot trigger itself).
  559. *FileChangedShellPost*
  560. FileChangedShellPost After handling a file that was changed outside
  561. of Vim. Can be used to update the statusline.
  562. *FileReadCmd*
  563. FileReadCmd Before reading a file with a ":read" command.
  564. Should do the reading of the file. |Cmd-event|
  565. *FileReadPost*
  566. FileReadPost After reading a file with a ":read" command.
  567. Note that Vim sets the '[ and '] marks to the
  568. first and last line of the read. This can be
  569. used to operate on the lines just read.
  570. *FileReadPre*
  571. FileReadPre Before reading a file with a ":read" command.
  572. *FileType*
  573. FileType When the 'filetype' option has been set. The
  574. pattern is matched against the filetype.
  575. <afile> is the name of the file where this
  576. option was set. <amatch> is the new value of
  577. 'filetype'.
  578. Cannot switch windows or buffers.
  579. See |filetypes|.
  580. *FileWriteCmd*
  581. FileWriteCmd Before writing to a file, when not writing the
  582. whole buffer. Should do the writing to the
  583. file. Should not change the buffer. Use the
  584. '[ and '] marks for the range of lines.
  585. |Cmd-event|
  586. *FileWritePost*
  587. FileWritePost After writing to a file, when not writing the
  588. whole buffer.
  589. *FileWritePre*
  590. FileWritePre Before writing to a file, when not writing the
  591. whole buffer. Use the '[ and '] marks for the
  592. range of lines.
  593. *FilterReadPost*
  594. FilterReadPost After reading a file from a filter command.
  595. Vim checks the pattern against the name of
  596. the current buffer as with FilterReadPre.
  597. Not triggered when 'shelltemp' is off.
  598. *FilterReadPre* *E135*
  599. FilterReadPre Before reading a file from a filter command.
  600. Vim checks the pattern against the name of
  601. the current buffer, not the name of the
  602. temporary file that is the output of the
  603. filter command.
  604. Not triggered when 'shelltemp' is off.
  605. *FilterWritePost*
  606. FilterWritePost After writing a file for a filter command or
  607. making a diff with an external diff (see
  608. |DiffUpdated| for internal diff).
  609. Vim checks the pattern against the name of
  610. the current buffer as with FilterWritePre.
  611. Not triggered when 'shelltemp' is off.
  612. *FilterWritePre*
  613. FilterWritePre Before writing a file for a filter command or
  614. making a diff with an external diff.
  615. Vim checks the pattern against the name of
  616. the current buffer, not the name of the
  617. temporary file that is the output of the
  618. filter command.
  619. Not triggered when 'shelltemp' is off.
  620. *FocusGained*
  621. FocusGained Nvim got focus.
  622. *FocusLost*
  623. FocusLost Nvim lost focus. Also (potentially) when
  624. a GUI dialog pops up.
  625. *FuncUndefined*
  626. FuncUndefined When a user function is used but it isn't
  627. defined. Useful for defining a function only
  628. when it's used. The pattern is matched
  629. against the function name. Both <amatch> and
  630. <afile> are set to the name of the function.
  631. NOTE: When writing Vim scripts a better
  632. alternative is to use an autoloaded function.
  633. See |autoload-functions|.
  634. *UIEnter*
  635. UIEnter After a UI connects via |nvim_ui_attach()|, or
  636. after builtin TUI is started, after |VimEnter|.
  637. Sets these |v:event| keys:
  638. chan: |channel-id| of the UI
  639. *UILeave*
  640. UILeave After a UI disconnects from Nvim, or after
  641. builtin TUI is stopped, after |VimLeave|.
  642. Sets these |v:event| keys:
  643. chan: |channel-id| of the UI
  644. *InsertChange*
  645. InsertChange When typing <Insert> while in Insert or
  646. Replace mode. The |v:insertmode| variable
  647. indicates the new mode.
  648. Be careful not to move the cursor or do
  649. anything else that the user does not expect.
  650. *InsertCharPre*
  651. InsertCharPre When a character is typed in Insert mode,
  652. before inserting the char.
  653. The |v:char| variable indicates the char typed
  654. and can be changed during the event to insert
  655. a different character. When |v:char| is set
  656. to more than one character this text is
  657. inserted literally.
  658. Cannot change the text. |textlock|
  659. *InsertEnter*
  660. InsertEnter Just before starting Insert mode. Also for
  661. Replace mode and Virtual Replace mode. The
  662. |v:insertmode| variable indicates the mode.
  663. Be careful not to do anything else that the
  664. user does not expect.
  665. The cursor is restored afterwards. If you do
  666. not want that set |v:char| to a non-empty
  667. string.
  668. *InsertLeavePre*
  669. InsertLeavePre Just before leaving Insert mode. Also when
  670. using CTRL-O |i_CTRL-O|. Be careful not to
  671. change mode or use `:normal`, it will likely
  672. cause trouble.
  673. *InsertLeave*
  674. InsertLeave Just after leaving Insert mode. Also when
  675. using CTRL-O |i_CTRL-O|. But not for |i_CTRL-C|.
  676. *MenuPopup*
  677. MenuPopup Just before showing the popup menu (under the
  678. right mouse button). Useful for adjusting the
  679. menu for what is under the cursor or mouse
  680. pointer.
  681. The pattern is matched against one or two
  682. characters representing the mode:
  683. n Normal
  684. v Visual
  685. o Operator-pending
  686. i Insert
  687. c Command line
  688. tl Terminal
  689. *ModeChanged*
  690. ModeChanged After changing the mode. The pattern is
  691. matched against `'old_mode:new_mode'`, for
  692. example match against `*:c` to simulate
  693. |CmdlineEnter|.
  694. The following values of |v:event| are set:
  695. old_mode The mode before it changed.
  696. new_mode The new mode as also returned
  697. by |mode()| called with a
  698. non-zero argument.
  699. When ModeChanged is triggered, old_mode will
  700. have the value of new_mode when the event was
  701. last triggered.
  702. This will be triggered on every minor mode
  703. change.
  704. Usage example to use relative line numbers
  705. when entering visual mode: >
  706. :au ModeChanged [vV\x16]*:* let &l:rnu = mode() =~# '^[vV\x16]'
  707. :au ModeChanged *:[vV\x16]* let &l:rnu = mode() =~# '^[vV\x16]'
  708. :au WinEnter,WinLeave * let &l:rnu = mode() =~# '^[vV\x16]'
  709. < *OptionSet*
  710. OptionSet After setting an option (except during
  711. |startup|). The |autocmd-pattern| is matched
  712. against the long option name. |<amatch>|
  713. indicates what option has been set.
  714. |v:option_type| indicates whether it's global
  715. or local scoped.
  716. |v:option_command| indicates what type of
  717. set/let command was used (follow the tag to
  718. see the table).
  719. |v:option_new| indicates the newly set value.
  720. |v:option_oldlocal| has the old local value.
  721. |v:option_oldglobal| has the old global value.
  722. |v:option_old| indicates the old option value.
  723. |v:option_oldlocal| is only set when |:set|
  724. or |:setlocal| or a |modeline| was used to set
  725. the option. Similarly |v:option_oldglobal| is
  726. only set when |:set| or |:setglobal| was used.
  727. This does not set |<abuf>|, you could use
  728. |bufnr()|.
  729. Note that when setting a |global-local| option
  730. with |:set|, then |v:option_old| is the old
  731. global value. However, for all options that
  732. are not global-local it is the old local
  733. value.
  734. Usage example: Check for the existence of the
  735. directory in the 'backupdir' and 'undodir'
  736. options, create the directory if it doesn't
  737. exist yet.
  738. Note: Do not reset the same option during this
  739. autocommand, that may break plugins. You can
  740. always use |:noautocmd| to prevent triggering
  741. OptionSet.
  742. Non-recursive: |:set| in the autocommand does
  743. not trigger OptionSet again.
  744. Not triggered on startup.
  745. *QuickFixCmdPre*
  746. QuickFixCmdPre Before a quickfix command is run (|:make|,
  747. |:lmake|, |:grep|, |:lgrep|, |:grepadd|,
  748. |:lgrepadd|, |:vimgrep|, |:lvimgrep|,
  749. |:vimgrepadd|, |:lvimgrepadd|,
  750. |:cfile|, |:cgetfile|, |:caddfile|, |:lfile|,
  751. |:lgetfile|, |:laddfile|, |:helpgrep|,
  752. |:lhelpgrep|, |:cexpr|, |:cgetexpr|,
  753. |:caddexpr|, |:cbuffer|, |:cgetbuffer|,
  754. |:caddbuffer|).
  755. The pattern is matched against the command
  756. being run. When |:grep| is used but 'grepprg'
  757. is set to "internal" it still matches "grep".
  758. This command cannot be used to set the
  759. 'makeprg' and 'grepprg' variables.
  760. If this command causes an error, the quickfix
  761. command is not executed.
  762. *QuickFixCmdPost*
  763. QuickFixCmdPost Like QuickFixCmdPre, but after a quickfix
  764. command is run, before jumping to the first
  765. location. For |:cfile| and |:lfile| commands
  766. it is run after the error file is read and
  767. before moving to the first error.
  768. See |QuickFixCmdPost-example|.
  769. *QuitPre*
  770. QuitPre When using `:quit`, `:wq` or `:qall`, before
  771. deciding whether it closes the current window
  772. or quits Vim. For `:wq` the buffer is written
  773. before QuitPre is triggered. Can be used to
  774. close any non-essential window if the current
  775. window is the last ordinary window.
  776. See also |ExitPre|, |WinClosed|.
  777. *RemoteReply*
  778. RemoteReply When a reply from a Vim that functions as
  779. server was received server2client(). The
  780. pattern is matched against the {serverid}.
  781. <amatch> is equal to the {serverid} from which
  782. the reply was sent, and <afile> is the actual
  783. reply string.
  784. Note that even if an autocommand is defined,
  785. the reply should be read with remote_read()
  786. to consume it.
  787. *SearchWrapped*
  788. SearchWrapped After making a search with |n| or |N| if the
  789. search wraps around the document back to
  790. the start/finish respectively.
  791. *RecordingEnter*
  792. RecordingEnter When a macro starts recording.
  793. The pattern is the current file name, and
  794. |reg_recording()| is the current register that
  795. is used.
  796. *RecordingLeave*
  797. RecordingLeave When a macro stops recording.
  798. The pattern is the current file name, and
  799. |reg_recording()| is the recorded
  800. register.
  801. |reg_recorded()| is only updated after this
  802. event.
  803. Sets these |v:event| keys:
  804. regcontents
  805. regname
  806. *SafeState*
  807. SafeState When nothing is pending, going to wait for the
  808. user to type a character.
  809. This will not be triggered when:
  810. - an operator is pending
  811. - a register was entered with "r
  812. - halfway executing a command
  813. - executing a mapping
  814. - there is typeahead
  815. - Insert mode completion is active
  816. - Command line completion is active
  817. You can use `mode()` to find out what state
  818. Vim is in. That may be:
  819. - Visual mode
  820. - Normal mode
  821. - Insert mode
  822. - Command-line mode
  823. Depending on what you want to do, you may also
  824. check more with `state()`, e.g. whether the
  825. screen was scrolled for messages.
  826. *SessionLoadPost*
  827. SessionLoadPost After loading the session file created using
  828. the |:mksession| command.
  829. *SessionWritePost*
  830. SessionWritePost After writing a session file by calling
  831. the |:mksession| command.
  832. *ShellCmdPost*
  833. ShellCmdPost After executing a shell command with |:!cmd|,
  834. |:make| and |:grep|. Can be used to check for
  835. any changed files.
  836. For non-blocking shell commands, see
  837. |job-control|.
  838. *Signal*
  839. Signal After Nvim receives a signal. The pattern is
  840. matched against the signal name. Only
  841. "SIGUSR1" and "SIGWINCH" are supported. Example: >
  842. autocmd Signal SIGUSR1 call some#func()
  843. < *ShellFilterPost*
  844. ShellFilterPost After executing a shell command with
  845. ":{range}!cmd", ":w !cmd" or ":r !cmd".
  846. Can be used to check for any changed files.
  847. *SourcePre*
  848. SourcePre Before sourcing a Vimscript/Lua file. |:source|
  849. <afile> is the name of the file being sourced.
  850. *SourcePost*
  851. SourcePost After sourcing a Vimscript/Lua file. |:source|
  852. <afile> is the name of the file being sourced.
  853. Not triggered when sourcing was interrupted.
  854. Also triggered after a SourceCmd autocommand
  855. was triggered.
  856. *SourceCmd*
  857. SourceCmd When sourcing a Vimscript/Lua file. |:source|
  858. <afile> is the name of the file being sourced.
  859. The autocommand must source that file.
  860. |Cmd-event|
  861. *SpellFileMissing*
  862. SpellFileMissing When trying to load a spell checking file and
  863. it can't be found. The pattern is matched
  864. against the language. <amatch> is the
  865. language, 'encoding' also matters. See
  866. |spell-SpellFileMissing|.
  867. *StdinReadPost*
  868. StdinReadPost During startup, after reading from stdin into
  869. the buffer, before executing modelines. |--|
  870. *StdinReadPre*
  871. StdinReadPre During startup, before reading from stdin into
  872. the buffer. |--|
  873. *SwapExists*
  874. SwapExists Detected an existing swap file when starting
  875. to edit a file. Only when it is possible to
  876. select a way to handle the situation, when Vim
  877. would ask the user what to do.
  878. The |v:swapname| variable holds the name of
  879. the swap file found, <afile> the file being
  880. edited. |v:swapcommand| may contain a command
  881. to be executed in the opened file.
  882. The commands should set the |v:swapchoice|
  883. variable to a string with one character to
  884. tell Vim what should be done next:
  885. 'o' open read-only
  886. 'e' edit the file anyway
  887. 'r' recover
  888. 'd' delete the swap file
  889. 'q' quit, don't edit the file
  890. 'a' abort, like hitting CTRL-C
  891. When set to an empty string the user will be
  892. asked, as if there was no SwapExists autocmd.
  893. *E812*
  894. Cannot change to another buffer, change
  895. the buffer name or change directory.
  896. *Syntax*
  897. Syntax When the 'syntax' option has been set. The
  898. pattern is matched against the syntax name.
  899. <afile> expands to the name of the file where
  900. this option was set. <amatch> expands to the
  901. new value of 'syntax'.
  902. See |:syn-on|.
  903. *TabEnter*
  904. TabEnter Just after entering a tab page. |tab-page|
  905. After WinEnter.
  906. Before BufEnter.
  907. *TabLeave*
  908. TabLeave Just before leaving a tab page. |tab-page|
  909. After WinLeave.
  910. *TabNew*
  911. TabNew When creating a new tab page. |tab-page|
  912. After WinEnter.
  913. Before TabEnter.
  914. *TabNewEntered*
  915. TabNewEntered After entering a new tab page. |tab-page|
  916. After BufEnter.
  917. *TabClosed*
  918. TabClosed After closing a tab page. <afile> expands to
  919. the tab page number.
  920. *TermOpen*
  921. TermOpen When a |terminal| job is starting. Can be
  922. used to configure the terminal buffer.
  923. *TermEnter*
  924. TermEnter After entering |Terminal-mode|.
  925. After TermOpen.
  926. *TermLeave*
  927. TermLeave After leaving |Terminal-mode|.
  928. After TermClose.
  929. *TermClose*
  930. TermClose When a |terminal| job ends.
  931. Sets these |v:event| keys:
  932. status
  933. *TermRequest*
  934. TermRequest When a |:terminal| child process emits an OSC
  935. or DCS sequence. Sets |v:termrequest|. The
  936. |event-data| is the request string.
  937. *TermResponse*
  938. TermResponse When Nvim receives an OSC or DCS response from
  939. the host terminal. Sets |v:termresponse|. The
  940. |event-data| is the response string. May be
  941. triggered during another event (file I/O,
  942. a shell command, or anything else that takes
  943. time). Example: >lua
  944. -- Query the terminal palette for the RGB value of color 1
  945. -- (red) using OSC 4
  946. vim.api.nvim_create_autocmd('TermResponse', {
  947. once = true,
  948. callback = function(args)
  949. local resp = args.data
  950. local r, g, b = resp:match("\027%]4;1;rgb:(%w+)/(%w+)/(%w+)")
  951. end,
  952. })
  953. io.stdout:write("\027]4;1;?\027\\")
  954. <
  955. *TextChanged*
  956. TextChanged After a change was made to the text in the
  957. current buffer in Normal mode. That is after
  958. |b:changedtick| has changed (also when that
  959. happened before the TextChanged autocommand
  960. was defined).
  961. Not triggered when there is typeahead or when
  962. an operator is pending.
  963. Note: Cannot be skipped with `:noautocmd`.
  964. Careful: This is triggered very often, don't
  965. do anything that the user does not expect or
  966. that is slow.
  967. *TextChangedI*
  968. TextChangedI After a change was made to the text in the
  969. current buffer in Insert mode.
  970. Not triggered when the popup menu is visible.
  971. Otherwise the same as TextChanged.
  972. *TextChangedP*
  973. TextChangedP After a change was made to the text in the
  974. current buffer in Insert mode, only when the
  975. popup menu is visible. Otherwise the same as
  976. TextChanged.
  977. *TextChangedT*
  978. TextChangedT After a change was made to the text in the
  979. current buffer in |Terminal-mode|. Otherwise
  980. the same as TextChanged.
  981. *TextYankPost*
  982. TextYankPost Just after a |yank| or |deleting| command, but not
  983. if the black hole register |quote_| is used nor
  984. for |setreg()|. Pattern must be "*".
  985. Sets these |v:event| keys:
  986. inclusive
  987. operator
  988. regcontents
  989. regname
  990. regtype
  991. visual
  992. The `inclusive` flag combined with the |'[|
  993. and |']| marks can be used to calculate the
  994. precise region of the operation.
  995. Non-recursive (event cannot trigger itself).
  996. Cannot change the text. |textlock|
  997. *User*
  998. User Not executed automatically. Use |:doautocmd|
  999. to trigger this, typically for "custom events"
  1000. in a plugin. Example: >
  1001. :autocmd User MyPlugin echom 'got MyPlugin event'
  1002. :doautocmd User MyPlugin
  1003. < *UserGettingBored*
  1004. UserGettingBored When the user presses the same key 42 times.
  1005. Just kidding! :-)
  1006. *VimEnter*
  1007. VimEnter After doing all the startup stuff, including
  1008. loading vimrc files, executing the "-c cmd"
  1009. arguments, creating all windows and loading
  1010. the buffers in them.
  1011. Just before this event is triggered the
  1012. |v:vim_did_enter| variable is set, so that you
  1013. can do: >
  1014. if v:vim_did_enter
  1015. call s:init()
  1016. else
  1017. au VimEnter * call s:init()
  1018. endif
  1019. < *VimLeave*
  1020. VimLeave Before exiting Vim, just after writing the
  1021. .shada file. Executed only once, like
  1022. VimLeavePre.
  1023. Use |v:dying| to detect an abnormal exit.
  1024. Use |v:exiting| to get the exit code.
  1025. Not triggered if |v:dying| is 2 or more.
  1026. *VimLeavePre*
  1027. VimLeavePre Before exiting Vim, just before writing the
  1028. .shada file. This is executed only once,
  1029. if there is a match with the name of what
  1030. happens to be the current buffer when exiting.
  1031. Mostly useful with a "*" pattern. >
  1032. :autocmd VimLeavePre * call CleanupStuff()
  1033. < Use |v:dying| to detect an abnormal exit.
  1034. Use |v:exiting| to get the exit code.
  1035. Not triggered if |v:dying| is 2 or more.
  1036. *VimResized*
  1037. VimResized After the Vim window was resized, thus 'lines'
  1038. and/or 'columns' changed. Not when starting
  1039. up though.
  1040. *VimResume*
  1041. VimResume After Nvim resumes from |suspend| state.
  1042. *VimSuspend*
  1043. VimSuspend Before Nvim enters |suspend| state.
  1044. *WinClosed*
  1045. WinClosed When closing a window, just before it is
  1046. removed from the window layout. The pattern
  1047. is matched against the |window-ID|. Both
  1048. <amatch> and <afile> are set to the |window-ID|.
  1049. After WinLeave.
  1050. Non-recursive (event cannot trigger itself).
  1051. See also |ExitPre|, |QuitPre|.
  1052. *WinEnter*
  1053. WinEnter After entering another window. Not done for
  1054. the first window, when Vim has just started.
  1055. Useful for setting the window height.
  1056. If the window is for another buffer, Vim
  1057. executes the BufEnter autocommands after the
  1058. WinEnter autocommands.
  1059. Note: For split and tabpage commands the
  1060. WinEnter event is triggered after the split
  1061. or tab command but before the file is loaded.
  1062. *WinLeave*
  1063. WinLeave Before leaving a window. If the window to be
  1064. entered next is for a different buffer, Vim
  1065. executes the BufLeave autocommands before the
  1066. WinLeave autocommands (but not for ":new").
  1067. Not used for ":qa" or ":q" when exiting Vim.
  1068. Before WinClosed.
  1069. *WinNew*
  1070. WinNew When a new window was created. Not done for
  1071. the first window, when Vim has just started.
  1072. Before WinEnter.
  1073. *WinScrolled*
  1074. WinScrolled After any window in the current tab page
  1075. scrolled the text (horizontally or vertically)
  1076. or changed width or height. See
  1077. |win-scrolled-resized|.
  1078. The pattern is matched against the |window-ID|
  1079. of the first window that scrolled or resized.
  1080. Both <amatch> and <afile> are set to the
  1081. |window-ID|.
  1082. |v:event| is set with information about size
  1083. and scroll changes. |WinScrolled-event|
  1084. Only starts triggering after startup finished
  1085. and the first screen redraw was done.
  1086. Does not trigger when defining the first
  1087. WinScrolled or WinResized event, but may
  1088. trigger when adding more.
  1089. Non-recursive: the event will not trigger
  1090. while executing commands for the WinScrolled
  1091. event. However, if the command causes a
  1092. window to scroll or change size, then another
  1093. WinScrolled event will be triggered later.
  1094. *WinResized*
  1095. WinResized After a window in the current tab page changed
  1096. width or height.
  1097. See |win-scrolled-resized|.
  1098. |v:event| is set with information about size
  1099. changes. |WinResized-event|
  1100. Same behavior as |WinScrolled| for the
  1101. pattern, triggering and recursiveness.
  1102. ==============================================================================
  1103. 6. Patterns *autocmd-pattern* *{aupat}*
  1104. The {aupat} argument of `:autocmd` can be a comma-separated list. This works as
  1105. if the command was given with each pattern separately. Thus this command: >
  1106. :autocmd BufRead *.txt,*.info set et
  1107. Is equivalent to: >
  1108. :autocmd BufRead *.txt set et
  1109. :autocmd BufRead *.info set et
  1110. The file pattern {aupat} is tested for a match against the file name in one of
  1111. two ways:
  1112. 1. When there is no '/' in the pattern, Vim checks for a match against only
  1113. the tail part of the file name (without its leading directory path).
  1114. 2. When there is a '/' in the pattern, Vim checks for a match against both the
  1115. short file name (as you typed it) and the full file name (after expanding
  1116. it to a full path and resolving symbolic links).
  1117. The special pattern <buffer> or <buffer=N> is used for buffer-local
  1118. autocommands |autocmd-buflocal|. This pattern is not matched against the name
  1119. of a buffer.
  1120. Examples: >
  1121. :autocmd BufRead *.txt set et
  1122. Set the 'et' option for all text files. >
  1123. :autocmd BufRead /vim/src/*.c set cindent
  1124. Set the 'cindent' option for C files in the /vim/src directory. >
  1125. :autocmd BufRead /tmp/*.c set ts=5
  1126. If you have a link from "/tmp/test.c" to "/home/nobody/vim/src/test.c", and
  1127. you start editing "/tmp/test.c", this autocommand will match.
  1128. Note: To match part of a path, but not from the root directory, use a "*" as
  1129. the first character. Example: >
  1130. :autocmd BufRead */doc/*.txt set tw=78
  1131. This autocommand will for example be executed for "/tmp/doc/xx.txt" and
  1132. "/usr/home/piet/doc/yy.txt". The number of directories does not matter here.
  1133. The file name that the pattern is matched against is after expanding
  1134. wildcards. Thus if you issue this command: >
  1135. :e $ROOTDIR/main.$EXT
  1136. The argument is first expanded to: >
  1137. /usr/root/main.py
  1138. Before it's matched with the pattern of the autocommand. Careful with this
  1139. when using events like FileReadCmd, the value of <amatch> may not be what you
  1140. expect.
  1141. Environment variables can be used in a pattern: >
  1142. :autocmd BufRead $VIMRUNTIME/doc/*.txt set expandtab
  1143. And ~ can be used for the home directory (if $HOME is defined): >
  1144. :autocmd BufWritePost ~/.config/nvim/init.vim so <afile>
  1145. :autocmd BufRead ~archive/* set readonly
  1146. The environment variable is expanded when the autocommand is defined, not when
  1147. the autocommand is executed. This is different from the command!
  1148. *file-pattern*
  1149. The pattern is interpreted like mostly used in file names:
  1150. * matches any sequence of characters; Unusual: includes path
  1151. separators
  1152. ? matches any single character
  1153. \? matches a '?'
  1154. . matches a '.'
  1155. ~ matches a '~'
  1156. , separates patterns
  1157. \, matches a ','
  1158. { } like \( \) in a |pattern|
  1159. , inside { }: like \| in a |pattern|
  1160. \} literal }
  1161. \{ literal {
  1162. \\\{n,m\} like \{n,m} in a |pattern|
  1163. \ special meaning like in a |pattern|
  1164. [ch] matches 'c' or 'h'
  1165. [^ch] match any character but 'c' and 'h'
  1166. Note that for all systems the '/' character is used for path separator (even
  1167. Windows). This was done because the backslash is difficult to use in a pattern
  1168. and to make the autocommands portable across different systems.
  1169. It is possible to use |pattern| items, but they may not work as expected,
  1170. because of the translation done for the above.
  1171. *autocmd-changes*
  1172. Matching with the pattern is done when an event is triggered. Changing the
  1173. buffer name in one of the autocommands, or even deleting the buffer, does not
  1174. change which autocommands will be executed. Example: >
  1175. au BufEnter *.foo bdel
  1176. au BufEnter *.foo set modified
  1177. This will delete the current buffer and then set 'modified' in what has become
  1178. the current buffer instead. Vim doesn't take into account that "*.foo"
  1179. doesn't match with that buffer name. It matches "*.foo" with the name of the
  1180. buffer at the moment the event was triggered.
  1181. However, buffer-local autocommands will not be executed for a buffer that has
  1182. been wiped out with |:bwipe|. After deleting the buffer with |:bdel| the
  1183. buffer actually still exists (it becomes unlisted), thus the autocommands are
  1184. still executed.
  1185. ==============================================================================
  1186. 7. Buffer-local autocommands *autocmd-buflocal* *autocmd-buffer-local*
  1187. *<buffer>* *<buffer=N>* *<buffer=abuf>* *E680*
  1188. Buffer-local autocommands are attached to a specific buffer. They are useful
  1189. if the buffer does not have a name and when the name does not match a specific
  1190. pattern. But it also means they must be explicitly added to each buffer.
  1191. Instead of a pattern buffer-local autocommands use one of these forms:
  1192. <buffer> current buffer
  1193. <buffer=99> buffer number 99
  1194. <buffer=abuf> using <abuf> (only when executing autocommands)
  1195. |<abuf>|
  1196. Examples: >
  1197. :au CursorHold <buffer> echo 'hold'
  1198. :au CursorHold <buffer=33> echo 'hold'
  1199. :au BufNewFile * au CursorHold <buffer=abuf> echo 'hold'
  1200. All the commands for autocommands also work with buffer-local autocommands,
  1201. simply use the special string instead of the pattern. Examples: >
  1202. :au! * <buffer> " remove buffer-local autocommands for
  1203. " current buffer
  1204. :au! * <buffer=33> " remove buffer-local autocommands for
  1205. " buffer #33
  1206. :bufdo :au! CursorHold <buffer> " remove autocmd for given event for all
  1207. " buffers
  1208. :au * <buffer> " list buffer-local autocommands for
  1209. " current buffer
  1210. Note that when an autocommand is defined for the current buffer, it is stored
  1211. with the buffer number. Thus it uses the form "<buffer=12>", where 12 is the
  1212. number of the current buffer. You will see this when listing autocommands,
  1213. for example.
  1214. To test for presence of buffer-local autocommands use the |exists()| function
  1215. as follows: >
  1216. :if exists("#CursorHold#<buffer=12>") | ... | endif
  1217. :if exists("#CursorHold#<buffer>") | ... | endif " for current buffer
  1218. When a buffer is wiped out its buffer-local autocommands are also gone, of
  1219. course. Note that when deleting a buffer, e.g., with ":bdel", it is only
  1220. unlisted, the autocommands are still present. In order to see the removal of
  1221. buffer-local autocommands: >
  1222. :set verbose=6
  1223. It is not possible to define buffer-local autocommands for a non-existent
  1224. buffer.
  1225. ==============================================================================
  1226. 8. Groups *autocmd-groups*
  1227. Autocommands can be put together in a group. This is useful for removing or
  1228. executing a group of autocommands. For example, all the autocommands for
  1229. syntax highlighting are put in the "highlight" group, to be able to execute
  1230. ":doautoall highlight BufRead" when the GUI starts.
  1231. When no specific group is selected, Vim uses the default group. The default
  1232. group does not have a name. You cannot execute the autocommands from the
  1233. default group separately; you can execute them only by executing autocommands
  1234. for all groups.
  1235. Normally, when executing autocommands automatically, Vim uses the autocommands
  1236. for all groups. The group only matters when executing autocommands with
  1237. ":doautocmd" or ":doautoall", or when defining or deleting autocommands.
  1238. The group name can contain any characters except white space. The group name
  1239. "end" is reserved (also in uppercase).
  1240. The group name is case sensitive. Note that this is different from the event
  1241. name!
  1242. *:aug* *:augroup*
  1243. :aug[roup] {name} Define the autocmd group name for the
  1244. following ":autocmd" commands. The name "end"
  1245. or "END" selects the default group.
  1246. To avoid confusion, the name should be
  1247. different from existing {event} names, as this
  1248. most likely will not do what you intended.
  1249. *:augroup-delete* *E367* *W19* *E936*
  1250. :aug[roup]! {name} Delete the autocmd group {name}. Don't use
  1251. this if there is still an autocommand using
  1252. this group! You will get a warning if doing
  1253. it anyway. When the group is the current
  1254. group you will get error E936.
  1255. To enter autocommands for a specific group, use this method:
  1256. 1. Select the group with ":augroup {name}".
  1257. 2. Delete any old autocommands with ":au!".
  1258. 3. Define the autocommands.
  1259. 4. Go back to the default group with "augroup END".
  1260. Example: >
  1261. :augroup uncompress
  1262. : au!
  1263. : au BufEnter *.gz %!gunzip
  1264. :augroup END
  1265. This prevents having the autocommands defined twice (e.g., after sourcing the
  1266. vimrc file again).
  1267. *FileExplorer*
  1268. There is one group that is recognized by Vim: FileExplorer. If this group
  1269. exists Vim assumes that editing a directory is possible and will trigger a
  1270. plugin that lists the files in that directory. This is used by the |netrw|
  1271. plugin. This allows you to do: >
  1272. browse edit
  1273. ==============================================================================
  1274. 9. Executing autocommands *autocmd-execute*
  1275. Vim can also execute Autocommands non-automatically. This is useful if you
  1276. have changed autocommands, or when Vim has executed the wrong autocommands
  1277. (e.g., the file pattern match was wrong).
  1278. Note that the 'eventignore' option applies here too. Events listed in this
  1279. option will not cause any commands to be executed.
  1280. *:do* *:doau* *:doaut* *:doautocmd* *E217*
  1281. :do[autocmd] [<nomodeline>] [group] {event} [fname]
  1282. Apply the autocommands matching [fname] (default:
  1283. current file name) for {event} to the current buffer.
  1284. You can use this when the current file name does not
  1285. match the right pattern, after changing settings, or
  1286. to execute autocommands for a certain event.
  1287. It's possible to use this inside an autocommand too,
  1288. so you can base the autocommands for one extension on
  1289. another extension. Example: >
  1290. :au BufEnter *.cpp so ~/.config/nvim/init_cpp.vim
  1291. :au BufEnter *.cpp doau BufEnter x.c
  1292. < Be careful to avoid endless loops. |autocmd-nested|
  1293. When the [group] argument is not given, Vim executes
  1294. the autocommands for all groups. When the [group]
  1295. argument is included, Vim executes only the matching
  1296. autocommands for that group. Undefined group is an
  1297. error.
  1298. *<nomodeline>*
  1299. After applying the autocommands the modelines are
  1300. processed, so that their settings overrule the
  1301. settings from autocommands when editing a file. This
  1302. is skipped if <nomodeline> is specified. You probably
  1303. want to use <nomodeline> for events not used when
  1304. loading a buffer, such as |User|.
  1305. Modelines are also skipped when no matching
  1306. autocommands were executed.
  1307. *:doautoa* *:doautoall*
  1308. :doautoa[ll] [<nomodeline>] [group] {event} [fname]
  1309. Like ":doautocmd", but apply the autocommands to each
  1310. loaded buffer. The current buffer is done last.
  1311. Note that [fname] is used to select the autocommands,
  1312. not the buffers to which they are applied. Example: >
  1313. augroup mine
  1314. autocmd!
  1315. autocmd FileType * echo expand('<amatch>')
  1316. augroup END
  1317. doautoall mine FileType Loaded-Buffer
  1318. < Sourcing this script, you'll see as many
  1319. "Loaded-Buffer" echoed as there are loaded buffers.
  1320. Careful: Don't use this for autocommands that delete a
  1321. buffer, change to another buffer or change the
  1322. contents of a buffer; the result is unpredictable.
  1323. This command is intended for autocommands that set
  1324. options, change highlighting, and things like that.
  1325. ==============================================================================
  1326. 10. Using autocommands *autocmd-use*
  1327. For WRITING FILES there are four possible sets of events. Vim uses only one
  1328. of these sets for a write command:
  1329. BufWriteCmd BufWritePre BufWritePost writing the whole buffer
  1330. FilterWritePre FilterWritePost writing to filter temp file
  1331. FileAppendCmd FileAppendPre FileAppendPost appending to a file
  1332. FileWriteCmd FileWritePre FileWritePost any other file write
  1333. When there is a matching "*Cmd" autocommand, it is assumed it will do the
  1334. writing. No further writing is done and the other events are not triggered.
  1335. |Cmd-event|
  1336. Note that the "*WritePost" commands should undo any changes to the buffer that
  1337. were caused by the "*WritePre" commands; otherwise, writing the file will have
  1338. the side effect of changing the buffer.
  1339. Before executing the autocommands, the buffer from which the lines are to be
  1340. written temporarily becomes the current buffer. Unless the autocommands
  1341. change the current buffer or delete the previously current buffer, the
  1342. previously current buffer is made the current buffer again.
  1343. The "*WritePre" and "*AppendPre" autocommands must not delete the buffer from
  1344. which the lines are to be written.
  1345. The '[ and '] marks have a special position:
  1346. - Before the "*ReadPre" event the '[ mark is set to the line just above where
  1347. the new lines will be inserted.
  1348. - Before the "*ReadPost" event the '[ mark is set to the first line that was
  1349. just read, the '] mark to the last line.
  1350. - Before executing the "*WriteCmd", "*WritePre" and "*AppendPre" autocommands the '[
  1351. mark is set to the first line that will be written, the '] mark to the last
  1352. line.
  1353. Careful: '[ and '] change when using commands that change the buffer.
  1354. In commands which expect a file name, you can use "<afile>" for the file name
  1355. that is being read |:<afile>| (you can also use "%" for the current file
  1356. name). "<abuf>" can be used for the buffer number of the currently effective
  1357. buffer. This also works for buffers that don't have a name. But it doesn't
  1358. work for files without a buffer (e.g., with ":r file").
  1359. *gzip-example*
  1360. Examples for reading and writing compressed files: >
  1361. :augroup gzip
  1362. : autocmd!
  1363. : autocmd BufReadPre,FileReadPre *.gz set bin
  1364. : autocmd BufReadPost,FileReadPost *.gz '[,']!gunzip
  1365. : autocmd BufReadPost,FileReadPost *.gz set nobin
  1366. : autocmd BufReadPost,FileReadPost *.gz execute ":doautocmd BufReadPost " .. expand("%:r")
  1367. : autocmd BufWritePost,FileWritePost *.gz !mv <afile> <afile>:r
  1368. : autocmd BufWritePost,FileWritePost *.gz !gzip <afile>:r
  1369. : autocmd FileAppendPre *.gz !gunzip <afile>
  1370. : autocmd FileAppendPre *.gz !mv <afile>:r <afile>
  1371. : autocmd FileAppendPost *.gz !mv <afile> <afile>:r
  1372. : autocmd FileAppendPost *.gz !gzip <afile>:r
  1373. :augroup END
  1374. The "gzip" group is used to be able to delete any existing autocommands with
  1375. ":autocmd!", for when the file is sourced twice.
  1376. ("<afile>:r" is the file name without the extension, see |:_%:|)
  1377. The commands executed for the BufNewFile, BufRead/BufReadPost, BufWritePost,
  1378. FileAppendPost and VimLeave events do not set or reset the changed flag of the
  1379. buffer. When you decompress the buffer with the BufReadPost autocommands, you
  1380. can still exit with ":q". When you use ":undo" in BufWritePost to undo the
  1381. changes made by BufWritePre commands, you can still do ":q" (this also makes
  1382. "ZZ" work). If you do want the buffer to be marked as modified, set the
  1383. 'modified' option.
  1384. To execute Normal mode commands from an autocommand, use the ":normal"
  1385. command. Use with care! If the Normal mode command is not finished, the user
  1386. needs to type characters (e.g., after ":normal m" you need to type a mark
  1387. name).
  1388. If you want the buffer to be unmodified after changing it, reset the
  1389. 'modified' option. This makes it possible to exit the buffer with ":q"
  1390. instead of ":q!".
  1391. *autocmd-nested* *E218*
  1392. By default, autocommands do not nest. For example, if you use ":e" or ":w" in
  1393. an autocommand, Vim does not execute the BufRead and BufWrite autocommands for
  1394. those commands. If you do want this, use the "++nested" flag for those
  1395. commands in which you want nesting. For example: >
  1396. :autocmd FileChangedShell *.c ++nested e!
  1397. The nesting is limited to 10 levels to get out of recursive loops.
  1398. It's possible to use the ":au" command in an autocommand. This can be a
  1399. self-modifying command! This can be useful for an autocommand that should
  1400. execute only once.
  1401. If you want to skip autocommands for one command, use the |:noautocmd| command
  1402. modifier or the 'eventignore' option.
  1403. Note: When reading a file (with ":read file" or with a filter command) and the
  1404. last line in the file does not have an <EOL>, Vim remembers this. At the next
  1405. write (with ":write file" or with a filter command), if the same line is
  1406. written again as the last line in a file AND 'binary' is set, Vim does not
  1407. supply an <EOL>. This makes a filter command on the just read lines write the
  1408. same file as was read, and makes a write command on just filtered lines write
  1409. the same file as was read from the filter. For example, another way to write
  1410. a compressed file: >
  1411. :autocmd FileWritePre *.gz set bin|'[,']!gzip
  1412. :autocmd FileWritePost *.gz undo|set nobin
  1413. <
  1414. *autocommand-pattern*
  1415. You can specify multiple patterns, separated by commas. Here are some
  1416. examples: >
  1417. :autocmd BufRead * set tw=79 nocin ic infercase fo=2croq
  1418. :autocmd BufRead .letter set tw=72 fo=2tcrq
  1419. :autocmd BufEnter .letter set dict=/usr/lib/dict/words
  1420. :autocmd BufLeave .letter set dict=
  1421. :autocmd BufRead,BufNewFile *.c,*.h set tw=0 cin noic
  1422. :autocmd BufEnter *.c,*.h abbr FOR for (i = 0; i < 3; ++i)<CR>{<CR>}<Esc>O
  1423. :autocmd BufLeave *.c,*.h unabbr FOR
  1424. For makefiles (makefile, Makefile, imakefile, makefile.unix, etc.): >
  1425. :autocmd BufEnter ?akefile* set include=^s\=include
  1426. :autocmd BufLeave ?akefile* set include&
  1427. To always start editing C files at the first function: >
  1428. :autocmd BufRead *.c,*.h 1;/^{
  1429. Without the "1;" above, the search would start from wherever the file was
  1430. entered, rather than from the start of the file.
  1431. *skeleton* *template*
  1432. To read a skeleton (template) file when opening a new file: >
  1433. :autocmd BufNewFile *.c 0r ~/vim/skeleton.c
  1434. :autocmd BufNewFile *.h 0r ~/vim/skeleton.h
  1435. :autocmd BufNewFile *.java 0r ~/vim/skeleton.java
  1436. To insert the current date and time in a "*.html" file when writing it: >
  1437. :autocmd BufWritePre,FileWritePre *.html ks|call LastMod()|'s
  1438. :fun LastMod()
  1439. : if line("$") > 20
  1440. : let l = 20
  1441. : else
  1442. : let l = line("$")
  1443. : endif
  1444. : exe "1," .. l .. "g/Last modified: /s/Last modified: .*/Last modified: " ..
  1445. : \ strftime("%Y %b %d")
  1446. :endfun
  1447. You need to have a line "Last modified: <date time>" in the first 20 lines
  1448. of the file for this to work. Vim replaces <date time> (and anything in the
  1449. same line after it) with the current date and time. Explanation:
  1450. ks mark current position with mark 's'
  1451. call LastMod() call the LastMod() function to do the work
  1452. 's return the cursor to the old position
  1453. The LastMod() function checks if the file is shorter than 20 lines, and then
  1454. uses the ":g" command to find lines that contain "Last modified: ". For those
  1455. lines the ":s" command is executed to replace the existing date with the
  1456. current one. The ":execute" command is used to be able to use an expression
  1457. for the ":g" and ":s" commands. The date is obtained with the strftime()
  1458. function. You can change its argument to get another date string.
  1459. When entering :autocmd on the command-line, completion of events and command
  1460. names may be done (with <Tab>, CTRL-D, etc.) where appropriate.
  1461. Vim executes all matching autocommands in the order that you specify them.
  1462. It is recommended that your first autocommand be used for all files by using
  1463. "*" as the file pattern. This means that you can define defaults you like
  1464. here for any settings, and if there is another matching autocommand it will
  1465. override these. But if there is no other matching autocommand, then at least
  1466. your default settings are recovered (if entering this file from another for
  1467. which autocommands did match). Note that "*" will also match files starting
  1468. with ".", unlike Unix shells.
  1469. *autocmd-searchpat*
  1470. Autocommands do not change the current search patterns. Vim saves the current
  1471. search patterns before executing autocommands then restores them after the
  1472. autocommands finish. This means that autocommands do not affect the strings
  1473. highlighted with the 'hlsearch' option. Within autocommands, you can still
  1474. use search patterns normally, e.g., with the "n" command.
  1475. If you want an autocommand to set the search pattern, such that it is used
  1476. after the autocommand finishes, use the ":let @/ =" command.
  1477. The search-highlighting cannot be switched off with ":nohlsearch" in an
  1478. autocommand. Use the 'h' flag in the 'shada' option to disable search-
  1479. highlighting when starting Vim.
  1480. *Cmd-event*
  1481. When using one of the "*Cmd" events, the matching autocommands are expected to
  1482. do the file reading, writing or sourcing. This can be used when working with
  1483. a special kind of file, for example on a remote system.
  1484. CAREFUL: If you use these events in a wrong way, it may have the effect of
  1485. making it impossible to read or write the matching files! Make sure you test
  1486. your autocommands properly. Best is to use a pattern that will never match a
  1487. normal file name, for example "ftp://*".
  1488. When defining a BufReadCmd it will be difficult for Vim to recover a crashed
  1489. editing session. When recovering from the original file, Vim reads only those
  1490. parts of a file that are not found in the swap file. Since that is not
  1491. possible with a BufReadCmd, use the |:preserve| command to make sure the
  1492. original file isn't needed for recovery. You might want to do this only when
  1493. you expect the file to be modified.
  1494. For file read and write commands the |v:cmdarg| variable holds the "++enc="
  1495. and "++ff=" argument that are effective. These should be used for the command
  1496. that reads/writes the file. The |v:cmdbang| variable is one when "!" was
  1497. used, zero otherwise.
  1498. See the $VIMRUNTIME/plugin/netrwPlugin.vim for examples.
  1499. ==============================================================================
  1500. 11. Disabling autocommands *autocmd-disable*
  1501. To disable autocommands for some time use the 'eventignore' option. Note that
  1502. this may cause unexpected behavior, make sure you restore 'eventignore'
  1503. afterwards, using a |:try| block with |:finally|.
  1504. *:noautocmd* *:noa*
  1505. To disable autocommands for just one command use the ":noautocmd" command
  1506. modifier. This will set 'eventignore' to "all" for the duration of the
  1507. following command. Example: >
  1508. :noautocmd w fname.gz
  1509. This will write the file without triggering the autocommands defined by the
  1510. gzip plugin.
  1511. Note that some autocommands are not triggered right away, but only later.
  1512. This specifically applies to |CursorMoved| and |TextChanged|.
  1513. vim:tw=78:ts=8:noet:ft=help:norl: