quickfix.txt 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996
  1. *quickfix.txt* Nvim
  2. VIM REFERENCE MANUAL by Bram Moolenaar
  3. This subject is introduced in section |30.1| of the user manual.
  4. Type |gO| to see the table of contents.
  5. =============================================================================
  6. 1. Using QuickFix commands *quickfix* *Quickfix* *E42*
  7. Vim has a special mode to speedup the edit-compile-edit cycle. This is
  8. inspired by the quickfix option of the Manx's Aztec C compiler on the Amiga.
  9. The idea is to save the error messages from the compiler in a file and use Vim
  10. to jump to the errors one by one. You can examine each problem and fix it,
  11. without having to remember all the error messages.
  12. In Vim the quickfix commands are used more generally to find a list of
  13. positions in files. For example, |:vimgrep| finds pattern matches. You can
  14. use the positions in a script with the |getqflist()| function. Thus you can
  15. do a lot more than the edit/compile/fix cycle!
  16. If you have the error messages in a file you can start Vim with: >
  17. vim -q filename
  18. From inside Vim an easy way to run a command and handle the output is with the
  19. |:make| command (see below).
  20. The 'errorformat' option should be set to match the error messages from your
  21. compiler (see |errorformat| below).
  22. *quickfix-ID*
  23. Each quickfix list has a unique identifier called the quickfix ID and this
  24. number will not change within a Vim session. The |getqflist()| function can be
  25. used to get the identifier assigned to a list. There is also a quickfix list
  26. number which may change whenever more than ten lists are added to a quickfix
  27. stack.
  28. *location-list* *E776*
  29. A location list is a window-local quickfix list. You get one after commands
  30. like `:lvimgrep`, `:lgrep`, `:lhelpgrep`, `:lmake`, etc., which create a
  31. location list instead of a quickfix list as the corresponding `:vimgrep`,
  32. `:grep`, `:helpgrep`, `:make` do.
  33. *location-list-file-window*
  34. A location list is associated with a window and each window can have a
  35. separate location list. A location list can be associated with only one
  36. window. The location list is independent of the quickfix list.
  37. When a window with a location list is split, the new window gets a copy of the
  38. location list. When there are no longer any references to a location list,
  39. the location list is destroyed.
  40. *quickfix-changedtick*
  41. Every quickfix and location list has a read-only changedtick variable that
  42. tracks the total number of changes made to the list. Every time the quickfix
  43. list is modified, this count is incremented. This can be used to perform an
  44. action only when the list has changed. The |getqflist()| and |getloclist()|
  45. functions can be used to query the current value of changedtick. You cannot
  46. change the changedtick variable.
  47. The following quickfix commands can be used. The location list commands are
  48. similar to the quickfix commands, replacing the 'c' prefix in the quickfix
  49. command with 'l'.
  50. *E924*
  51. If the current window was closed by an |autocommand| while processing a
  52. location list command, it will be aborted.
  53. *E925* *E926*
  54. If the current quickfix or location list was changed by an |autocommand| while
  55. processing a quickfix or location list command, it will be aborted.
  56. *:cc*
  57. :cc[!] [nr] Display error [nr]. If [nr] is omitted, the same
  58. :[nr]cc[!] error is displayed again. Without [!] this doesn't
  59. work when jumping to another buffer, the current buffer
  60. has been changed, there is the only window for the
  61. buffer and both 'hidden' and 'autowrite' are off.
  62. When jumping to another buffer with [!] any changes to
  63. the current buffer are lost, unless 'hidden' is set or
  64. there is another window for this buffer.
  65. The 'switchbuf' settings are respected when jumping
  66. to a buffer.
  67. When used in the quickfix window the line number can
  68. be used, including "." for the current line and "$"
  69. for the last line.
  70. *:ll*
  71. :ll[!] [nr] Same as ":cc", except the location list for the
  72. :[nr]ll[!] current window is used instead of the quickfix list.
  73. *:cn* *:cne* *:cnext* *E553*
  74. :[count]cn[ext][!] Display the [count] next error in the list that
  75. includes a file name. If there are no file names at
  76. all, go to the [count] next error. See |:cc| for
  77. [!] and 'switchbuf'.
  78. *:lne* *:lnext*
  79. :[count]lne[xt][!] Same as ":cnext", except the location list for the
  80. current window is used instead of the quickfix list.
  81. :[count]cN[ext][!] *:cp* *:cprevious* *:cprev* *:cN* *:cNext*
  82. :[count]cp[revious][!] Display the [count] previous error in the list that
  83. includes a file name. If there are no file names at
  84. all, go to the [count] previous error. See |:cc| for
  85. [!] and 'switchbuf'.
  86. :[count]lN[ext][!] *:lp* *:lprevious* *:lprev* *:lN* *:lNext*
  87. :[count]lp[revious][!] Same as ":cNext" and ":cprevious", except the location
  88. list for the current window is used instead of the
  89. quickfix list.
  90. *:cabo* *:cabove*
  91. :[count]cabo[ve] Go to the [count] error above the current line in the
  92. current buffer. If [count] is omitted, then 1 is
  93. used. If there are no errors, then an error message
  94. is displayed. Assumes that the entries in a quickfix
  95. list are sorted by their buffer number and line
  96. number. If there are multiple errors on the same line,
  97. then only the first entry is used. If [count] exceeds
  98. the number of entries above the current line, then the
  99. first error in the file is selected.
  100. *:lab* *:labove*
  101. :[count]lab[ove] Same as ":cabove", except the location list for the
  102. current window is used instead of the quickfix list.
  103. *:cbel* *:cbelow*
  104. :[count]cbel[ow] Go to the [count] error below the current line in the
  105. current buffer. If [count] is omitted, then 1 is
  106. used. If there are no errors, then an error message
  107. is displayed. Assumes that the entries in a quickfix
  108. list are sorted by their buffer number and line
  109. number. If there are multiple errors on the same
  110. line, then only the first entry is used. If [count]
  111. exceeds the number of entries below the current line,
  112. then the last error in the file is selected.
  113. *:lbel* *:lbelow*
  114. :[count]lbel[ow] Same as ":cbelow", except the location list for the
  115. current window is used instead of the quickfix list.
  116. *:cbe* *:cbefore*
  117. :[count]cbe[fore] Go to the [count] error before the current cursor
  118. position in the current buffer. If [count] is
  119. omitted, then 1 is used. If there are no errors, then
  120. an error message is displayed. Assumes that the
  121. entries in a quickfix list are sorted by their buffer,
  122. line and column numbers. If [count] exceeds the
  123. number of entries before the current position, then
  124. the first error in the file is selected.
  125. *:lbe* *:lbefore*
  126. :[count]lbe[fore] Same as ":cbefore", except the location list for the
  127. current window is used instead of the quickfix list.
  128. *:caf* *:cafter*
  129. :[count]caf[ter] Go to the [count] error after the current cursor
  130. position in the current buffer. If [count] is
  131. omitted, then 1 is used. If there are no errors, then
  132. an error message is displayed. Assumes that the
  133. entries in a quickfix list are sorted by their buffer,
  134. line and column numbers. If [count] exceeds the
  135. number of entries after the current position, then
  136. the last error in the file is selected.
  137. *:laf* *:lafter*
  138. :[count]laf[ter] Same as ":cafter", except the location list for the
  139. current window is used instead of the quickfix list.
  140. *:cnf* *:cnfile*
  141. :[count]cnf[ile][!] Display the first error in the [count] next file in
  142. the list that includes a file name. If there are no
  143. file names at all or if there is no next file, go to
  144. the [count] next error. See |:cc| for [!] and
  145. 'switchbuf'.
  146. *:lnf* *:lnfile*
  147. :[count]lnf[ile][!] Same as ":cnfile", except the location list for the
  148. current window is used instead of the quickfix list.
  149. :[count]cNf[ile][!] *:cpf* *:cpfile* *:cNf* *:cNfile*
  150. :[count]cpf[ile][!] Display the last error in the [count] previous file in
  151. the list that includes a file name. If there are no
  152. file names at all or if there is no next file, go to
  153. the [count] previous error. See |:cc| for [!] and
  154. 'switchbuf'.
  155. :[count]lNf[ile][!] *:lpf* *:lpfile* *:lNf* *:lNfile*
  156. :[count]lpf[ile][!] Same as ":cNfile" and ":cpfile", except the location
  157. list for the current window is used instead of the
  158. quickfix list.
  159. *:crewind* *:cr*
  160. :cr[ewind][!] [nr] Display error [nr]. If [nr] is omitted, the FIRST
  161. error is displayed. See |:cc|.
  162. *:lrewind* *:lr*
  163. :lr[ewind][!] [nr] Same as ":crewind", except the location list for the
  164. current window is used instead of the quickfix list.
  165. *:cfirst* *:cfir*
  166. :cfir[st][!] [nr] Same as ":crewind".
  167. *:lfirst* *:lfir*
  168. :lfir[st][!] [nr] Same as ":lrewind".
  169. *:clast* *:cla*
  170. :cla[st][!] [nr] Display error [nr]. If [nr] is omitted, the LAST
  171. error is displayed. See |:cc|.
  172. *:llast* *:lla*
  173. :lla[st][!] [nr] Same as ":clast", except the location list for the
  174. current window is used instead of the quickfix list.
  175. *:cq* *:cquit*
  176. :cq[uit][!]
  177. :{N}cq[uit][!]
  178. :cq[uit][!] {N} Quit Vim with error code {N}. {N} defaults to one.
  179. Useful when Vim is called from another program:
  180. e.g., a compiler will not compile the same file again,
  181. `git commit` will abort the committing process, `fc`
  182. (built-in for shells like bash and zsh) will not
  183. execute the command, etc.
  184. {N} can also be zero, in which case Vim exits
  185. normally.
  186. WARNING: All changes in files are lost. It works like
  187. ":qall!" |:qall|, except that Nvim exits non-zero or
  188. [count].
  189. *:cf* *:cfi* *:cfile*
  190. :cf[ile][!] [errorfile] Read the error file and jump to the first error.
  191. This is done automatically when Vim is started with
  192. the -q option. You can use this command when you
  193. keep Vim running while compiling. If you give the
  194. name of the errorfile, the 'errorfile' option will
  195. be set to [errorfile]. See |:cc| for [!].
  196. If the encoding of the error file differs from the
  197. 'encoding' option, you can use the 'makeencoding'
  198. option to specify the encoding.
  199. *:lf* *:lfi* *:lfile*
  200. :lf[ile][!] [errorfile] Same as ":cfile", except the location list for the
  201. current window is used instead of the quickfix list.
  202. You can not use the -q command-line option to set
  203. the location list.
  204. :cg[etfile] [errorfile] *:cg* *:cgetfile*
  205. Read the error file. Just like ":cfile" but don't
  206. jump to the first error.
  207. If the encoding of the error file differs from the
  208. 'encoding' option, you can use the 'makeencoding'
  209. option to specify the encoding.
  210. :lg[etfile] [errorfile] *:lg* *:lge* *:lgetfile*
  211. Same as ":cgetfile", except the location list for the
  212. current window is used instead of the quickfix list.
  213. *:caddf* *:caddfile*
  214. :caddf[ile] [errorfile] Read the error file and add the errors from the
  215. errorfile to the current quickfix list. If a quickfix
  216. list is not present, then a new list is created.
  217. If the encoding of the error file differs from the
  218. 'encoding' option, you can use the 'makeencoding'
  219. option to specify the encoding.
  220. *:laddf* *:laddfile*
  221. :laddf[ile] [errorfile] Same as ":caddfile", except the location list for the
  222. current window is used instead of the quickfix list.
  223. *:cb* *:cbuffer* *E681*
  224. :cb[uffer][!] [bufnr] Read the error list from the current buffer.
  225. When [bufnr] is given it must be the number of a
  226. loaded buffer. That buffer will then be used instead
  227. of the current buffer.
  228. A range can be specified for the lines to be used.
  229. Otherwise all lines in the buffer are used.
  230. See |:cc| for [!].
  231. *:lb* *:lbuffer*
  232. :lb[uffer][!] [bufnr] Same as ":cbuffer", except the location list for the
  233. current window is used instead of the quickfix list.
  234. *:cgetb* *:cgetbuffer*
  235. :cgetb[uffer] [bufnr] Read the error list from the current buffer. Just
  236. like ":cbuffer" but don't jump to the first error.
  237. *:lgetb* *:lgetbuffer*
  238. :lgetb[uffer] [bufnr] Same as ":cgetbuffer", except the location list for
  239. the current window is used instead of the quickfix
  240. list.
  241. *:cad* *:cadd* *:caddbuffer*
  242. :cad[dbuffer] [bufnr] Read the error list from the current buffer and add
  243. the errors to the current quickfix list. If a
  244. quickfix list is not present, then a new list is
  245. created. Otherwise, same as ":cbuffer".
  246. *:laddb* *:laddbuffer*
  247. :laddb[uffer] [bufnr] Same as ":caddbuffer", except the location list for
  248. the current window is used instead of the quickfix
  249. list.
  250. *:cex* *:cexpr* *E777*
  251. :cex[pr][!] {expr} Create a quickfix list using the result of {expr} and
  252. jump to the first error.
  253. If {expr} is a String, then each newline terminated
  254. line in the String is processed using the global value
  255. of 'errorformat' and the result is added to the
  256. quickfix list.
  257. If {expr} is a List, then each String item in the list
  258. is processed and added to the quickfix list. Non
  259. String items in the List are ignored.
  260. See |:cc| for [!].
  261. Examples: >
  262. :cexpr system('grep -n xyz *')
  263. :cexpr getline(1, '$')
  264. <
  265. *:lex* *:lexpr*
  266. :lex[pr][!] {expr} Same as |:cexpr|, except the location list for the
  267. current window is used instead of the quickfix list.
  268. *:cgete* *:cgetexpr*
  269. :cgete[xpr] {expr} Create a quickfix list using the result of {expr}.
  270. Just like |:cexpr|, but don't jump to the first error.
  271. *:lgete* *:lgetexpr*
  272. :lgete[xpr] {expr} Same as |:cgetexpr|, except the location list for the
  273. current window is used instead of the quickfix list.
  274. *:cadde* *:caddexpr*
  275. :cadde[xpr] {expr} Evaluate {expr} and add the resulting lines to the
  276. current quickfix list. If a quickfix list is not
  277. present, then a new list is created. The current
  278. cursor position will not be changed. See |:cexpr| for
  279. more information.
  280. Example: >
  281. :g/mypattern/caddexpr expand("%") .. ":" .. line(".") .. ":" .. getline(".")
  282. <
  283. *:lad* *:addd* *:laddexpr*
  284. :lad[dexpr] {expr} Same as ":caddexpr", except the location list for the
  285. current window is used instead of the quickfix list.
  286. *:cl* *:clist*
  287. :cl[ist] [from] [, [to]]
  288. List all errors that are valid |quickfix-valid|.
  289. If numbers [from] and/or [to] are given, the respective
  290. range of errors is listed. A negative number counts
  291. from the last error backwards, -1 being the last error.
  292. The 'switchbuf' settings are respected when jumping
  293. to a buffer.
  294. The |:filter| command can be used to display only the
  295. quickfix entries matching a supplied pattern. The
  296. pattern is matched against the filename, module name,
  297. pattern and text of the entry.
  298. :cl[ist] +{count} List the current and next {count} valid errors. This
  299. is similar to ":clist from from+count", where "from"
  300. is the current error position.
  301. :cl[ist]! [from] [, [to]]
  302. List all errors.
  303. :cl[ist]! +{count} List the current and next {count} error lines. This
  304. is useful to see unrecognized lines after the current
  305. one. For example, if ":clist" shows:
  306. 8384 testje.java:252: error: cannot find symbol ~
  307. Then using ":cl! +3" shows the reason:
  308. 8384 testje.java:252: error: cannot find symbol ~
  309. 8385: ZexitCode = Fmainx(); ~
  310. 8386: ^ ~
  311. 8387: symbol: method Fmainx() ~
  312. :lli[st] [from] [, [to]] *:lli* *:llist*
  313. Same as ":clist", except the location list for the
  314. current window is used instead of the quickfix list.
  315. :lli[st]! [from] [, [to]]
  316. List all the entries in the location list for the
  317. current window.
  318. If you insert or delete lines, mostly the correct error location is still
  319. found because hidden marks are used. Sometimes, when the mark has been
  320. deleted for some reason, the message "line changed" is shown to warn you that
  321. the error location may not be correct. If you quit Vim and start again the
  322. marks are lost and the error locations may not be correct anymore.
  323. Two autocommands are available for running commands before and after a
  324. quickfix command (':make', ':grep' and so on) is executed. See
  325. |QuickFixCmdPre| and |QuickFixCmdPost| for details.
  326. *QuickFixCmdPost-example*
  327. When 'encoding' differs from the locale, the error messages may have a
  328. different encoding from what Vim is using. To convert the messages you can
  329. use this code: >
  330. function QfMakeConv()
  331. let qflist = getqflist()
  332. for i in qflist
  333. let i.text = iconv(i.text, "cp936", "utf-8")
  334. endfor
  335. call setqflist(qflist)
  336. endfunction
  337. au QuickfixCmdPost make call QfMakeConv()
  338. Another option is using 'makeencoding'.
  339. *quickfix-title*
  340. Every quickfix and location list has a title. By default the title is set to
  341. the command that created the list. The |getqflist()| and |getloclist()|
  342. functions can be used to get the title of a quickfix and a location list
  343. respectively. The |setqflist()| and |setloclist()| functions can be used to
  344. modify the title of a quickfix and location list respectively. Examples: >
  345. call setqflist([], 'a', {'title' : 'Cmd output'})
  346. echo getqflist({'title' : 1})
  347. call setloclist(3, [], 'a', {'title' : 'Cmd output'})
  348. echo getloclist(3, {'title' : 1})
  349. <
  350. *quickfix-index*
  351. When you jump to a quickfix/location list entry using any of the quickfix
  352. commands (e.g. |:cc|, |:cnext|, |:cprev|, etc.), that entry becomes the
  353. currently selected entry. The index of the currently selected entry in a
  354. quickfix/location list can be obtained using the getqflist()/getloclist()
  355. functions. Examples: >
  356. echo getqflist({'idx' : 0}).idx
  357. echo getqflist({'id' : qfid, 'idx' : 0}).idx
  358. echo getloclist(2, {'idx' : 0}).idx
  359. <
  360. For a new quickfix list, the first entry is selected and the index is 1. Any
  361. entry in any quickfix/location list can be set as the currently selected entry
  362. using the setqflist() function. Examples: >
  363. call setqflist([], 'a', {'idx' : 12})
  364. call setqflist([], 'a', {'id' : qfid, 'idx' : 7})
  365. call setloclist(1, [], 'a', {'idx' : 7})
  366. <
  367. *quickfix-size*
  368. You can get the number of entries (size) in a quickfix and a location list
  369. using the |getqflist()| and |getloclist()| functions respectively. Examples: >
  370. echo getqflist({'size' : 1})
  371. echo getloclist(5, {'size' : 1})
  372. <
  373. *quickfix-context*
  374. Any Vim type can be associated as a context with a quickfix or location list.
  375. The |setqflist()| and the |setloclist()| functions can be used to associate a
  376. context with a quickfix and a location list respectively. The |getqflist()|
  377. and the |getloclist()| functions can be used to retrieve the context of a
  378. quickfix and a location list respectively. This is useful for a Vim plugin
  379. dealing with multiple quickfix/location lists.
  380. Examples: >
  381. let somectx = {'name' : 'Vim', 'type' : 'Editor'}
  382. call setqflist([], 'a', {'context' : somectx})
  383. echo getqflist({'context' : 1})
  384. let newctx = ['red', 'green', 'blue']
  385. call setloclist(2, [], 'a', {'id' : qfid, 'context' : newctx})
  386. echo getloclist(2, {'id' : qfid, 'context' : 1})
  387. <
  388. *quickfix-parse*
  389. You can parse a list of lines using 'errorformat' without creating or
  390. modifying a quickfix list using the |getqflist()| function. Examples: >
  391. echo getqflist({'lines' : ["F1:10:Line10", "F2:20:Line20"]})
  392. echo getqflist({'lines' : systemlist('grep -Hn quickfix *')})
  393. This returns a dictionary where the "items" key contains the list of quickfix
  394. entries parsed from lines. The following shows how to use a custom
  395. 'errorformat' to parse the lines without modifying the 'errorformat' option: >
  396. echo getqflist({'efm' : '%f#%l#%m', 'lines' : ['F1#10#Line']})
  397. <
  398. EXECUTE A COMMAND IN ALL THE BUFFERS IN QUICKFIX OR LOCATION LIST:
  399. *:cdo*
  400. :cdo[!] {cmd} Execute {cmd} in each valid entry in the quickfix list.
  401. It works like doing this: >
  402. :cfirst
  403. :{cmd}
  404. :cnext
  405. :{cmd}
  406. etc.
  407. < When the current file can't be |abandon|ed and the [!]
  408. is not present, the command fails.
  409. When going to the next entry fails execution stops.
  410. The last buffer (or where an error occurred) becomes
  411. the current buffer.
  412. {cmd} can contain '|' to concatenate several commands.
  413. Only valid entries in the quickfix list are used.
  414. A range can be used to select entries, e.g.: >
  415. :10,$cdo cmd
  416. < To skip entries 1 to 9.
  417. Note: While this command is executing, the Syntax
  418. autocommand event is disabled by adding it to
  419. 'eventignore'. This considerably speeds up editing
  420. each buffer.
  421. Also see |:bufdo|, |:tabdo|, |:argdo|, |:windo|,
  422. |:ldo|, |:cfdo| and |:lfdo|.
  423. *:cfdo*
  424. :cfdo[!] {cmd} Execute {cmd} in each file in the quickfix list.
  425. It works like doing this: >
  426. :cfirst
  427. :{cmd}
  428. :cnfile
  429. :{cmd}
  430. etc.
  431. < Otherwise it works the same as `:cdo`.
  432. *:ldo*
  433. :ld[o][!] {cmd} Execute {cmd} in each valid entry in the location list
  434. for the current window.
  435. It works like doing this: >
  436. :lfirst
  437. :{cmd}
  438. :lnext
  439. :{cmd}
  440. etc.
  441. < Only valid entries in the location list are used.
  442. Otherwise it works the same as `:cdo`.
  443. *:lfdo*
  444. :lfdo[!] {cmd} Execute {cmd} in each file in the location list for
  445. the current window.
  446. It works like doing this: >
  447. :lfirst
  448. :{cmd}
  449. :lnfile
  450. :{cmd}
  451. etc.
  452. < Otherwise it works the same as `:ldo`.
  453. FILTERING A QUICKFIX OR LOCATION LIST:
  454. *cfilter-plugin* *:Cfilter* *:Lfilter*
  455. If you have too many entries in a quickfix list, you can use the cfilter
  456. plugin to reduce the number of entries. Load the plugin with: >
  457. packadd cfilter
  458. Then you can use the following commands to filter a quickfix/location list: >
  459. :Cfilter[!] /{pat}/
  460. :Lfilter[!] /{pat}/
  461. The |:Cfilter| command creates a new quickfix list from the entries matching
  462. {pat} in the current quickfix list. {pat} is a Vim |regular-expression|
  463. pattern. Both the file name and the text of the entries are matched against
  464. {pat}. If the optional ! is supplied, then the entries not matching {pat} are
  465. used. The pattern can be optionally enclosed using one of the following
  466. characters: ', ", /. If the pattern is empty, then the last used search
  467. pattern is used.
  468. The |:Lfilter| command does the same as |:Cfilter| but operates on the current
  469. location list.
  470. The current quickfix/location list is not modified by these commands, so you
  471. can go back to the unfiltered list using the |:colder|/|:lolder| command.
  472. =============================================================================
  473. 2. The error window *quickfix-window*
  474. *:cope* *:copen* *w:quickfix_title*
  475. :cope[n] [height] Open a window to show the current list of errors.
  476. When [height] is given, the window becomes that high
  477. (if there is room). When [height] is omitted the
  478. window is made ten lines high.
  479. If there already is a quickfix window, it will be made
  480. the current window. It is not possible to open a
  481. second quickfix window. If [height] is given the
  482. existing window will be resized to it.
  483. *quickfix-buffer*
  484. The window will contain a special buffer, with
  485. 'buftype' equal to "quickfix". Don't change this!
  486. The window will have the w:quickfix_title variable set
  487. which will indicate the command that produced the
  488. quickfix list. This can be used to compose a custom
  489. status line if the value of 'statusline' is adjusted
  490. properly. Whenever this buffer is modified by a
  491. quickfix command or function, the |b:changedtick|
  492. variable is incremented. You can get the number of
  493. this buffer using the getqflist() and getloclist()
  494. functions by passing the "qfbufnr" item. For a
  495. location list, this buffer is wiped out when the
  496. location list is removed.
  497. *:lop* *:lopen*
  498. :lop[en] [height] Open a window to show the location list for the
  499. current window. Works only when the location list for
  500. the current window is present. You can have more than
  501. one location window opened at a time. Otherwise, it
  502. acts the same as ":copen".
  503. *:ccl* *:cclose*
  504. :ccl[ose] Close the quickfix window.
  505. *:lcl* *:lclose*
  506. :lcl[ose] Close the window showing the location list for the
  507. current window.
  508. *:cw* *:cwindow*
  509. :cw[indow] [height] Open the quickfix window when there are recognized
  510. errors. If the window is already open and there are
  511. no recognized errors, close the window.
  512. *:lw* *:lwindow*
  513. :lw[indow] [height] Same as ":cwindow", except use the window showing the
  514. location list for the current window.
  515. *:cbo* *:cbottom*
  516. :cbo[ttom] Put the cursor in the last line of the quickfix window
  517. and scroll to make it visible. This is useful for
  518. when errors are added by an asynchronous callback.
  519. Only call it once in a while if there are many
  520. updates to avoid a lot of redrawing.
  521. *:lbo* *:lbottom*
  522. :lbo[ttom] Same as ":cbottom", except use the window showing the
  523. location list for the current window.
  524. Normally the quickfix window is at the bottom of the screen. If there are
  525. vertical splits, it's at the bottom of the rightmost column of windows. To
  526. make it always occupy the full width: >
  527. :botright cwindow
  528. You can move the window around with |window-moving| commands.
  529. For example, to move it to the top: CTRL-W K
  530. The 'winfixheight' option will be set, which means that the window will mostly
  531. keep its height, ignoring 'winheight' and 'equalalways'. You can change the
  532. height manually (e.g., by dragging the status line above it with the mouse).
  533. In the quickfix window, each line is one error. The line number is equal to
  534. the error number. The current entry is highlighted with the QuickFixLine
  535. highlighting. You can change it to your liking, e.g.: >
  536. :hi QuickFixLine ctermbg=Yellow guibg=Yellow
  537. You can use ":.cc" to jump to the error under the cursor.
  538. Hitting the <Enter> key or double-clicking the mouse on a line has the same
  539. effect. The file containing the error is opened in the window above the
  540. quickfix window. If there already is a window for that file, it is used
  541. instead. If the buffer in the used window has changed, and the error is in
  542. another file, jumping to the error will fail. You will first have to make
  543. sure the window contains a buffer which can be abandoned.
  544. When you select a file from the quickfix window, the following steps are used
  545. to find a window to edit the file:
  546. 1. If a window displaying the selected file is present in the current tabpage
  547. (starting with the window before the quickfix window), then that window is
  548. used.
  549. 2. If the above step fails and if 'switchbuf' contains "usetab" and a window
  550. displaying the selected file is present in any one of the tabpages
  551. (starting with the first tabpage) then that window is used.
  552. 3. If the above step fails then a window in the current tabpage displaying a
  553. buffer with 'buftype' not set (starting with the window before the quickfix
  554. window) is used.
  555. 4. If the above step fails and if 'switchbuf' contains "uselast", then the
  556. previously accessed window is used.
  557. 5. If the above step fails then the window before the quickfix window is used.
  558. If there is no previous window, then the window after the quickfix window
  559. is used.
  560. 6. If the above step fails, then a new horizontally split window above the
  561. quickfix window is used.
  562. *CTRL-W_<Enter>* *CTRL-W_<CR>*
  563. You can use CTRL-W <Enter> to open a new window and jump to the error there.
  564. When the quickfix window has been filled, two autocommand events are
  565. triggered. First the 'filetype' option is set to "qf", which triggers the
  566. FileType event (also see |qf.vim|). Then the BufReadPost event is triggered,
  567. using "quickfix" for the buffer name. This can be used to perform some action
  568. on the listed errors. Example: >
  569. au BufReadPost quickfix setlocal modifiable
  570. \ | silent exe 'g/^/s//\=line(".") .. " "/'
  571. \ | setlocal nomodifiable
  572. This prepends the line number to each line. Note the use of "\=" in the
  573. substitute string of the ":s" command, which is used to evaluate an
  574. expression.
  575. The BufWinEnter event is also triggered, again using "quickfix" for the buffer
  576. name.
  577. Note: When adding to an existing quickfix list the autocommand are not
  578. triggered.
  579. Note: Making changes in the quickfix window has no effect on the list of
  580. errors. 'modifiable' is off to avoid making changes. If you delete or insert
  581. lines anyway, the relation between the text and the error number is messed up.
  582. If you really want to do this, you could write the contents of the quickfix
  583. window to a file and use ":cfile" to have it parsed and used as the new error
  584. list.
  585. *location-list-window*
  586. The location list window displays the entries in a location list. When you
  587. open a location list window, it is created below the current window and
  588. displays the location list for the current window. The location list window
  589. is similar to the quickfix window, except that you can have more than one
  590. location list window open at a time. When you use a location list command in
  591. this window, the displayed location list is used.
  592. When you select a file from the location list window, the following steps are
  593. used to find a window to edit the file:
  594. 1. If a non-quickfix window associated with the location list is present in
  595. the current tabpage, then that window is used.
  596. 2. If the above step fails and if the file is already opened in another window
  597. in the current tabpage, then that window is used.
  598. 3. If the above step fails and 'switchbuf' contains "usetab" and if the file
  599. is opened in a window in any one of the tabpages, then that window is used.
  600. 4. If the above step fails then a window in the current tabpage showing a
  601. buffer with 'buftype' not set is used.
  602. 5. If the above step fails, then the file is edited in a new window.
  603. In all of the above cases, if the location list for the selected window is not
  604. yet set, then it is set to the location list displayed in the location list
  605. window.
  606. *quickfix-window-ID*
  607. You can use the |getqflist()| and |getloclist()| functions to obtain the
  608. window ID of the quickfix window and location list window respectively (if
  609. present). Examples: >
  610. echo getqflist({'winid' : 1}).winid
  611. echo getloclist(2, {'winid' : 1}).winid
  612. <
  613. *getqflist-examples*
  614. The |getqflist()| and |getloclist()| functions can be used to get the various
  615. attributes of a quickfix and location list respectively. Some examples for
  616. using these functions are below:
  617. >
  618. " get the title of the current quickfix list
  619. :echo getqflist({'title' : 0}).title
  620. " get the identifier of the current quickfix list
  621. :let qfid = getqflist({'id' : 0}).id
  622. " get the identifier of the fourth quickfix list in the stack
  623. :let qfid = getqflist({'nr' : 4, 'id' : 0}).id
  624. " check whether a quickfix list with a specific identifier exists
  625. :if getqflist({'id' : qfid}).id == qfid
  626. " get the index of the current quickfix list in the stack
  627. :let qfnum = getqflist({'nr' : 0}).nr
  628. " get the items of a quickfix list specified by an identifier
  629. :echo getqflist({'id' : qfid, 'items' : 0}).items
  630. " get the number of entries in a quickfix list specified by an id
  631. :echo getqflist({'id' : qfid, 'size' : 0}).size
  632. " get the context of the third quickfix list in the stack
  633. :echo getqflist({'nr' : 3, 'context' : 0}).context
  634. " get the number of quickfix lists in the stack
  635. :echo getqflist({'nr' : '$'}).nr
  636. " get the number of times the current quickfix list is changed
  637. :echo getqflist({'changedtick' : 0}).changedtick
  638. " get the current entry in a quickfix list specified by an identifier
  639. :echo getqflist({'id' : qfid, 'idx' : 0}).idx
  640. " get all the quickfix list attributes using an identifier
  641. :echo getqflist({'id' : qfid, 'all' : 0})
  642. " parse text from a List of lines and return a quickfix list
  643. :let myList = ["a.java:10:L10", "b.java:20:L20"]
  644. :echo getqflist({'lines' : myList}).items
  645. " parse text using a custom 'efm' and return a quickfix list
  646. :echo getqflist({'lines' : ['a.c#10#Line 10'], 'efm':'%f#%l#%m'}).items
  647. " get the quickfix list window id
  648. :echo getqflist({'winid' : 0}).winid
  649. " get the quickfix list window buffer number
  650. :echo getqflist({'qfbufnr' : 0}).qfbufnr
  651. " get the context of the current location list
  652. :echo getloclist(0, {'context' : 0}).context
  653. " get the location list window id of the third window
  654. :echo getloclist(3, {'winid' : 0}).winid
  655. " get the location list window buffer number of the third window
  656. :echo getloclist(3, {'qfbufnr' : 0}).qfbufnr
  657. " get the file window id of a location list window (winnr: 4)
  658. :echo getloclist(4, {'filewinid' : 0}).filewinid
  659. <
  660. *setqflist-examples*
  661. The |setqflist()| and |setloclist()| functions can be used to set the various
  662. attributes of a quickfix and location list respectively. Some examples for
  663. using these functions are below:
  664. >
  665. " create an empty quickfix list with a title and a context
  666. :let t = 'Search results'
  667. :let c = {'cmd' : 'grep'}
  668. :call setqflist([], ' ', {'title' : t, 'context' : c})
  669. " set the title of the current quickfix list
  670. :call setqflist([], 'a', {'title' : 'Mytitle'})
  671. " change the current entry in the list specified by an identifier
  672. :call setqflist([], 'a', {'id' : qfid, 'idx' : 10})
  673. " set the context of a quickfix list specified by an identifier
  674. :call setqflist([], 'a', {'id' : qfid, 'context' : {'val' : 100}})
  675. " create a new quickfix list from a command output
  676. :call setqflist([], ' ', {'lines' : systemlist('grep -Hn main *.c')})
  677. " parse text using a custom efm and add to a particular quickfix list
  678. :call setqflist([], 'a', {'id' : qfid,
  679. \ 'lines' : ["a.c#10#L10", "b.c#20#L20"], 'efm':'%f#%l#%m'})
  680. " add items to the quickfix list specified by an identifier
  681. :let newItems = [{'filename' : 'a.txt', 'lnum' : 10, 'text' : "Apple"},
  682. \ {'filename' : 'b.txt', 'lnum' : 20, 'text' : "Orange"}]
  683. :call setqflist([], 'a', {'id' : qfid, 'items' : newItems})
  684. " empty a quickfix list specified by an identifier
  685. :call setqflist([], 'r', {'id' : qfid, 'items' : []})
  686. " free all the quickfix lists in the stack
  687. :call setqflist([], 'f')
  688. " set the title of the fourth quickfix list
  689. :call setqflist([], 'a', {'nr' : 4, 'title' : 'SomeTitle'})
  690. " create a new quickfix list at the end of the stack
  691. :call setqflist([], ' ', {'nr' : '$',
  692. \ 'lines' : systemlist('grep -Hn class *.java')})
  693. " create a new location list from a command output
  694. :call setloclist(0, [], ' ', {'lines' : systemlist('grep -Hn main *.c')})
  695. " replace the location list entries for the third window
  696. :call setloclist(3, [], 'r', {'items' : newItems})
  697. <
  698. =============================================================================
  699. 3. Using more than one list of errors *quickfix-error-lists*
  700. So far has been assumed that there is only one list of errors. Actually the
  701. ten last used lists are remembered. When starting a new list, the previous
  702. ones are automatically kept. Two commands can be used to access older error
  703. lists. They set one of the existing error lists as the current one.
  704. *:colder* *:col* *E380*
  705. :col[der] [count] Go to older error list. When [count] is given, do
  706. this [count] times. When already at the oldest error
  707. list, an error message is given.
  708. *:lolder* *:lol*
  709. :lol[der] [count] Same as `:colder`, except use the location list for
  710. the current window instead of the quickfix list.
  711. *:cnewer* *:cnew* *E381*
  712. :cnew[er] [count] Go to newer error list. When [count] is given, do
  713. this [count] times. When already at the newest error
  714. list, an error message is given.
  715. *:lnewer* *:lnew*
  716. :lnew[er] [count] Same as `:cnewer`, except use the location list for
  717. the current window instead of the quickfix list.
  718. *:chistory* *:chi*
  719. :[count]chi[story] Show the list of error lists. The current list is
  720. marked with ">". The output looks like:
  721. error list 1 of 3; 43 errors :make ~
  722. > error list 2 of 3; 0 errors :helpgrep tag ~
  723. error list 3 of 3; 15 errors :grep ex_help *.c ~
  724. When [count] is given, then the count'th quickfix
  725. list is made the current list. Example: >
  726. " Make the 4th quickfix list current
  727. :4chistory
  728. <
  729. *:lhistory* *:lhi*
  730. :[count]lhi[story] Show the list of location lists, otherwise like
  731. `:chistory`.
  732. When adding a new error list, it becomes the current list.
  733. When ":colder" has been used and ":make" or ":grep" is used to add a new error
  734. list, one newer list is overwritten. This is especially useful if you are
  735. browsing with ":grep" |grep|. If you want to keep the more recent error
  736. lists, use ":cnewer 99" first.
  737. To get the number of lists in the quickfix and location list stack, you can
  738. use the |getqflist()| and |getloclist()| functions respectively with the list
  739. number set to the special value '$'. Examples: >
  740. echo getqflist({'nr' : '$'}).nr
  741. echo getloclist(3, {'nr' : '$'}).nr
  742. To get the number of the current list in the stack: >
  743. echo getqflist({'nr' : 0}).nr
  744. <
  745. =============================================================================
  746. 4. Using :make *:make_makeprg*
  747. *:mak* *:make*
  748. :mak[e][!] [arguments] 1. All relevant |QuickFixCmdPre| autocommands are
  749. executed.
  750. 2. If the 'autowrite' option is on, write any changed
  751. buffers
  752. 3. An errorfile name is made from 'makeef'. If
  753. 'makeef' doesn't contain "##", and a file with this
  754. name already exists, it is deleted.
  755. 4. The program given with the 'makeprg' option is
  756. started (default "make") with the optional
  757. [arguments] and the output is saved in the
  758. errorfile (for Unix it is also echoed on the
  759. screen).
  760. 5. The errorfile is read using 'errorformat'.
  761. 6. All relevant |QuickFixCmdPost| autocommands are
  762. executed. See example below.
  763. 7. If [!] is not given the first error is jumped to.
  764. 8. The errorfile is deleted.
  765. 9. You can now move through the errors with commands
  766. like |:cnext| and |:cprevious|, see above.
  767. This command does not accept a comment, any "
  768. characters are considered part of the arguments.
  769. If the encoding of the program output differs from the
  770. 'encoding' option, you can use the 'makeencoding'
  771. option to specify the encoding.
  772. *:lmak* *:lmake*
  773. :lmak[e][!] [arguments]
  774. Same as ":make", except the location list for the
  775. current window is used instead of the quickfix list.
  776. The ":make" command executes the command given with the 'makeprg' option.
  777. This is done by passing the command to the shell given with the 'shell'
  778. option. This works almost like typing
  779. ":!{makeprg} [arguments] {shellpipe} {errorfile}".
  780. {makeprg} is the string given with the 'makeprg' option. Any command can be
  781. used, not just "make". Characters '%' and '#' are expanded as usual on a
  782. command-line. You can use "%<" to insert the current file name without
  783. extension, or "#<" to insert the alternate file name without extension, for
  784. example: >
  785. :set makeprg=make\ #<.o
  786. [arguments] is anything that is typed after ":make".
  787. {shellpipe} is the 'shellpipe' option.
  788. {errorfile} is the 'makeef' option, with ## replaced to make it unique.
  789. The placeholder "$*" can be used for the argument list in {makeprg} if the
  790. command needs some additional characters after its arguments. The $* is
  791. replaced then by all arguments. Example: >
  792. :set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}
  793. or simpler >
  794. :let &mp = 'latex \\nonstopmode \\input\{$*}'
  795. "$*" can be given multiple times, for example: >
  796. :set makeprg=gcc\ -o\ $*\ $*
  797. The 'shellpipe' option defaults to ">%s 2>&1" for Win32.
  798. This means that the output of the compiler is saved in a file and not shown on
  799. the screen directly. For Unix "| tee" is used. The compiler output is shown
  800. on the screen and saved in a file the same time. Depending on the shell used
  801. "|& tee" or "2>&1| tee" is the default, so stderr output will be included.
  802. If 'shellpipe' is empty, the {errorfile} part will be omitted. This is useful
  803. for compilers that write to an errorfile themselves.
  804. Using QuickFixCmdPost to fix the encoding ~
  805. It may be that 'encoding' is set to an encoding that differs from the messages
  806. your build program produces. This example shows how to fix this after Vim has
  807. read the error messages: >
  808. function QfMakeConv()
  809. let qflist = getqflist()
  810. for i in qflist
  811. let i.text = iconv(i.text, "cp936", "utf-8")
  812. endfor
  813. call setqflist(qflist)
  814. endfunction
  815. au QuickfixCmdPost make call QfMakeConv()
  816. (Example by Faque Cheng)
  817. Another option is using 'makeencoding'.
  818. ==============================================================================
  819. 5. Using :vimgrep and :grep *grep* *lid*
  820. Vim has two ways to find matches for a pattern: Internal and external. The
  821. advantage of the internal grep is that it works on all systems and uses the
  822. powerful Vim search patterns. An external grep program can be used when the
  823. Vim grep does not do what you want.
  824. The internal method will be slower, because files are read into memory. The
  825. advantages are:
  826. - Line separators and encoding are automatically recognized, as if a file is
  827. being edited.
  828. - Uses Vim search patterns. Multi-line patterns can be used.
  829. - When plugins are enabled: compressed and remote files can be searched.
  830. |gzip| |netrw|
  831. To be able to do this Vim loads each file as if it is being edited. When
  832. there is no match in the file the associated buffer is wiped out again. The
  833. 'hidden' option is ignored here to avoid running out of memory or file
  834. descriptors when searching many files. However, when the |:hide| command
  835. modifier is used the buffers are kept loaded. This makes following searches
  836. in the same files a lot faster.
  837. Note that |:copen| (or |:lopen| for |:lgrep|) may be used to open a buffer
  838. containing the search results in linked form. The |:silent| command may be
  839. used to suppress the default full screen grep output. The ":grep!" form of
  840. the |:grep| command doesn't jump to the first match automatically. These
  841. commands can be combined to create a NewGrep command: >
  842. command! -nargs=+ NewGrep execute 'silent grep! <args>' | copen 42
  843. 5.1 using Vim's internal grep
  844. *:vim* *:vimgrep* *E682* *E683*
  845. :vim[grep][!] /{pattern}/[g][j][f] {file} ...
  846. Search for {pattern} in the files {file} ... and set
  847. the error list to the matches. Files matching
  848. 'wildignore' are ignored; files in 'suffixes' are
  849. searched last.
  850. {pattern} is a Vim search pattern. Instead of
  851. enclosing it in / any non-ID character (see
  852. |'isident'|) can be used, so long as it does not
  853. appear in {pattern}.
  854. 'ignorecase' applies. To overrule it put |/\c| in the
  855. pattern to ignore case or |/\C| to match case.
  856. 'smartcase' is not used.
  857. If {pattern} is empty (e.g. // is specified), the last
  858. used search pattern is used. |last-pattern|
  859. Flags:
  860. 'g' Without the 'g' flag each line is added only
  861. once. With 'g' every match is added.
  862. 'j' Without the 'j' flag Vim jumps to the first
  863. match. With 'j' only the quickfix list is
  864. updated. With the [!] any changes in the current
  865. buffer are abandoned.
  866. 'f' When the 'f' flag is specified, fuzzy string
  867. matching is used to find matching lines. In this
  868. case, {pattern} is treated as a literal string
  869. instead of a regular expression. See
  870. |fuzzy-matching| for more information about fuzzy
  871. matching strings.
  872. |QuickFixCmdPre| and |QuickFixCmdPost| are triggered.
  873. A file that is opened for matching may use a buffer
  874. number, but it is reused if possible to avoid
  875. consuming buffer numbers.
  876. :{count}vim[grep] ...
  877. When a number is put before the command this is used
  878. as the maximum number of matches to find. Use
  879. ":1vimgrep pattern file" to find only the first.
  880. Useful if you only want to check if there is a match
  881. and quit quickly when it's found.
  882. Every second or so the searched file name is displayed
  883. to give you an idea of the progress made.
  884. Examples: >
  885. :vimgrep /an error/ *.c
  886. :vimgrep /\<FileName\>/ *.h include/*
  887. :vimgrep /myfunc/ **/*.c
  888. < For the use of "**" see |starstar-wildcard|.
  889. :vim[grep][!] {pattern} {file} ...
  890. Like above, but instead of enclosing the pattern in a
  891. non-ID character use a white-separated pattern. The
  892. pattern must start with an ID character.
  893. Example: >
  894. :vimgrep Error *.c
  895. <
  896. *:lv* *:lvimgrep*
  897. :lv[imgrep][!] /{pattern}/[g][j][f] {file} ...
  898. :lv[imgrep][!] {pattern} {file} ...
  899. Same as ":vimgrep", except the location list for the
  900. current window is used instead of the quickfix list.
  901. *:vimgrepa* *:vimgrepadd*
  902. :vimgrepa[dd][!] /{pattern}/[g][j][f] {file} ...
  903. :vimgrepa[dd][!] {pattern} {file} ...
  904. Just like ":vimgrep", but instead of making a new list
  905. of errors the matches are appended to the current
  906. list.
  907. *:lvimgrepa* *:lvimgrepadd*
  908. :lvimgrepa[dd][!] /{pattern}/[g][j][f] {file} ...
  909. :lvimgrepa[dd][!] {pattern} {file} ...
  910. Same as ":vimgrepadd", except the location list for
  911. the current window is used instead of the quickfix
  912. list.
  913. 5.2 External grep
  914. Vim can interface with "grep" and grep-like programs (such as the GNU
  915. id-utils) in a similar way to its compiler integration (see |:make| above).
  916. [Unix trivia: The name for the Unix "grep" command comes from ":g/re/p", where
  917. "re" stands for Regular Expression.]
  918. *:gr* *:grep*
  919. :gr[ep][!] [arguments] Just like ":make", but use 'grepprg' instead of
  920. 'makeprg' and 'grepformat' instead of 'errorformat'.
  921. When 'grepprg' is "internal" this works like
  922. |:vimgrep|. Note that the pattern needs to be
  923. enclosed in separator characters then.
  924. If the encoding of the program output differs from the
  925. 'encoding' option, you can use the 'makeencoding'
  926. option to specify the encoding.
  927. *:lgr* *:lgrep*
  928. :lgr[ep][!] [arguments] Same as ":grep", except the location list for the
  929. current window is used instead of the quickfix list.
  930. *:grepa* *:grepadd*
  931. :grepa[dd][!] [arguments]
  932. Just like ":grep", but instead of making a new list of
  933. errors the matches are appended to the current list.
  934. Example: >
  935. :call setqflist([])
  936. :bufdo grepadd! something %
  937. < The first command makes a new error list which is
  938. empty. The second command executes "grepadd" for each
  939. listed buffer. Note the use of ! to avoid that
  940. ":grepadd" jumps to the first error, which is not
  941. allowed with |:bufdo|.
  942. An example that uses the argument list and avoids
  943. errors for files without matches: >
  944. :silent argdo try
  945. \ | grepadd! something %
  946. \ | catch /E480:/
  947. \ | endtry"
  948. <
  949. If the encoding of the program output differs from the
  950. 'encoding' option, you can use the 'makeencoding'
  951. option to specify the encoding.
  952. *:lgrepa* *:lgrepadd*
  953. :lgrepa[dd][!] [arguments]
  954. Same as ":grepadd", except the location list for the
  955. current window is used instead of the quickfix list.
  956. 5.3 Setting up external grep
  957. If you have a standard "grep" program installed, the :grep command may work
  958. well with the defaults. The syntax is very similar to the standard command: >
  959. :grep foo *.c
  960. Will search all files with the .c extension for the substring "foo". The
  961. arguments to :grep are passed straight to the "grep" program, so you can use
  962. whatever options your "grep" supports.
  963. By default, :grep invokes grep with the -n option (show file and line
  964. numbers). You can change this with the 'grepprg' option. You will need to set
  965. 'grepprg' if:
  966. a) You are using a program that isn't called "grep"
  967. b) You have to call grep with a full path
  968. c) You want to pass other options automatically (e.g. case insensitive
  969. search.)
  970. Once "grep" has executed, Vim parses the results using the 'grepformat'
  971. option. This option works in the same way as the 'errorformat' option - see
  972. that for details. You may need to change 'grepformat' from the default if
  973. your grep outputs in a non-standard format, or you are using some other
  974. program with a special format.
  975. Once the results are parsed, Vim loads the first file containing a match and
  976. jumps to the appropriate line, in the same way that it jumps to a compiler
  977. error in |quickfix| mode. You can then use the |:cnext|, |:clist|, etc.
  978. commands to see the other matches.
  979. 5.4 Using :grep with id-utils
  980. You can set up :grep to work with the GNU id-utils like this: >
  981. :set grepprg=lid\ -Rgrep\ -s
  982. :set grepformat=%f:%l:%m
  983. then >
  984. :grep (regexp)
  985. works just as you'd expect.
  986. (provided you remembered to mkid first :)
  987. 5.5 Browsing source code with :vimgrep or :grep
  988. Using the stack of error lists that Vim keeps, you can browse your files to
  989. look for functions and the functions they call. For example, suppose that you
  990. have to add an argument to the read_file() function. You enter this command: >
  991. :vimgrep /\<read_file\>/ *.c
  992. You use ":cn" to go along the list of matches and add the argument. At one
  993. place you have to get the new argument from a higher level function msg(), and
  994. need to change that one too. Thus you use: >
  995. :vimgrep /\<msg\>/ *.c
  996. While changing the msg() functions, you find another function that needs to
  997. get the argument from a higher level. You can again use ":vimgrep" to find
  998. these functions. Once you are finished with one function, you can use >
  999. :colder
  1000. to go back to the previous one.
  1001. This works like browsing a tree: ":vimgrep" goes one level deeper, creating a
  1002. list of branches. ":colder" goes back to the previous level. You can mix
  1003. this use of ":vimgrep" and "colder" to browse all the locations in a tree-like
  1004. way. If you do this consistently, you will find all locations without the
  1005. need to write down a "todo" list.
  1006. =============================================================================
  1007. 6. Selecting a compiler *compiler-select*
  1008. *:comp* *:compiler* *E666*
  1009. :comp[iler][!] {name} Set options to work with compiler {name}.
  1010. Without the "!" options are set for the
  1011. current buffer. With "!" global options are
  1012. set.
  1013. If you use ":compiler foo" in "file.foo" and
  1014. then ":compiler! bar" in another buffer, Vim
  1015. will keep on using "foo" in "file.foo".
  1016. The Vim plugins in the "compiler" directory will set options to use the
  1017. selected compiler. For `:compiler` local options are set, for `:compiler!`
  1018. global options.
  1019. *current_compiler*
  1020. To support older Vim versions, the plugins always use "current_compiler" and
  1021. not "b:current_compiler". What the command actually does is the following:
  1022. - Delete the "current_compiler" and "b:current_compiler" variables.
  1023. - Define the "CompilerSet" user command. With "!" it does ":set", without "!"
  1024. it does ":setlocal".
  1025. - Execute ":runtime! compiler/{name}.(vim|lua)". The plugins are expected to
  1026. set options with "CompilerSet" and set the "current_compiler" variable to the
  1027. name of the compiler.
  1028. - Delete the "CompilerSet" user command.
  1029. - Set "b:current_compiler" to the value of "current_compiler".
  1030. - Without "!" the old value of "current_compiler" is restored.
  1031. For writing a compiler plugin, see |write-compiler-plugin|.
  1032. GCC *quickfix-gcc* *compiler-gcc*
  1033. There's one variable you can set for the GCC compiler:
  1034. g:compiler_gcc_ignore_unmatched_lines
  1035. Ignore lines that don't match any patterns
  1036. defined for GCC. Useful if output from
  1037. commands run from make are generating false
  1038. positives.
  1039. PERL *quickfix-perl* *compiler-perl*
  1040. The Perl compiler plugin doesn't actually compile, but invokes Perl's internal
  1041. syntax checking feature and parses the output for possible errors so you can
  1042. correct them in quick-fix mode.
  1043. Warnings are forced regardless of "no warnings" or "$^W = 0" within the file
  1044. being checked. To disable this set g:perl_compiler_force_warnings to a zero
  1045. value. For example: >
  1046. let g:perl_compiler_force_warnings = 0
  1047. PYUNIT COMPILER *compiler-pyunit*
  1048. This is not actually a compiler, but a unit testing framework for the
  1049. Python language. It is included into standard Python distribution
  1050. starting from version 2.0. For older versions, you can get it from
  1051. https://pyunit.sourceforge.net.
  1052. When you run your tests with the help of the framework, possible errors
  1053. are parsed by Vim and presented for you in quick-fix mode.
  1054. Unfortunately, there is no standard way to run the tests.
  1055. The alltests.py script seems to be used quite often, that's all.
  1056. Useful values for the 'makeprg' options therefore are:
  1057. setlocal makeprg=./alltests.py " Run a testsuite
  1058. setlocal makeprg=python\ %:S " Run a single testcase
  1059. TEX COMPILER *compiler-tex*
  1060. Included in the distribution compiler for TeX ($VIMRUNTIME/compiler/tex.vim)
  1061. uses make command if possible. If the compiler finds a file named "Makefile"
  1062. or "makefile" in the current directory, it supposes that you want to process
  1063. your *TeX files with make, and the makefile does the right work. In this case
  1064. compiler sets 'errorformat' for *TeX output and leaves 'makeprg' untouched. If
  1065. neither "Makefile" nor "makefile" is found, the compiler will not use make.
  1066. You can force the compiler to ignore makefiles by defining
  1067. b:tex_ignore_makefile or g:tex_ignore_makefile variable (they are checked for
  1068. existence only).
  1069. If the compiler chose not to use make, it needs to choose a right program for
  1070. processing your input. If b:tex_flavor or g:tex_flavor (in this precedence)
  1071. variable exists, it defines TeX flavor for :make (actually, this is the name
  1072. of executed command), and if both variables do not exist, it defaults to
  1073. "latex". For example, while editing chapter2.tex \input-ed from mypaper.tex
  1074. written in AMS-TeX: >
  1075. :let b:tex_flavor = 'amstex'
  1076. :compiler tex
  1077. < [editing...] >
  1078. :make mypaper
  1079. Note that you must specify a name of the file to process as an argument (to
  1080. process the right file when editing \input-ed or \include-ed file; portable
  1081. solution for substituting % for no arguments is welcome). This is not in the
  1082. semantics of make, where you specify a target, not source, but you may specify
  1083. filename without extension ".tex" and mean this as "make filename.dvi or
  1084. filename.pdf or filename.some_result_extension according to compiler".
  1085. Note: tex command line syntax is set to usable both for MikTeX (suggestion
  1086. by Srinath Avadhanula) and teTeX (checked by Artem Chuprina). Suggestion
  1087. from |errorformat-LaTeX| is too complex to keep it working for different
  1088. shells and OSes and also does not allow to use other available TeX options,
  1089. if any. If your TeX doesn't support "-interaction=nonstopmode", please
  1090. report it with different means to express \nonstopmode from the command line.
  1091. =============================================================================
  1092. 7. The error format *error-file-format*
  1093. *errorformat* *E372* *E373* *E374*
  1094. *E375* *E376* *E377* *E378*
  1095. The 'errorformat' option specifies a list of formats that are recognized. The
  1096. first format that matches with an error message is used. You can add several
  1097. formats for different messages your compiler produces, or even entries for
  1098. multiple compilers. See |efm-entries|.
  1099. Each entry in 'errorformat' is a scanf-like string that describes the format.
  1100. First, you need to know how scanf works. Look in the documentation of your
  1101. C compiler. Below you find the % items that Vim understands. Others are
  1102. invalid.
  1103. Special characters in 'errorformat' are comma and backslash. See
  1104. |efm-entries| for how to deal with them. Note that a literal "%" is matched
  1105. by "%%", thus it is not escaped with a backslash.
  1106. Keep in mind that in the `:make` and `:grep` output all NUL characters are
  1107. replaced with SOH (0x01).
  1108. Note: By default the difference between upper and lowercase is ignored. If
  1109. you want to match case, add "\C" to the pattern |/\C|.
  1110. Vim will read lines of any length, but only the first 4095 bytes are used, the
  1111. rest is ignored. Items can only be 1023 bytes long.
  1112. Basic items
  1113. %f file name (finds a string)
  1114. %o module name (finds a string)
  1115. %l line number (finds a number)
  1116. %e end line number (finds a number)
  1117. %c column number (finds a number representing character
  1118. column of the error, byte index, a <tab> is 1
  1119. character column)
  1120. %v virtual column number (finds a number representing
  1121. screen column of the error (1 <tab> == 8 screen
  1122. columns))
  1123. %k end column number (finds a number representing
  1124. the character column of the error, byte index, or a
  1125. number representing screen end column of the error if
  1126. it's used with %v)
  1127. %t error type (finds a single character):
  1128. e - error message
  1129. w - warning message
  1130. i - info message
  1131. n - note message
  1132. %n error number (finds a number)
  1133. %m error message (finds a string)
  1134. %r matches the "rest" of a single-line file message %O/P/Q
  1135. %p pointer line (finds a sequence of '-', '.', ' ' or
  1136. tabs and uses the length for the column number)
  1137. %*{conv} any scanf non-assignable conversion
  1138. %% the single '%' character
  1139. %s search text (finds a string)
  1140. The "%f" conversion may depend on the current 'isfname' setting. "~/" is
  1141. expanded to the home directory and environment variables are expanded.
  1142. The "%f" and "%m" conversions have to detect the end of the string. This
  1143. normally happens by matching following characters and items. When nothing is
  1144. following the rest of the line is matched. If "%f" is followed by a '%' or a
  1145. backslash, it will look for a sequence of 'isfname' characters.
  1146. On Windows a leading "C:" will be included in "%f", even when using "%f:".
  1147. This means that a file name which is a single alphabetical letter will not be
  1148. detected.
  1149. The "%p" conversion is normally followed by a "^". It's used for compilers
  1150. that output a line like: >
  1151. ^
  1152. or >
  1153. ---------^
  1154. to indicate the column of the error. This is to be used in a multi-line error
  1155. message. See |errorformat-javac| for a useful example.
  1156. The "%s" conversion specifies the text to search for, to locate the error line.
  1157. The text is used as a literal string. The anchors "^" and "$" are added to
  1158. the text to locate the error line exactly matching the search text and the
  1159. text is prefixed with the "\V" atom to make it "very nomagic". The "%s"
  1160. conversion can be used to locate lines without a line number in the error
  1161. output. Like the output of the "grep" shell command.
  1162. When the pattern is present the line number will not be used.
  1163. The "%o" conversion specifies the module name in quickfix entry. If present
  1164. it will be used in quickfix error window instead of the filename. The module
  1165. name is used only for displaying purposes, the file name is used when jumping
  1166. to the file.
  1167. Changing directory
  1168. The following uppercase conversion characters specify the type of special
  1169. format strings. At most one of them may be given as a prefix at the beginning
  1170. of a single comma-separated format pattern.
  1171. Some compilers produce messages that consist of directory names that have to
  1172. be prepended to each file name read by %f (example: GNU make). The following
  1173. codes can be used to scan these directory names; they will be stored in an
  1174. internal directory stack. *E379*
  1175. %D "enter directory" format string; expects a following
  1176. %f that finds the directory name
  1177. %X "leave directory" format string; expects following %f
  1178. When defining an "enter directory" or "leave directory" format, the "%D" or
  1179. "%X" has to be given at the start of that substring. Vim tracks the directory
  1180. changes and prepends the current directory to each erroneous file found with a
  1181. relative path. See |quickfix-directory-stack| for details, tips and
  1182. limitations.
  1183. Multi-line messages *errorformat-multi-line*
  1184. It is possible to read the output of programs that produce multi-line
  1185. messages, i.e. error strings that consume more than one line. Possible
  1186. prefixes are:
  1187. %E start of a multi-line error message
  1188. %W start of a multi-line warning message
  1189. %I start of a multi-line informational message
  1190. %N start of a multi-line note message
  1191. %A start of a multi-line message (unspecified type)
  1192. %> for next line start with current pattern again |efm-%>|
  1193. %C continuation of a multi-line message
  1194. %Z end of a multi-line message
  1195. These can be used with '+' and '-', see |efm-ignore| below.
  1196. Using "\n" in the pattern won't work to match multi-line messages.
  1197. Example: Your compiler happens to write out errors in the following format
  1198. (leading line numbers not being part of the actual output):
  1199. 1 Error 275 ~
  1200. 2 line 42 ~
  1201. 3 column 3 ~
  1202. 4 ' ' expected after '--' ~
  1203. The appropriate error format string has to look like this: >
  1204. :set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
  1205. And the |:clist| error message generated for this error is:
  1206. 1:42 col 3 error 275: ' ' expected after '--'
  1207. Another example: Think of a Python interpreter that produces the following
  1208. error message (line numbers are not part of the actual output):
  1209. 1 ==============================================================
  1210. 2 FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)
  1211. 3 --------------------------------------------------------------
  1212. 4 Traceback (most recent call last):
  1213. 5 File "unittests/dbfacadeTest.py", line 89, in testFoo
  1214. 6 self.assertEquals(34, dtid)
  1215. 7 File "/usr/lib/python3.8/unittest.py", line 286, in
  1216. 8 failUnlessEqual
  1217. 9 raise self.failureException, \
  1218. 10 AssertionError: 34 != 33
  1219. 11
  1220. 12 --------------------------------------------------------------
  1221. 13 Ran 27 tests in 0.063s
  1222. Say you want |:clist| write the relevant information of this message only,
  1223. namely:
  1224. 5 unittests/dbfacadeTest.py:89: AssertionError: 34 != 33
  1225. Then the error format string could be defined as follows: >
  1226. :set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
  1227. Note that the %C string is given before the %A here: since the expression
  1228. ' %.%#' (which stands for the regular expression ' .*') matches every line
  1229. starting with a space, followed by any characters to the end of the line,
  1230. it also hides line 7 which would trigger a separate error message otherwise.
  1231. Error format strings are always parsed pattern by pattern until the first
  1232. match occurs.
  1233. *efm-%>*
  1234. The %> item can be used to avoid trying patterns that appear earlier in
  1235. 'errorformat'. This is useful for patterns that match just about anything.
  1236. For example, if the error looks like this:
  1237. Error in line 123 of foo.c: ~
  1238. unknown variable "i" ~
  1239. This can be found with: >
  1240. :set efm=xxx,%E%>Error in line %l of %f:,%Z%m
  1241. Where "xxx" has a pattern that would also match the second line.
  1242. Important: There is no memory of what part of the errorformat matched before;
  1243. every line in the error file gets a complete new run through the error format
  1244. lines. For example, if one has: >
  1245. setlocal efm=aa,bb,cc,dd,ee
  1246. Where aa, bb, etc. are error format strings. Each line of the error file will
  1247. be matched to the pattern aa, then bb, then cc, etc. Just because cc matched
  1248. the previous error line does _not_ mean that dd will be tried first on the
  1249. current line, even if cc and dd are multi-line errorformat strings.
  1250. Separate file name *errorformat-separate-filename*
  1251. These prefixes are useful if the file name is given once and multiple messages
  1252. follow that refer to this file name.
  1253. %O single-line file message: overread the matched part
  1254. %P single-line file message: push file %f onto the stack
  1255. %Q single-line file message: pop the last file from stack
  1256. Example: Given a compiler that produces the following error logfile (without
  1257. leading line numbers):
  1258. 1 [a1.tt]
  1259. 2 (1,17) error: ';' missing
  1260. 3 (21,2) warning: variable 'z' not defined
  1261. 4 (67,3) error: end of file found before string ended
  1262. 5
  1263. 6 [a2.tt]
  1264. 7
  1265. 8 [a3.tt]
  1266. 9 NEW compiler v1.1
  1267. 10 (2,2) warning: variable 'x' not defined
  1268. 11 (67,3) warning: 's' already defined
  1269. This logfile lists several messages for each file enclosed in [...] which are
  1270. properly parsed by an error format like this: >
  1271. :set efm=%+P[%f],(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%-Q
  1272. A call of |:clist| writes them accordingly with their correct filenames:
  1273. 2 a1.tt:1 col 17 error: ';' missing
  1274. 3 a1.tt:21 col 2 warning: variable 'z' not defined
  1275. 4 a1.tt:67 col 3 error: end of file found before string ended
  1276. 8 a3.tt:2 col 2 warning: variable 'x' not defined
  1277. 9 a3.tt:67 col 3 warning: 's' already defined
  1278. Unlike the other prefixes that all match against whole lines, %P, %Q and %O
  1279. can be used to match several patterns in the same line. Thus it is possible
  1280. to parse even nested files like in the following line:
  1281. {"file1" {"file2" error1} error2 {"file3" error3 {"file4" error4 error5}}}
  1282. The %O then parses over strings that do not contain any push/pop file name
  1283. information. See |errorformat-LaTeX| for an extended example.
  1284. Ignoring and using whole messages *efm-ignore*
  1285. The codes '+' or '-' can be combined with the uppercase codes above; in that
  1286. case they have to precede the letter, e.g. '%+A' or '%-G':
  1287. %- do not include the matching multi-line in any output
  1288. %+ include the whole matching line in the %m error string
  1289. One prefix is only useful in combination with '+' or '-', namely %G. It parses
  1290. over lines containing general information like compiler version strings or
  1291. other headers that can be skipped.
  1292. %-G ignore this message
  1293. %+G general message
  1294. Pattern matching
  1295. The scanf()-like "%*[]" notation is supported for backward-compatibility
  1296. with previous versions of Vim. However, it is also possible to specify
  1297. (nearly) any Vim supported regular expression in format strings.
  1298. Since meta characters of the regular expression language can be part of
  1299. ordinary matching strings or file names (and therefore internally have to
  1300. be escaped), meta symbols have to be written with leading '%':
  1301. %\ The single '\' character. Note that this has to be
  1302. escaped ("%\\") in ":set errorformat=" definitions.
  1303. %. The single '.' character.
  1304. %# The single '*'(!) character.
  1305. %^ The single '^' character. Note that this is not
  1306. useful, the pattern already matches start of line.
  1307. %$ The single '$' character. Note that this is not
  1308. useful, the pattern already matches end of line.
  1309. %[ The single '[' character for a [] character range.
  1310. %~ The single '~' character.
  1311. When using character classes in expressions (see |/\i| for an overview),
  1312. terms containing the "\+" quantifier can be written in the scanf() "%*"
  1313. notation. Example: "%\\d%\\+" ("\d\+", "any number") is equivalent to "%*\\d".
  1314. Important note: The \(...\) grouping of sub-matches can not be used in format
  1315. specifications because it is reserved for internal conversions.
  1316. Multiple entries in 'errorformat' *efm-entries*
  1317. To be able to detect output from several compilers, several format patterns
  1318. may be put in 'errorformat', separated by commas (note: blanks after the comma
  1319. are ignored). The first pattern that has a complete match is used. If no
  1320. match is found, matching parts from the last one will be used, although the
  1321. file name is removed and the error message is set to the whole message. If
  1322. there is a pattern that may match output from several compilers (but not in a
  1323. right way), put it after one that is more restrictive.
  1324. To include a comma in a pattern precede it with a backslash (you have to type
  1325. two in a ":set" command). To include a backslash itself give two backslashes
  1326. (you have to type four in a ":set" command). You also need to put a backslash
  1327. before a space for ":set".
  1328. Valid matches *quickfix-valid*
  1329. If a line does not completely match one of the entries in 'errorformat', the
  1330. whole line is put in the error message and the entry is marked "not valid"
  1331. These lines are skipped with the ":cn" and ":cp" commands (unless there is
  1332. no valid line at all). You can use ":cl!" to display all the error messages.
  1333. If the error format does not contain a file name Vim cannot switch to the
  1334. correct file. You will have to do this by hand.
  1335. For example, the format of the output from the Amiga Aztec compiler is:
  1336. filename>linenumber:columnnumber:errortype:errornumber:errormessage
  1337. filename name of the file in which the error was detected
  1338. linenumber line number where the error was detected
  1339. columnnumber column number where the error was detected
  1340. errortype type of the error, normally a single 'E' or 'W'
  1341. errornumber number of the error (for lookup in the manual)
  1342. errormessage description of the error
  1343. This can be matched with this 'errorformat' entry:
  1344. %f>%l:%c:%t:%n:%m
  1345. Some examples for C compilers that produce single-line error outputs:
  1346. %f:%l:\ %t%*[^0123456789]%n:\ %m for Manx/Aztec C error messages
  1347. (scanf() doesn't understand [0-9])
  1348. %f\ %l\ %t%*[^0-9]%n:\ %m for SAS C
  1349. \"%f\"\\,%*[^0-9]%l:\ %m for generic C compilers
  1350. %f:%l:\ %m for GCC
  1351. %f:%l:\ %m,%Dgmake[%*\\d]:\ Entering\ directory\ `%f',
  1352. %Dgmake[%*\\d]:\ Leaving\ directory\ `%f'
  1353. for GCC with gmake (concat the lines!)
  1354. %f(%l)\ :\ %*[^:]:\ %m old SCO C compiler (pre-OS5)
  1355. %f(%l)\ :\ %t%*[^0-9]%n:\ %m idem, with error type and number
  1356. %f:%l:\ %m,In\ file\ included\ from\ %f:%l:,\^I\^Ifrom\ %f:%l%m
  1357. for GCC, with some extras
  1358. Extended examples for the handling of multi-line messages are given below,
  1359. see |errorformat-Jikes| and |errorformat-LaTeX|.
  1360. Note the backslash in front of a space and double quote. It is required for
  1361. the :set command. There are two backslashes in front of a comma, one for the
  1362. :set command and one to avoid recognizing the comma as a separator of error
  1363. formats.
  1364. Filtering messages
  1365. If you have a compiler that produces error messages that do not fit in the
  1366. format string, you could write a program that translates the error messages
  1367. into this format. You can use this program with the ":make" command by
  1368. changing the 'makeprg' option. For example: >
  1369. :set mp=make\ \\\|&\ error_filter
  1370. The backslashes before the pipe character are required to avoid it to be
  1371. recognized as a command separator. The backslash before each space is
  1372. required for the set command.
  1373. =============================================================================
  1374. 8. The directory stack *quickfix-directory-stack*
  1375. Quickfix maintains a stack for saving all used directories parsed from the
  1376. make output. For GNU-make this is rather simple, as it always prints the
  1377. absolute path of all directories it enters and leaves. Regardless if this is
  1378. done via a 'cd' command in the makefile or with the parameter "-C dir" (change
  1379. to directory before reading the makefile). It may be useful to use the switch
  1380. "-w" to force GNU-make to print out the working directory before and after
  1381. processing.
  1382. Maintaining the correct directory is more complicated if you don't use
  1383. GNU-make. AIX-make for example doesn't print any information about its
  1384. working directory. Then you need to enhance the makefile. In the makefile of
  1385. LessTif there is a command which echoes "Making {target} in {dir}". The
  1386. special problem here is that it doesn't print information on leaving the
  1387. directory and that it doesn't print the absolute path.
  1388. To solve the problem with relative paths and missing "leave directory"
  1389. messages Vim uses the following algorithm:
  1390. 1) Check if the given directory is a subdirectory of the current directory.
  1391. If this is true, store it as the current directory.
  1392. 2) If it is not a subdir of the current directory, try if this is a
  1393. subdirectory of one of the upper directories.
  1394. 3) If the directory still isn't found, it is assumed to be a subdirectory
  1395. of Vim's current directory.
  1396. Additionally it is checked for every file, if it really exists in the
  1397. identified directory. If not, it is searched in all other directories of the
  1398. directory stack (NOT the directory subtree!). If it is still not found, it is
  1399. assumed that it is in Vim's current directory.
  1400. There are limitations in this algorithm. These examples assume that make just
  1401. prints information about entering a directory in the form "Making all in dir".
  1402. 1) Assume you have following directories and files:
  1403. ./dir1
  1404. ./dir1/file1.c
  1405. ./file1.c
  1406. If make processes the directory "./dir1" before the current directory and
  1407. there is an error in the file "./file1.c", you will end up with the file
  1408. "./dir1/file.c" loaded by Vim.
  1409. This can only be solved with a "leave directory" message.
  1410. 2) Assume you have following directories and files:
  1411. ./dir1
  1412. ./dir1/dir2
  1413. ./dir2
  1414. You get the following:
  1415. Make output Directory interpreted by Vim
  1416. ------------------------ ----------------------------
  1417. Making all in dir1 ./dir1
  1418. Making all in dir2 ./dir1/dir2
  1419. Making all in dir2 ./dir1/dir2
  1420. This can be solved by printing absolute directories in the "enter directory"
  1421. message or by printing "leave directory" messages.
  1422. To avoid this problem, ensure to print absolute directory names and "leave
  1423. directory" messages.
  1424. Examples for Makefiles:
  1425. Unix:
  1426. libs:
  1427. for dn in $(LIBDIRS); do \
  1428. (cd $$dn; echo "Entering dir '$$(pwd)'"; make); \
  1429. echo "Leaving dir"; \
  1430. done
  1431. Add
  1432. %DEntering\ dir\ '%f',%XLeaving\ dir
  1433. to your 'errorformat' to handle the above output.
  1434. Note that Vim doesn't check if the directory name in a "leave directory"
  1435. messages is the current directory. This is why you could just use the message
  1436. "Leaving dir".
  1437. =============================================================================
  1438. 9. Specific error file formats *errorformats*
  1439. *errorformat-Jikes*
  1440. Jikes(TM), a source-to-bytecode Java compiler published by IBM Research,
  1441. produces simple multi-line error messages.
  1442. An 'errorformat' string matching the produced messages is shown below.
  1443. The following lines can be placed in the user's |init.vim| to overwrite Vim's
  1444. recognized default formats, or see |:set+=| how to install this format
  1445. additionally to the default. >
  1446. :set efm=%A%f:%l:%c:%*\\d:%*\\d:,
  1447. \%C%*\\s%trror:%m,
  1448. \%+C%*[^:]%trror:%m,
  1449. \%C%*\\s%tarning:%m,
  1450. \%C%m
  1451. <
  1452. Jikes(TM) produces a single-line error message when invoked with the option
  1453. "+E", and can be matched with the following: >
  1454. :setl efm=%f:%l:%v:%*\\d:%*\\d:%*\\s%m
  1455. <
  1456. *errorformat-javac*
  1457. This 'errorformat' has been reported to work well for javac, which outputs a
  1458. line with "^" to indicate the column of the error: >
  1459. :setl efm=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
  1460. or: >
  1461. :setl efm=%A%f:%l:\ %m,%+Z%p^,%+C%.%#,%-G%.%#
  1462. <
  1463. Here is an alternative from Michael F. Lamb for Unix that filters the errors
  1464. first: >
  1465. :setl errorformat=%Z%f:%l:\ %m,%A%p^,%-G%*[^sl]%.%#
  1466. :setl makeprg=javac\ %:S\ 2>&1\ \\\|\ vim-javac-filter
  1467. You need to put the following in "vim-javac-filter" somewhere in your path
  1468. (e.g., in ~/bin) and make it executable: >
  1469. #!/bin/sed -f
  1470. /\^$/s/\t/\ /g;/:[0-9]\+:/{h;d};/^[ \t]*\^/G;
  1471. In English, that sed script:
  1472. - Changes single tabs to single spaces and
  1473. - Moves the line with the filename, line number, error message to just after
  1474. the pointer line. That way, the unused error text between doesn't break
  1475. vim's notion of a "multi-line message" and also doesn't force us to include
  1476. it as a "continuation of a multi-line message."
  1477. *errorformat-ant*
  1478. For ant (https://jakarta.apache.org/) the above errorformat has to be modified
  1479. to honour the leading [javac] in front of each javac output line: >
  1480. :set efm=%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
  1481. The 'errorformat' can also be configured to handle ant together with either
  1482. javac or jikes. If you're using jikes, you should tell ant to use jikes' +E
  1483. command line switch which forces jikes to generate one-line error messages.
  1484. This is what the second line (of a build.xml file) below does: >
  1485. <property name = "build.compiler" value = "jikes"/>
  1486. <property name = "build.compiler.emacs" value = "true"/>
  1487. The 'errorformat' which handles ant with both javac and jikes is: >
  1488. :set efm=\ %#[javac]\ %#%f:%l:%c:%*\\d:%*\\d:\ %t%[%^:]%#:%m,
  1489. \%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
  1490. <
  1491. *errorformat-jade*
  1492. parsing jade (see http://www.jclark.com/) errors is simple: >
  1493. :set efm=jade:%f:%l:%c:%t:%m
  1494. <
  1495. *errorformat-LaTeX*
  1496. The following is an example how an 'errorformat' string can be specified
  1497. for the (La)TeX typesetting system which displays error messages over
  1498. multiple lines. The output of ":clist" and ":cc" etc. commands displays
  1499. multi-lines in a single line, leading white space is removed.
  1500. It should be easy to adopt the above LaTeX errorformat to any compiler output
  1501. consisting of multi-line errors.
  1502. The commands can be placed in a |vimrc| file or some other Vim script file,
  1503. e.g. a script containing LaTeX related stuff which is loaded only when editing
  1504. LaTeX sources.
  1505. Make sure to copy all lines of the example (in the given order), afterwards
  1506. remove the comment lines. For the '\' notation at the start of some lines see
  1507. |line-continuation|.
  1508. First prepare 'makeprg' such that LaTeX will report multiple
  1509. errors; do not stop when the first error has occurred: >
  1510. :set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}
  1511. <
  1512. Start of multi-line error messages: >
  1513. :set efm=%E!\ LaTeX\ %trror:\ %m,
  1514. \%E!\ %m,
  1515. < Start of multi-line warning messages; the first two also
  1516. include the line number. Meaning of some regular expressions:
  1517. - "%.%#" (".*") matches a (possibly empty) string
  1518. - "%*\\d" ("\d\+") matches a number >
  1519. \%+WLaTeX\ %.%#Warning:\ %.%#line\ %l%.%#,
  1520. \%+W%.%#\ at\ lines\ %l--%*\\d,
  1521. \%WLaTeX\ %.%#Warning:\ %m,
  1522. < Possible continuations of error/warning messages; the first
  1523. one also includes the line number: >
  1524. \%Cl.%l\ %m,
  1525. \%+C\ \ %m.,
  1526. \%+C%.%#-%.%#,
  1527. \%+C%.%#[]%.%#,
  1528. \%+C[]%.%#,
  1529. \%+C%.%#%[{}\\]%.%#,
  1530. \%+C<%.%#>%.%#,
  1531. \%C\ \ %m,
  1532. < Lines that match the following patterns do not contain any
  1533. important information; do not include them in messages: >
  1534. \%-GSee\ the\ LaTeX%m,
  1535. \%-GType\ \ H\ <return>%m,
  1536. \%-G\ ...%.%#,
  1537. \%-G%.%#\ (C)\ %.%#,
  1538. \%-G(see\ the\ transcript%.%#),
  1539. < Generally exclude any empty or whitespace-only line from
  1540. being displayed: >
  1541. \%-G\\s%#,
  1542. < The LaTeX output log does not specify the names of erroneous
  1543. source files per line; rather they are given globally,
  1544. enclosed in parentheses.
  1545. The following patterns try to match these names and store
  1546. them in an internal stack. The patterns possibly scan over
  1547. the same input line (one after another), the trailing "%r"
  1548. conversion indicates the "rest" of the line that will be
  1549. parsed in the next go until the end of line is reached.
  1550. Overread a file name enclosed in '('...')'; do not push it
  1551. on a stack since the file apparently does not contain any
  1552. error: >
  1553. \%+O(%f)%r,
  1554. < Push a file name onto the stack. The name is given after '(': >
  1555. \%+P(%f%r,
  1556. \%+P\ %\\=(%f%r,
  1557. \%+P%*[^()](%f%r,
  1558. \%+P[%\\d%[^()]%#(%f%r,
  1559. < Pop the last stored file name when a ')' is scanned: >
  1560. \%+Q)%r,
  1561. \%+Q%*[^()])%r,
  1562. \%+Q[%\\d%*[^()])%r
  1563. Note that in some cases file names in the LaTeX output log cannot be parsed
  1564. properly. The parser might have been messed up by unbalanced parentheses
  1565. then. The above example tries to catch the most relevant cases only.
  1566. You can customize the given setting to suit your own purposes, for example,
  1567. all the annoying "Overfull ..." warnings could be excluded from being
  1568. recognized as an error.
  1569. Alternatively to filtering the LaTeX compiler output, it is also possible
  1570. to directly read the *.log file that is produced by the [La]TeX compiler.
  1571. This contains even more useful information about possible error causes.
  1572. However, to properly parse such a complex file, an external filter should
  1573. be used. See the description further above how to make such a filter known
  1574. by Vim.
  1575. =============================================================================
  1576. 10. Customizing the quickfix window *quickfix-window-function*
  1577. The default format for the lines displayed in the quickfix window and location
  1578. list window is:
  1579. <filename>|<lnum> col <col>|<text>
  1580. The values displayed in each line correspond to the "bufnr", "lnum", "col" and
  1581. "text" fields returned by the |getqflist()| function.
  1582. For some quickfix/location lists, the displayed text needs to be customized.
  1583. For example, if only the filename is present for a quickfix entry, then the
  1584. two "|" field separator characters after the filename are not needed. Another
  1585. use case is to customize the path displayed for a filename. By default, the
  1586. complete path (which may be too long) is displayed for files which are not
  1587. under the current directory tree. The file path may need to be simplified to a
  1588. common parent directory.
  1589. The displayed text can be customized by setting the 'quickfixtextfunc' option
  1590. to a Vim function. This function will be called with a dict argument and
  1591. should return a List of strings to be displayed in the quickfix or location
  1592. list window. The dict argument will have the following fields:
  1593. quickfix set to 1 when called for a quickfix list and 0 when called for
  1594. a location list.
  1595. winid for a location list, set to the id of the window with the
  1596. location list. For a quickfix list, set to 0. Can be used in
  1597. getloclist() to get the location list entry.
  1598. id quickfix or location list identifier
  1599. start_idx index of the first entry for which text should be returned
  1600. end_idx index of the last entry for which text should be returned
  1601. The function should return a single line of text to display in the quickfix
  1602. window for each entry from start_idx to end_idx. The function can obtain
  1603. information about the entries using the |getqflist()| function and specifying
  1604. the quickfix list identifier "id". For a location list, getloclist() function
  1605. can be used with the "winid" argument. If an empty list is returned, then the
  1606. default format is used to display all the entries. If an item in the returned
  1607. list is an empty string, then the default format is used to display the
  1608. corresponding entry.
  1609. If a quickfix or location list specific customization is needed, then the
  1610. 'quickfixtextfunc' attribute of the list can be set using the |setqflist()| or
  1611. |setloclist()| function. This overrides the global 'quickfixtextfunc' option.
  1612. The example below displays the list of old files (|v:oldfiles|) in a quickfix
  1613. window. As there is no line, column number and error text information
  1614. associated with each entry, the 'quickfixtextfunc' function returns only the
  1615. filename.
  1616. Example: >
  1617. " create a quickfix list from v:oldfiles
  1618. call setqflist([], ' ', {'lines' : v:oldfiles, 'efm' : '%f',
  1619. \ 'quickfixtextfunc' : 'QfOldFiles'})
  1620. func QfOldFiles(info)
  1621. " get information about a range of quickfix entries
  1622. let items = getqflist({'id' : a:info.id, 'items' : 1}).items
  1623. let l = []
  1624. for idx in range(a:info.start_idx - 1, a:info.end_idx - 1)
  1625. " use the simplified file name
  1626. call add(l, fnamemodify(bufname(items[idx].bufnr), ':p:.'))
  1627. endfor
  1628. return l
  1629. endfunc
  1630. <
  1631. vim:tw=78:ts=8:noet:ft=help:norl: