quickfix.txt 83 KB

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