quickfix.txt 71 KB

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