quickfix.txt 90 KB

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