blob: 9fb6b18c4182036f6abe10127db4d2beb3e6bc74 [file] [log] [blame]
Bram Moolenaare18dbe82016-07-02 21:42:23 +02001*quickfix.txt* For Vim version 7.4. Last change: 2016 Jul 02
Bram Moolenaar071d4272004-06-13 20:20:40 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7This subject is introduced in section |30.1| of the user manual.
8
91. Using QuickFix commands |quickfix|
102. The error window |quickfix-window|
113. Using more than one list of errors |quickfix-error-lists|
124. Using :make |:make_makeprg|
135. Using :grep |grep|
146. Selecting a compiler |compiler-select|
157. The error format |error-file-format|
168. The directory stack |quickfix-directory-stack|
179. Specific error file formats |errorformats|
18
19{Vi does not have any of these commands}
20
21The quickfix commands are not available when the |+quickfix| feature was
22disabled at compile time.
23
24=============================================================================
251. Using QuickFix commands *quickfix* *Quickfix* *E42*
26
27Vim has a special mode to speedup the edit-compile-edit cycle. This is
28inspired by the quickfix option of the Manx's Aztec C compiler on the Amiga.
29The idea is to save the error messages from the compiler in a file and use Vim
30to jump to the errors one by one. You can examine each problem and fix it,
31without having to remember all the error messages.
32
Bram Moolenaar05159a02005-02-26 23:04:13 +000033In Vim the quickfix commands are used more generally to find a list of
34positions in files. For example, |:vimgrep| finds pattern matches. You can
Bram Moolenaar2641f772005-03-25 21:58:17 +000035use the positions in a script with the |getqflist()| function. Thus you can
Bram Moolenaar05159a02005-02-26 23:04:13 +000036do a lot more than the edit/compile/fix cycle!
37
Bram Moolenaare18dbe82016-07-02 21:42:23 +020038If you have the error messages in a file you can start Vim with: >
39 vim -q filename
40
41From inside Vim an easy way to run a command and handle the output is with the
42|:make| command (see below).
43
44The 'errorformat' option should be set to match the error messages from your
Bram Moolenaar071d4272004-06-13 20:20:40 +000045compiler (see |errorformat| below).
46
Bram Moolenaard12f5c12006-01-25 22:10:52 +000047 *location-list* *E776*
Bram Moolenaar280f1262006-01-30 00:14:18 +000048A location list is similar to a quickfix list and contains a list of positions
49in files. A location list is associated with a window and each window can
50have a separate location list. A location list can be associated with only
51one window. The location list is independent of the quickfix list.
Bram Moolenaard12f5c12006-01-25 22:10:52 +000052
Bram Moolenaar280f1262006-01-30 00:14:18 +000053When a window with a location list is split, the new window gets a copy of the
Bram Moolenaare18dbe82016-07-02 21:42:23 +020054location list. When there are no longer any references to a location list,
55the location list is destroyed.
Bram Moolenaar280f1262006-01-30 00:14:18 +000056
57The following quickfix commands can be used. The location list commands are
58similar to the quickfix commands, replacing the 'c' prefix in the quickfix
59command with 'l'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000060
Bram Moolenaare18c0b32016-03-20 21:08:34 +010061 *E924*
62If the current window was closed by an |autocommand| while processing a
63location list command, it will be aborted.
64
Bram Moolenaarffec3c52016-03-23 20:55:42 +010065 *E925* *E926*
66If the current quickfix or location list was changed by an |autocommand| while
67processing a quickfix or location list command, it will be aborted.
68
Bram Moolenaar071d4272004-06-13 20:20:40 +000069 *:cc*
70:cc[!] [nr] Display error [nr]. If [nr] is omitted, the same
71 error is displayed again. Without [!] this doesn't
72 work when jumping to another buffer, the current buffer
73 has been changed, there is the only window for the
74 buffer and both 'hidden' and 'autowrite' are off.
75 When jumping to another buffer with [!] any changes to
76 the current buffer are lost, unless 'hidden' is set or
77 there is another window for this buffer.
78 The 'switchbuf' settings are respected when jumping
79 to a buffer.
80
Bram Moolenaard12f5c12006-01-25 22:10:52 +000081 *:ll*
82:ll[!] [nr] Same as ":cc", except the location list for the
83 current window is used instead of the quickfix list.
84
Bram Moolenaar071d4272004-06-13 20:20:40 +000085 *:cn* *:cnext* *E553*
86:[count]cn[ext][!] Display the [count] next error in the list that
87 includes a file name. If there are no file names at
88 all, go to the [count] next error. See |:cc| for
89 [!] and 'switchbuf'.
90
Bram Moolenaar17c7c012006-01-26 22:25:15 +000091 *:lne* *:lnext*
92:[count]lne[xt][!] Same as ":cnext", except the location list for the
Bram Moolenaard12f5c12006-01-25 22:10:52 +000093 current window is used instead of the quickfix list.
94
Bram Moolenaar071d4272004-06-13 20:20:40 +000095:[count]cN[ext][!] *:cp* *:cprevious* *:cN* *:cNext*
96:[count]cp[revious][!] Display the [count] previous error in the list that
97 includes a file name. If there are no file names at
98 all, go to the [count] previous error. See |:cc| for
99 [!] and 'switchbuf'.
100
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000101
Bram Moolenaar17c7c012006-01-26 22:25:15 +0000102:[count]lN[ext][!] *:lp* *:lprevious* *:lN* *:lNext*
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000103:[count]lp[revious][!] Same as ":cNext" and ":cprevious", except the location
104 list for the current window is used instead of the
105 quickfix list.
106
Bram Moolenaar071d4272004-06-13 20:20:40 +0000107 *:cnf* *:cnfile*
108:[count]cnf[ile][!] Display the first error in the [count] next file in
109 the list that includes a file name. If there are no
110 file names at all or if there is no next file, go to
111 the [count] next error. See |:cc| for [!] and
112 'switchbuf'.
113
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000114 *:lnf* *:lnfile*
115:[count]lnf[ile][!] Same as ":cnfile", except the location list for the
116 current window is used instead of the quickfix list.
117
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118:[count]cNf[ile][!] *:cpf* *:cpfile* *:cNf* *:cNfile*
119:[count]cpf[ile][!] Display the last error in the [count] previous file in
120 the list that includes a file name. If there are no
121 file names at all or if there is no next file, go to
122 the [count] previous error. See |:cc| for [!] and
123 'switchbuf'.
124
Bram Moolenaar17c7c012006-01-26 22:25:15 +0000125
126:[count]lNf[ile][!] *:lpf* *:lpfile* *:lNf* *:lNfile*
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000127:[count]lpf[ile][!] Same as ":cNfile" and ":cpfile", except the location
128 list for the current window is used instead of the
129 quickfix list.
130
Bram Moolenaar071d4272004-06-13 20:20:40 +0000131 *:crewind* *:cr*
132:cr[ewind][!] [nr] Display error [nr]. If [nr] is omitted, the FIRST
133 error is displayed. See |:cc|.
134
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000135 *:lrewind* *:lr*
136:lr[ewind][!] [nr] Same as ":crewind", except the location list for the
137 current window is used instead of the quickfix list.
138
Bram Moolenaar071d4272004-06-13 20:20:40 +0000139 *:cfirst* *:cfir*
140:cfir[st][!] [nr] Same as ":crewind".
141
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000142 *:lfirst* *:lfir*
143:lfir[st][!] [nr] Same as ":lrewind".
144
Bram Moolenaar071d4272004-06-13 20:20:40 +0000145 *:clast* *:cla*
146:cla[st][!] [nr] Display error [nr]. If [nr] is omitted, the LAST
147 error is displayed. See |:cc|.
148
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000149 *:llast* *:lla*
150:lla[st][!] [nr] Same as ":clast", except the location list for the
151 current window is used instead of the quickfix list.
152
Bram Moolenaar071d4272004-06-13 20:20:40 +0000153 *:cq* *:cquit*
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000154:cq[uit][!] Quit Vim with an error code, so that the compiler
Bram Moolenaar071d4272004-06-13 20:20:40 +0000155 will not compile the same file again.
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000156 WARNING: All changes in files are lost! Also when the
157 [!] is not used. It works like ":qall!" |:qall|,
158 except that Vim returns a non-zero exit code.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000159
160 *:cf* *:cfile*
161:cf[ile][!] [errorfile] Read the error file and jump to the first error.
162 This is done automatically when Vim is started with
163 the -q option. You can use this command when you
164 keep Vim running while compiling. If you give the
165 name of the errorfile, the 'errorfile' option will
166 be set to [errorfile]. See |:cc| for [!].
167
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000168 *:lf* *:lfile*
169:lf[ile][!] [errorfile] Same as ":cfile", except the location list for the
170 current window is used instead of the quickfix list.
171 You can not use the -q command-line option to set
172 the location list.
173
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000174
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000175:cg[etfile] [errorfile] *:cg* *:cgetfile*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000176 Read the error file. Just like ":cfile" but don't
177 jump to the first error.
178
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000179
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000180:lg[etfile] [errorfile] *:lg* *:lgetfile*
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000181 Same as ":cgetfile", except the location list for the
182 current window is used instead of the quickfix list.
183
Bram Moolenaar4770d092006-01-12 23:22:24 +0000184 *:caddf* *:caddfile*
185:caddf[ile] [errorfile] Read the error file and add the errors from the
Bram Moolenaar87e25fd2005-07-27 21:13:01 +0000186 errorfile to the current quickfix list. If a quickfix
187 list is not present, then a new list is created.
188
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000189 *:laddf* *:laddfile*
190:laddf[ile] [errorfile] Same as ":caddfile", except the location list for the
191 current window is used instead of the quickfix list.
192
Bram Moolenaar86b68352004-12-27 21:59:20 +0000193 *:cb* *:cbuffer* *E681*
Bram Moolenaar6cbce9d2007-03-08 10:01:03 +0000194:cb[uffer][!] [bufnr] Read the error list from the current buffer.
Bram Moolenaar86b68352004-12-27 21:59:20 +0000195 When [bufnr] is given it must be the number of a
196 loaded buffer. That buffer will then be used instead
197 of the current buffer.
198 A range can be specified for the lines to be used.
199 Otherwise all lines in the buffer are used.
Bram Moolenaar6cbce9d2007-03-08 10:01:03 +0000200 See |:cc| for [!].
Bram Moolenaar86b68352004-12-27 21:59:20 +0000201
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000202 *:lb* *:lbuffer*
Bram Moolenaar6cbce9d2007-03-08 10:01:03 +0000203:lb[uffer][!] [bufnr] Same as ":cbuffer", except the location list for the
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000204 current window is used instead of the quickfix list.
205
Bram Moolenaardb552d602006-03-23 22:59:57 +0000206 *:cgetb* *:cgetbuffer*
207:cgetb[uffer] [bufnr] Read the error list from the current buffer. Just
208 like ":cbuffer" but don't jump to the first error.
209
210 *:lgetb* *:lgetbuffer*
211:lgetb[uffer] [bufnr] Same as ":cgetbuffer", except the location list for
212 the current window is used instead of the quickfix
213 list.
214
Bram Moolenaara6878372014-03-22 21:02:50 +0100215 *:cad* *:caddbuffer*
Bram Moolenaar76f3b1a2014-03-27 22:30:07 +0100216:cad[dbuffer] [bufnr] Read the error list from the current buffer and add
Bram Moolenaar9f2c6e12006-02-04 22:45:44 +0000217 the errors to the current quickfix list. If a
218 quickfix list is not present, then a new list is
219 created. Otherwise, same as ":cbuffer".
220
221 *:laddb* *:laddbuffer*
222:laddb[uffer] [bufnr] Same as ":caddbuffer", except the location list for
223 the current window is used instead of the quickfix
224 list.
225
Bram Moolenaara40ceaf2006-01-13 22:35:40 +0000226 *:cex* *:cexpr* *E777*
Bram Moolenaar4770d092006-01-12 23:22:24 +0000227:cex[pr][!] {expr} Create a quickfix list using the result of {expr} and
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200228 jump to the first error.
229 If {expr} is a String, then each new-line terminated
Bram Moolenaard6357e82016-01-21 21:48:09 +0100230 line in the String is processed using the global value
231 of 'errorformat' and the result is added to the
232 quickfix list.
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200233 If {expr} is a List, then each String item in the list
234 is processed and added to the quickfix list. Non
235 String items in the List are ignored.
236 See |:cc| for [!].
Bram Moolenaar87e25fd2005-07-27 21:13:01 +0000237 Examples: >
238 :cexpr system('grep -n xyz *')
239 :cexpr getline(1, '$')
240<
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000241 *:lex* *:lexpr*
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200242:lex[pr][!] {expr} Same as |:cexpr|, except the location list for the
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000243 current window is used instead of the quickfix list.
244
Bram Moolenaar76b92b22006-03-24 22:46:53 +0000245 *:cgete* *:cgetexpr*
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000246:cgete[xpr] {expr} Create a quickfix list using the result of {expr}.
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200247 Just like |:cexpr|, but don't jump to the first error.
Bram Moolenaar76b92b22006-03-24 22:46:53 +0000248
249 *:lgete* *:lgetexpr*
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200250:lgete[xpr] {expr} Same as |:cgetexpr|, except the location list for the
Bram Moolenaar76b92b22006-03-24 22:46:53 +0000251 current window is used instead of the quickfix list.
252
Bram Moolenaara6878372014-03-22 21:02:50 +0100253 *:cadde* *:caddexpr*
Bram Moolenaar76f3b1a2014-03-27 22:30:07 +0100254:cadde[xpr] {expr} Evaluate {expr} and add the resulting lines to the
Bram Moolenaar4770d092006-01-12 23:22:24 +0000255 current quickfix list. If a quickfix list is not
256 present, then a new list is created. The current
257 cursor position will not be changed. See |:cexpr| for
258 more information.
259 Example: >
260 :g/mypattern/caddexpr expand("%") . ":" . line(".") . ":" . getline(".")
261<
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000262 *:lad* *:laddexpr*
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000263:lad[dexpr] {expr} Same as ":caddexpr", except the location list for the
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000264 current window is used instead of the quickfix list.
265
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266 *:cl* *:clist*
267:cl[ist] [from] [, [to]]
268 List all errors that are valid |quickfix-valid|.
269 If numbers [from] and/or [to] are given, the respective
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000270 range of errors is listed. A negative number counts
Bram Moolenaar071d4272004-06-13 20:20:40 +0000271 from the last error backwards, -1 being the last error.
272 The 'switchbuf' settings are respected when jumping
273 to a buffer.
274
Bram Moolenaare8fea072016-07-01 14:48:27 +0200275:cl[ist] +{count} List the current and next {count} valid errors. This
276 is similar to ":clist from from+count", where "from"
277 is the current error position.
278
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279:cl[ist]! [from] [, [to]]
280 List all errors.
281
Bram Moolenaare8fea072016-07-01 14:48:27 +0200282:cl[ist]! +{count} List the current and next {count} error lines. This
283 is useful to see unrecognized lines after the current
284 one. For example, if ":clist" shows:
285 8384 testje.java:252: error: cannot find symbol ~
286 Then using ":cl! +3" shows the reason:
287 8384 testje.java:252: error: cannot find symbol ~
288 8385: ZexitCode = Fmainx(); ~
289 8386: ^ ~
290 8387: symbol: method Fmainx() ~
291
292:lli[st] [from] [, [to]] *:lli* *:llist*
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000293 Same as ":clist", except the location list for the
294 current window is used instead of the quickfix list.
295
296:lli[st]! [from] [, [to]]
297 List all the entries in the location list for the
298 current window.
299
Bram Moolenaar071d4272004-06-13 20:20:40 +0000300If you insert or delete lines, mostly the correct error location is still
301found because hidden marks are used. Sometimes, when the mark has been
302deleted for some reason, the message "line changed" is shown to warn you that
303the error location may not be correct. If you quit Vim and start again the
304marks are lost and the error locations may not be correct anymore.
305
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000306If vim is built with |+autocmd| support, two autocommands are available for
307running commands before and after a quickfix command (':make', ':grep' and so
308on) is executed. See |QuickFixCmdPre| and |QuickFixCmdPost| for details.
309
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000310 *QuickFixCmdPost-example*
311When 'encoding' differs from the locale, the error messages may have a
312different encoding from what Vim is using. To convert the messages you can
313use this code: >
314 function QfMakeConv()
315 let qflist = getqflist()
316 for i in qflist
317 let i.text = iconv(i.text, "cp936", "utf-8")
318 endfor
319 call setqflist(qflist)
320 endfunction
321
322 au QuickfixCmdPost make call QfMakeConv()
323
324
Bram Moolenaar12969c02015-09-08 23:36:10 +0200325EXECUTE A COMMAND IN ALL THE BUFFERS IN QUICKFIX OR LOCATION LIST:
326 *:cdo*
327:cdo[!] {cmd} Execute {cmd} in each valid entry in the quickfix list.
328 It works like doing this: >
329 :cfirst
330 :{cmd}
331 :cnext
332 :{cmd}
333 etc.
334< When the current file can't be |abandon|ed and the [!]
335 is not present, the command fails.
Bram Moolenaare8fea072016-07-01 14:48:27 +0200336 When an error is detected execution stops.
Bram Moolenaar12969c02015-09-08 23:36:10 +0200337 The last buffer (or where an error occurred) becomes
338 the current buffer.
339 {cmd} can contain '|' to concatenate several commands.
340
341 Only valid entries in the quickfix list are used.
342 A range can be used to select entries, e.g.: >
343 :10,$cdo cmd
344< To skip entries 1 to 9.
345
346 Note: While this command is executing, the Syntax
347 autocommand event is disabled by adding it to
348 'eventignore'. This considerably speeds up editing
349 each buffer.
350 {not in Vi} {not available when compiled without the
351 |+listcmds| feature}
352 Also see |:bufdo|, |:tabdo|, |:argdo|, |:windo|,
353 |:ldo|, |:cfdo| and |:lfdo|.
354
355 *:cfdo*
356:cfdo[!] {cmd} Execute {cmd} in each file in the quickfix list.
357 It works like doing this: >
358 :cfirst
359 :{cmd}
360 :cnfile
361 :{cmd}
362 etc.
363< Otherwise it works the same as `:cdo`.
364 {not in Vi} {not available when compiled without the
365 |+listcmds| feature}
366
367 *:ldo*
368:ld[o][!] {cmd} Execute {cmd} in each valid entry in the location list
369 for the current window.
370 It works like doing this: >
371 :lfirst
372 :{cmd}
373 :lnext
374 :{cmd}
375 etc.
376< Only valid entries in the location list are used.
377 Otherwise it works the same as `:cdo`.
378 {not in Vi} {not available when compiled without the
379 |+listcmds| feature}
380
381 *:lfdo*
382:lfdo[!] {cmd} Execute {cmd} in each file in the location list for
383 the current window.
384 It works like doing this: >
385 :lfirst
386 :{cmd}
387 :lnfile
388 :{cmd}
389 etc.
390< Otherwise it works the same as `:ldo`.
391 {not in Vi} {not available when compiled without the
392 |+listcmds| feature}
393
Bram Moolenaar071d4272004-06-13 20:20:40 +0000394=============================================================================
3952. The error window *quickfix-window*
396
Bram Moolenaar7fd73202010-07-25 16:58:46 +0200397 *:cope* *:copen* *w:quickfix_title*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000398:cope[n] [height] Open a window to show the current list of errors.
Bram Moolenaar76f3b1a2014-03-27 22:30:07 +0100399
Bram Moolenaar071d4272004-06-13 20:20:40 +0000400 When [height] is given, the window becomes that high
Bram Moolenaar76f3b1a2014-03-27 22:30:07 +0100401 (if there is room). When [height] is omitted the
402 window is made ten lines high.
403
Bram Moolenaar071d4272004-06-13 20:20:40 +0000404 If there already is a quickfix window, it will be made
405 the current window. It is not possible to open a
Bram Moolenaar76f3b1a2014-03-27 22:30:07 +0100406 second quickfix window. If [height] is given the
407 existing window will be resized to it.
408
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.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000416
Bram Moolenaar17c7c012006-01-26 22:25:15 +0000417 *:lop* *:lopen*
418:lop[en] [height] Open a window to show the location list for the
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000419 current window. Works only when the location list for
Bram Moolenaar17c7c012006-01-26 22:25:15 +0000420 the current window is present. You can have more than
421 one location window opened at a time. Otherwise, it
Bram Moolenaar280f1262006-01-30 00:14:18 +0000422 acts the same as ":copen".
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000423
Bram Moolenaar071d4272004-06-13 20:20:40 +0000424 *:ccl* *:cclose*
425:ccl[ose] Close the quickfix window.
426
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000427 *:lcl* *:lclose*
428:lcl[ose] Close the window showing the location list for the
429 current window.
430
Bram Moolenaar071d4272004-06-13 20:20:40 +0000431 *:cw* *:cwindow*
432:cw[indow] [height] Open the quickfix window when there are recognized
433 errors. If the window is already open and there are
434 no recognized errors, close the window.
435
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000436 *:lw* *:lwindow*
437:lw[indow] [height] Same as ":cwindow", except use the window showing the
438 location list for the current window.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000439
Bram Moolenaardcb17002016-07-07 18:58:59 +0200440:cbo[ttom] Put the cursor in the last line of the quickfix window
441 and scroll to make it visible. This is useful for
442 when errors are added by an asynchronous callback.
443 Only call it once in a while if there are many
444 updates to avoid a lot of redrawing.
445
Bram Moolenaar071d4272004-06-13 20:20:40 +0000446Normally the quickfix window is at the bottom of the screen. If there are
447vertical splits, it's at the bottom of the rightmost column of windows. To
448make it always occupy the full width: >
449 :botright cwindow
450You can move the window around with |window-moving| commands.
451For example, to move it to the top: CTRL-W K
452The 'winfixheight' option will be set, which means that the window will mostly
453keep its height, ignoring 'winheight' and 'equalalways'. You can change the
454height manually (e.g., by dragging the status line above it with the mouse).
455
456In the quickfix window, each line is one error. The line number is equal to
457the error number. You can use ":.cc" to jump to the error under the cursor.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000458Hitting the <Enter> key or double-clicking the mouse on a line has the same
Bram Moolenaar071d4272004-06-13 20:20:40 +0000459effect. The file containing the error is opened in the window above the
460quickfix window. If there already is a window for that file, it is used
461instead. If the buffer in the used window has changed, and the error is in
462another file, jumping to the error will fail. You will first have to make
463sure the window contains a buffer which can be abandoned.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000464 *CTRL-W_<Enter>* *CTRL-W_<CR>*
465You can use CTRL-W <Enter> to open a new window and jump to the error there.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000466
467When the quickfix window has been filled, two autocommand events are
468triggered. First the 'filetype' option is set to "qf", which triggers the
Bram Moolenaar1ef15e32006-02-01 21:56:25 +0000469FileType event. Then the BufReadPost event is triggered, using "quickfix" for
470the buffer name. This can be used to perform some action on the listed
471errors. Example: >
Bram Moolenaar280f1262006-01-30 00:14:18 +0000472 au BufReadPost quickfix setlocal modifiable
473 \ | silent exe 'g/^/s//\=line(".")." "/'
474 \ | setlocal nomodifiable
Bram Moolenaar071d4272004-06-13 20:20:40 +0000475This prepends the line number to each line. Note the use of "\=" in the
476substitute string of the ":s" command, which is used to evaluate an
477expression.
Bram Moolenaar1ef15e32006-02-01 21:56:25 +0000478The BufWinEnter event is also triggered, again using "quickfix" for the buffer
479name.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000480
Bram Moolenaar82af8712016-06-04 20:20:29 +0200481Note: When adding to an existing quickfix list the autocommand are not
482triggered.
483
Bram Moolenaar071d4272004-06-13 20:20:40 +0000484Note: Making changes in the quickfix window has no effect on the list of
485errors. 'modifiable' is off to avoid making changes. If you delete or insert
486lines anyway, the relation between the text and the error number is messed up.
487If you really want to do this, you could write the contents of the quickfix
488window to a file and use ":cfile" to have it parsed and used as the new error
489list.
490
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000491 *location-list-window*
Bram Moolenaar280f1262006-01-30 00:14:18 +0000492The location list window displays the entries in a location list. When you
493open a location list window, it is created below the current window and
494displays the location list for the current window. The location list window
495is similar to the quickfix window, except that you can have more than one
Bram Moolenaar1ef15e32006-02-01 21:56:25 +0000496location list window open at a time. When you use a location list command in
497this window, the displayed location list is used.
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000498
Bram Moolenaar280f1262006-01-30 00:14:18 +0000499When you select a file from the location list window, the following steps are
500used to find a window to edit the file:
501
5021. If a window with the location list displayed in the location list window is
503 present, then the file is opened in that window.
5042. If the above step fails and if the file is already opened in another
505 window, then that window is used.
5063. If the above step fails then an existing window showing a buffer with
507 'buftype' not set is used.
5084. If the above step fails, then the file is edited in a new window.
509
510In all of the above cases, if the location list for the selected window is not
511yet set, then it is set to the location list displayed in the location list
512window.
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000513
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514=============================================================================
5153. Using more than one list of errors *quickfix-error-lists*
516
517So far has been assumed that there is only one list of errors. Actually the
518ten last used lists are remembered. When starting a new list, the previous
519ones are automatically kept. Two commands can be used to access older error
520lists. They set one of the existing error lists as the current one.
521
522 *:colder* *:col* *E380*
523:col[der] [count] Go to older error list. When [count] is given, do
524 this [count] times. When already at the oldest error
525 list, an error message is given.
526
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000527 *:lolder* *:lol*
528:lol[der] [count] Same as ":colder", except use the location list for
529 the current window instead of the quickfix list.
530
Bram Moolenaar071d4272004-06-13 20:20:40 +0000531 *:cnewer* *:cnew* *E381*
532:cnew[er] [count] Go to newer error list. When [count] is given, do
533 this [count] times. When already at the newest error
534 list, an error message is given.
535
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000536 *:lnewer* *:lnew*
537:lnew[er] [count] Same as ":cnewer", except use the location list for
538 the current window instead of the quickfix list.
539
Bram Moolenaar071d4272004-06-13 20:20:40 +0000540When adding a new error list, it becomes the current list.
541
542When ":colder" has been used and ":make" or ":grep" is used to add a new error
543list, one newer list is overwritten. This is especially useful if you are
544browsing with ":grep" |grep|. If you want to keep the more recent error
545lists, use ":cnewer 99" first.
546
547=============================================================================
5484. Using :make *:make_makeprg*
549
550 *:mak* *:make*
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000551:mak[e][!] [arguments] 1. If vim was built with |+autocmd|, all relevant
552 |QuickFixCmdPre| autocommands are executed.
553 2. If the 'autowrite' option is on, write any changed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554 buffers
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000555 3. An errorfile name is made from 'makeef'. If
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 'makeef' doesn't contain "##", and a file with this
557 name already exists, it is deleted.
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000558 4. The program given with the 'makeprg' option is
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 started (default "make") with the optional
560 [arguments] and the output is saved in the
561 errorfile (for Unix it is also echoed on the
562 screen).
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000563 5. The errorfile is read using 'errorformat'.
Bram Moolenaar6b803a72007-05-06 14:25:46 +0000564 6. If vim was built with |+autocmd|, all relevant
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000565 |QuickFixCmdPost| autocommands are executed.
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000566 See example below.
Bram Moolenaar6b803a72007-05-06 14:25:46 +0000567 7. If [!] is not given the first error is jumped to.
568 8. The errorfile is deleted.
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000569 9. You can now move through the errors with commands
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 like |:cnext| and |:cprevious|, see above.
571 This command does not accept a comment, any "
572 characters are considered part of the arguments.
573
Bram Moolenaar9f2c6e12006-02-04 22:45:44 +0000574 *:lmak* *:lmake*
575:lmak[e][!] [arguments]
576 Same as ":make", except the location list for the
577 current window is used instead of the quickfix list.
578
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579The ":make" command executes the command given with the 'makeprg' option.
580This is done by passing the command to the shell given with the 'shell'
581option. This works almost like typing
582
583 ":!{makeprg} [arguments] {shellpipe} {errorfile}".
584
585{makeprg} is the string given with the 'makeprg' option. Any command can be
586used, not just "make". Characters '%' and '#' are expanded as usual on a
587command-line. You can use "%<" to insert the current file name without
588extension, or "#<" to insert the alternate file name without extension, for
589example: >
590 :set makeprg=make\ #<.o
591
592[arguments] is anything that is typed after ":make".
593{shellpipe} is the 'shellpipe' option.
594{errorfile} is the 'makeef' option, with ## replaced to make it unique.
595
Bram Moolenaar6dfc28b2010-02-11 14:19:15 +0100596The placeholder "$*" can be used for the argument list in {makeprg} if the
Bram Moolenaar071d4272004-06-13 20:20:40 +0000597command needs some additional characters after its arguments. The $* is
598replaced then by all arguments. Example: >
599 :set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}
600or simpler >
601 :let &mp = 'latex \\nonstopmode \\input\{$*}'
602"$*" can be given multiple times, for example: >
603 :set makeprg=gcc\ -o\ $*\ $*
604
605The 'shellpipe' option defaults to ">" for the Amiga, MS-DOS and Win32. This
606means that the output of the compiler is saved in a file and not shown on the
607screen directly. For Unix "| tee" is used. The compiler output is shown on
608the screen and saved in a file the same time. Depending on the shell used
609"|& tee" or "2>&1| tee" is the default, so stderr output will be included.
610
611If 'shellpipe' is empty, the {errorfile} part will be omitted. This is useful
612for compilers that write to an errorfile themselves (e.g., Manx's Amiga C).
613
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000614
615Using QuickFixCmdPost to fix the encoding ~
616
617It may be that 'encoding' is set to an encoding that differs from the messages
618your build program produces. This example shows how to fix this after Vim has
619read the error messages: >
620
621 function QfMakeConv()
622 let qflist = getqflist()
623 for i in qflist
624 let i.text = iconv(i.text, "cp936", "utf-8")
625 endfor
626 call setqflist(qflist)
627 endfunction
628
629 au QuickfixCmdPost make call QfMakeConv()
630
631(Example by Faque Cheng)
632
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633==============================================================================
Bram Moolenaar86b68352004-12-27 21:59:20 +00006345. Using :vimgrep and :grep *grep* *lid*
635
636Vim has two ways to find matches for a pattern: Internal and external. The
637advantage of the internal grep is that it works on all systems and uses the
638powerful Vim search patterns. An external grep program can be used when the
639Vim grep does not do what you want.
640
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000641The internal method will be slower, because files are read into memory. The
642advantages are:
643- Line separators and encoding are automatically recognized, as if a file is
644 being edited.
645- Uses Vim search patterns. Multi-line patterns can be used.
646- When plugins are enabled: compressed and remote files can be searched.
647 |gzip| |netrw|
Bram Moolenaara3227e22006-03-08 21:32:40 +0000648
649To be able to do this Vim loads each file as if it is being edited. When
Bram Moolenaar1056d982006-03-09 22:37:52 +0000650there is no match in the file the associated buffer is wiped out again. The
Bram Moolenaara3227e22006-03-08 21:32:40 +0000651'hidden' option is ignored here to avoid running out of memory or file
652descriptors when searching many files. However, when the |:hide| command
653modifier is used the buffers are kept loaded. This makes following searches
654in the same files a lot faster.
Bram Moolenaar86b68352004-12-27 21:59:20 +0000655
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200656Note that |:copen| (or |:lopen| for |:lgrep|) may be used to open a buffer
657containing the search results in linked form. The |:silent| command may be
Bram Moolenaard58e9292011-02-09 17:07:58 +0100658used to suppress the default full screen grep output. The ":grep!" form of
Bram Moolenaar483c5d82010-10-20 18:45:33 +0200659the |:grep| command doesn't jump to the first match automatically. These
660commands can be combined to create a NewGrep command: >
661
662 command! -nargs=+ NewGrep execute 'silent grep! <args>' | copen 42
663
Bram Moolenaar86b68352004-12-27 21:59:20 +0000664
6655.1 using Vim's internal grep
666
Bram Moolenaare49b69a2005-01-08 16:11:57 +0000667 *:vim* *:vimgrep* *E682* *E683*
Bram Moolenaar05159a02005-02-26 23:04:13 +0000668:vim[grep][!] /{pattern}/[g][j] {file} ...
Bram Moolenaar86b68352004-12-27 21:59:20 +0000669 Search for {pattern} in the files {file} ... and set
Bram Moolenaar30b65812012-07-12 22:01:11 +0200670 the error list to the matches. Files matching
671 'wildignore' are ignored; files in 'suffixes' are
672 searched last.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000673 Without the 'g' flag each line is added only once.
674 With 'g' every match is added.
675
676 {pattern} is a Vim search pattern. Instead of
677 enclosing it in / any non-ID character (see
678 |'isident'|) can be used, so long as it does not
679 appear in {pattern}.
680 'ignorecase' applies. To overrule it put |/\c| in the
681 pattern to ignore case or |/\C| to match case.
682 'smartcase' is not used.
Bram Moolenaar60abe752013-03-07 16:32:54 +0100683 If {pattern} is empty (e.g. // is specified), the last
684 used search pattern is used. |last-pattern|
Bram Moolenaar05159a02005-02-26 23:04:13 +0000685
Bram Moolenaar1f35bf92006-03-07 22:38:47 +0000686 When a number is put before the command this is used
687 as the maximum number of matches to find. Use
688 ":1vimgrep pattern file" to find only the first.
689 Useful if you only want to check if there is a match
690 and quit quickly when it's found.
691
Bram Moolenaar05159a02005-02-26 23:04:13 +0000692 Without the 'j' flag Vim jumps to the first match.
693 With 'j' only the quickfix list is updated.
694 With the [!] any changes in the current buffer are
695 abandoned.
696
Bram Moolenaardcaf10e2005-01-21 11:55:25 +0000697 Every second or so the searched file name is displayed
698 to give you an idea of the progress made.
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000699 Examples: >
700 :vimgrep /an error/ *.c
701 :vimgrep /\<FileName\>/ *.h include/*
Bram Moolenaar231334e2005-07-25 20:46:57 +0000702 :vimgrep /myfunc/ **/*.c
703< For the use of "**" see |starstar-wildcard|.
Bram Moolenaar86b68352004-12-27 21:59:20 +0000704
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000705:vim[grep][!] {pattern} {file} ...
706 Like above, but instead of enclosing the pattern in a
707 non-ID character use a white-separated pattern. The
708 pattern must start with an ID character.
709 Example: >
710 :vimgrep Error *.c
711<
Bram Moolenaar9f2c6e12006-02-04 22:45:44 +0000712 *:lv* *:lvimgrep*
713:lv[imgrep][!] /{pattern}/[g][j] {file} ...
714:lv[imgrep][!] {pattern} {file} ...
715 Same as ":vimgrep", except the location list for the
716 current window is used instead of the quickfix list.
717
Bram Moolenaar86b68352004-12-27 21:59:20 +0000718 *:vimgrepa* *:vimgrepadd*
Bram Moolenaar05159a02005-02-26 23:04:13 +0000719:vimgrepa[dd][!] /{pattern}/[g][j] {file} ...
720:vimgrepa[dd][!] {pattern} {file} ...
Bram Moolenaar86b68352004-12-27 21:59:20 +0000721 Just like ":vimgrep", but instead of making a new list
722 of errors the matches are appended to the current
723 list.
724
Bram Moolenaar9f2c6e12006-02-04 22:45:44 +0000725 *:lvimgrepa* *:lvimgrepadd*
726:lvimgrepa[dd][!] /{pattern}/[g][j] {file} ...
727:lvimgrepa[dd][!] {pattern} {file} ...
728 Same as ":vimgrepadd", except the location list for
729 the current window is used instead of the quickfix
730 list.
Bram Moolenaar86b68352004-12-27 21:59:20 +0000731
7325.2 External grep
Bram Moolenaar071d4272004-06-13 20:20:40 +0000733
734Vim can interface with "grep" and grep-like programs (such as the GNU
735id-utils) in a similar way to its compiler integration (see |:make| above).
736
737[Unix trivia: The name for the Unix "grep" command comes from ":g/re/p", where
738"re" stands for Regular Expression.]
739
740 *:gr* *:grep*
741:gr[ep][!] [arguments] Just like ":make", but use 'grepprg' instead of
742 'makeprg' and 'grepformat' instead of 'errorformat'.
Bram Moolenaar86b68352004-12-27 21:59:20 +0000743 When 'grepprg' is "internal" this works like
744 |:vimgrep|. Note that the pattern needs to be
745 enclosed in separator characters then.
Bram Moolenaar9f2c6e12006-02-04 22:45:44 +0000746
747 *:lgr* *:lgrep*
748:lgr[ep][!] [arguments] Same as ":grep", except the location list for the
749 current window is used instead of the quickfix list.
750
Bram Moolenaar071d4272004-06-13 20:20:40 +0000751 *:grepa* *:grepadd*
752:grepa[dd][!] [arguments]
753 Just like ":grep", but instead of making a new list of
754 errors the matches are appended to the current list.
755 Example: >
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +0100756 :call setqflist([])
Bram Moolenaar071d4272004-06-13 20:20:40 +0000757 :bufdo grepadd! something %
758< The first command makes a new error list which is
759 empty. The second command executes "grepadd" for each
760 listed buffer. Note the use of ! to avoid that
761 ":grepadd" jumps to the first error, which is not
762 allowed with |:bufdo|.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +0100763 An example that uses the argument list and avoids
764 errors for files without matches: >
765 :silent argdo try
766 \ | grepadd! something %
767 \ | catch /E480:/
768 \ | endtry"
769<
Bram Moolenaar9f2c6e12006-02-04 22:45:44 +0000770 *:lgrepa* *:lgrepadd*
771:lgrepa[dd][!] [arguments]
772 Same as ":grepadd", except the location list for the
773 current window is used instead of the quickfix list.
774
Bram Moolenaar86b68352004-12-27 21:59:20 +00007755.3 Setting up external grep
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776
777If you have a standard "grep" program installed, the :grep command may work
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000778well with the defaults. The syntax is very similar to the standard command: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000779
780 :grep foo *.c
781
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000782Will search all files with the .c extension for the substring "foo". The
Bram Moolenaar071d4272004-06-13 20:20:40 +0000783arguments to :grep are passed straight to the "grep" program, so you can use
784whatever options your "grep" supports.
785
786By default, :grep invokes grep with the -n option (show file and line
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000787numbers). You can change this with the 'grepprg' option. You will need to set
Bram Moolenaar071d4272004-06-13 20:20:40 +0000788'grepprg' if:
789
790a) You are using a program that isn't called "grep"
791b) You have to call grep with a full path
792c) You want to pass other options automatically (e.g. case insensitive
793 search.)
794
795Once "grep" has executed, Vim parses the results using the 'grepformat'
796option. This option works in the same way as the 'errorformat' option - see
797that for details. You may need to change 'grepformat' from the default if
798your grep outputs in a non-standard format, or you are using some other
799program with a special format.
800
801Once the results are parsed, Vim loads the first file containing a match and
802jumps to the appropriate line, in the same way that it jumps to a compiler
803error in |quickfix| mode. You can then use the |:cnext|, |:clist|, etc.
804commands to see the other matches.
805
806
Bram Moolenaar86b68352004-12-27 21:59:20 +00008075.4 Using :grep with id-utils
Bram Moolenaar071d4272004-06-13 20:20:40 +0000808
809You can set up :grep to work with the GNU id-utils like this: >
810
811 :set grepprg=lid\ -Rgrep\ -s
812 :set grepformat=%f:%l:%m
813
814then >
815 :grep (regexp)
816
817works just as you'd expect.
818(provided you remembered to mkid first :)
819
820
Bram Moolenaar86b68352004-12-27 21:59:20 +00008215.5 Browsing source code with :vimgrep or :grep
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822
823Using the stack of error lists that Vim keeps, you can browse your files to
824look for functions and the functions they call. For example, suppose that you
825have to add an argument to the read_file() function. You enter this command: >
826
Bram Moolenaar86b68352004-12-27 21:59:20 +0000827 :vimgrep /\<read_file\>/ *.c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000828
829You use ":cn" to go along the list of matches and add the argument. At one
830place you have to get the new argument from a higher level function msg(), and
831need to change that one too. Thus you use: >
832
Bram Moolenaar86b68352004-12-27 21:59:20 +0000833 :vimgrep /\<msg\>/ *.c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000834
835While changing the msg() functions, you find another function that needs to
Bram Moolenaar86b68352004-12-27 21:59:20 +0000836get the argument from a higher level. You can again use ":vimgrep" to find
837these functions. Once you are finished with one function, you can use >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000838
839 :colder
840
841to go back to the previous one.
842
Bram Moolenaar86b68352004-12-27 21:59:20 +0000843This works like browsing a tree: ":vimgrep" goes one level deeper, creating a
Bram Moolenaar071d4272004-06-13 20:20:40 +0000844list of branches. ":colder" goes back to the previous level. You can mix
Bram Moolenaar86b68352004-12-27 21:59:20 +0000845this use of ":vimgrep" and "colder" to browse all the locations in a tree-like
Bram Moolenaar071d4272004-06-13 20:20:40 +0000846way. If you do this consistently, you will find all locations without the
847need to write down a "todo" list.
848
849=============================================================================
8506. Selecting a compiler *compiler-select*
851
852 *:comp* *:compiler* *E666*
853:comp[iler][!] {name} Set options to work with compiler {name}.
854 Without the "!" options are set for the
855 current buffer. With "!" global options are
856 set.
857 If you use ":compiler foo" in "file.foo" and
858 then ":compiler! bar" in another buffer, Vim
859 will keep on using "foo" in "file.foo".
860 {not available when compiled without the
861 |+eval| feature}
862
863
864The Vim plugins in the "compiler" directory will set options to use the
865selected compiler. For ":compiler" local options are set, for ":compiler!"
866global options.
867 *current_compiler*
868To support older Vim versions, the plugins always use "current_compiler" and
869not "b:current_compiler". What the command actually does is the following:
870
871- Delete the "current_compiler" and "b:current_compiler" variables.
872- Define the "CompilerSet" user command. With "!" it does ":set", without "!"
873 it does ":setlocal".
874- Execute ":runtime! compiler/{name}.vim". The plugins are expected to set
875 options with "CompilerSet" and set the "current_compiler" variable to the
876 name of the compiler.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000877- Delete the "CompilerSet" user command.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000878- Set "b:current_compiler" to the value of "current_compiler".
879- Without "!" the old value of "current_compiler" is restored.
880
881
882For writing a compiler plugin, see |write-compiler-plugin|.
883
884
Bram Moolenaarbae0c162007-05-10 19:30:25 +0000885GCC *quickfix-gcc* *compiler-gcc*
886
887There's one variable you can set for the GCC compiler:
888
889g:compiler_gcc_ignore_unmatched_lines
890 Ignore lines that don't match any patterns
891 defined for GCC. Useful if output from
892 commands run from make are generating false
893 positives.
894
895
Bram Moolenaar071d4272004-06-13 20:20:40 +0000896MANX AZTEC C *quickfix-manx* *compiler-manx*
897
898To use Vim with Manx's Aztec C compiler on the Amiga you should do the
899following:
900- Set the CCEDIT environment variable with the command: >
901 mset "CCEDIT=vim -q"
902- Compile with the -qf option. If the compiler finds any errors, Vim is
903 started and the cursor is positioned on the first error. The error message
904 will be displayed on the last line. You can go to other errors with the
905 commands mentioned above. You can fix the errors and write the file(s).
906- If you exit Vim normally the compiler will re-compile the same file. If you
907 exit with the :cq command, the compiler will terminate. Do this if you
908 cannot fix the error, or if another file needs to be compiled first.
909
910There are some restrictions to the Quickfix mode on the Amiga. The
911compiler only writes the first 25 errors to the errorfile (Manx's
912documentation does not say how to get more). If you want to find the others,
913you will have to fix a few errors and exit the editor. After recompiling,
914up to 25 remaining errors will be found.
915
916If Vim was started from the compiler, the :sh and some :! commands will not
917work, because Vim is then running in the same process as the compiler and
918stdin (standard input) will not be interactive.
919
920
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000921PERL *quickfix-perl* *compiler-perl*
922
923The Perl compiler plugin doesn't actually compile, but invokes Perl's internal
924syntax checking feature and parses the output for possible errors so you can
925correct them in quick-fix mode.
926
927Warnings are forced regardless of "no warnings" or "$^W = 0" within the file
928being checked. To disable this set g:perl_compiler_force_warnings to a zero
929value. For example: >
930 let g:perl_compiler_force_warnings = 0
931
932
Bram Moolenaar071d4272004-06-13 20:20:40 +0000933PYUNIT COMPILER *compiler-pyunit*
934
935This is not actually a compiler, but a unit testing framework for the
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000936Python language. It is included into standard Python distribution
937starting from version 2.0. For older versions, you can get it from
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938http://pyunit.sourceforge.net.
939
940When you run your tests with the help of the framework, possible errors
941are parsed by Vim and presented for you in quick-fix mode.
942
943Unfortunately, there is no standard way to run the tests.
944The alltests.py script seems to be used quite often, that's all.
945Useful values for the 'makeprg' options therefore are:
946 setlocal makeprg=./alltests.py " Run a testsuite
Bram Moolenaar26df0922014-02-23 23:39:13 +0100947 setlocal makeprg=python\ %:S " Run a single testcase
Bram Moolenaar071d4272004-06-13 20:20:40 +0000948
949Also see http://vim.sourceforge.net/tip_view.php?tip_id=280.
950
951
952TEX COMPILER *compiler-tex*
953
954Included in the distribution compiler for TeX ($VIMRUNTIME/compiler/tex.vim)
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000955uses make command if possible. If the compiler finds a file named "Makefile"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000956or "makefile" in the current directory, it supposes that you want to process
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000957your *TeX files with make, and the makefile does the right work. In this case
958compiler sets 'errorformat' for *TeX output and leaves 'makeprg' untouched. If
Bram Moolenaar071d4272004-06-13 20:20:40 +0000959neither "Makefile" nor "makefile" is found, the compiler will not use make.
960You can force the compiler to ignore makefiles by defining
961b:tex_ignore_makefile or g:tex_ignore_makefile variable (they are checked for
962existence only).
963
964If the compiler chose not to use make, it need to choose a right program for
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000965processing your input. If b:tex_flavor or g:tex_flavor (in this precedence)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000966variable exists, it defines TeX flavor for :make (actually, this is the name
967of executed command), and if both variables do not exist, it defaults to
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000968"latex". For example, while editing chapter2.tex \input-ed from mypaper.tex
Bram Moolenaar071d4272004-06-13 20:20:40 +0000969written in AMS-TeX: >
970
971 :let b:tex_flavor = 'amstex'
972 :compiler tex
973< [editing...] >
974 :make mypaper
975
976Note that you must specify a name of the file to process as an argument (to
977process the right file when editing \input-ed or \include-ed file; portable
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000978solution for substituting % for no arguments is welcome). This is not in the
Bram Moolenaar071d4272004-06-13 20:20:40 +0000979semantics of make, where you specify a target, not source, but you may specify
980filename without extension ".tex" and mean this as "make filename.dvi or
981filename.pdf or filename.some_result_extension according to compiler".
982
983Note: tex command line syntax is set to usable both for MikTeX (suggestion
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000984by Srinath Avadhanula) and teTeX (checked by Artem Chuprina). Suggestion
Bram Moolenaar071d4272004-06-13 20:20:40 +0000985from |errorformat-LaTeX| is too complex to keep it working for different
986shells and OSes and also does not allow to use other available TeX options,
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000987if any. If your TeX doesn't support "-interaction=nonstopmode", please
Bram Moolenaar071d4272004-06-13 20:20:40 +0000988report it with different means to express \nonstopmode from the command line.
989
990=============================================================================
9917. The error format *error-file-format*
992
993 *errorformat* *E372* *E373* *E374*
994 *E375* *E376* *E377* *E378*
995The 'errorformat' option specifies a list of formats that are recognized. The
996first format that matches with an error message is used. You can add several
997formats for different messages your compiler produces, or even entries for
998multiple compilers. See |efm-entries|.
999
1000Each entry in 'errorformat' is a scanf-like string that describes the format.
1001First, you need to know how scanf works. Look in the documentation of your
1002C compiler. Below you find the % items that Vim understands. Others are
1003invalid.
1004
1005Special characters in 'errorformat' are comma and backslash. See
1006|efm-entries| for how to deal with them. Note that a literal "%" is matched
1007by "%%", thus it is not escaped with a backslash.
Bram Moolenaar9d98fe92013-08-03 18:35:36 +02001008Keep in mind that in the `:make` and `:grep` output all NUL characters are
1009replaced with SOH (0x01).
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010
1011Note: By default the difference between upper and lowercase is ignored. If
1012you want to match case, add "\C" to the pattern |/\C|.
1013
1014
1015Basic items
1016
1017 %f file name (finds a string)
1018 %l line number (finds a number)
1019 %c column number (finds a number representing character
1020 column of the error, (1 <tab> == 1 character column))
1021 %v virtual column number (finds a number representing
1022 screen column of the error (1 <tab> == 8 screen
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001023 columns))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001024 %t error type (finds a single character)
1025 %n error number (finds a number)
1026 %m error message (finds a string)
1027 %r matches the "rest" of a single-line file message %O/P/Q
Bram Moolenaarc8734422012-06-01 22:38:45 +02001028 %p pointer line (finds a sequence of '-', '.', ' ' or
1029 tabs and uses the length for the column number)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030 %*{conv} any scanf non-assignable conversion
1031 %% the single '%' character
Bram Moolenaar2641f772005-03-25 21:58:17 +00001032 %s search text (finds a string)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001033
Bram Moolenaare344bea2005-09-01 20:46:49 +00001034The "%f" conversion may depend on the current 'isfname' setting. "~/" is
Bram Moolenaarf4630b62005-05-20 21:31:17 +00001035expanded to the home directory and environment variables are expanded.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001036
Bram Moolenaare344bea2005-09-01 20:46:49 +00001037The "%f" and "%m" conversions have to detect the end of the string. This
Bram Moolenaar482aaeb2005-09-29 18:26:07 +00001038normally happens by matching following characters and items. When nothing is
Bram Moolenaare344bea2005-09-01 20:46:49 +00001039following the rest of the line is matched. If "%f" is followed by a '%' or a
1040backslash, it will look for a sequence of 'isfname' characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001041
1042On MS-DOS, MS-Windows and OS/2 a leading "C:" will be included in "%f", even
1043when using "%f:". This means that a file name which is a single alphabetical
1044letter will not be detected.
1045
1046The "%p" conversion is normally followed by a "^". It's used for compilers
1047that output a line like: >
1048 ^
1049or >
1050 ---------^
1051to indicate the column of the error. This is to be used in a multi-line error
1052message. See |errorformat-javac| for a useful example.
1053
Bram Moolenaar2641f772005-03-25 21:58:17 +00001054The "%s" conversion specifies the text to search for to locate the error line.
1055The text is used as a literal string. The anchors "^" and "$" are added to
1056the text to locate the error line exactly matching the search text and the
1057text is prefixed with the "\V" atom to make it "very nomagic". The "%s"
1058conversion can be used to locate lines without a line number in the error
1059output. Like the output of the "grep" shell command.
1060When the pattern is present the line number will not be used.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061
1062Changing directory
1063
1064The following uppercase conversion characters specify the type of special
1065format strings. At most one of them may be given as a prefix at the begin
1066of a single comma-separated format pattern.
1067Some compilers produce messages that consist of directory names that have to
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001068be prepended to each file name read by %f (example: GNU make). The following
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069codes can be used to scan these directory names; they will be stored in an
1070internal directory stack. *E379*
1071 %D "enter directory" format string; expects a following
1072 %f that finds the directory name
1073 %X "leave directory" format string; expects following %f
1074
1075When defining an "enter directory" or "leave directory" format, the "%D" or
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001076"%X" has to be given at the start of that substring. Vim tracks the directory
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077changes and prepends the current directory to each erroneous file found with a
1078relative path. See |quickfix-directory-stack| for details, tips and
1079limitations.
1080
1081
1082Multi-line messages *errorformat-multi-line*
1083
1084It is possible to read the output of programs that produce multi-line
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001085messages, i.e. error strings that consume more than one line. Possible
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086prefixes are:
1087 %E start of a multi-line error message
1088 %W start of a multi-line warning message
1089 %I start of a multi-line informational message
1090 %A start of a multi-line message (unspecified type)
Bram Moolenaarb3656ed2006-03-20 21:59:49 +00001091 %> for next line start with current pattern again |efm-%>|
Bram Moolenaar071d4272004-06-13 20:20:40 +00001092 %C continuation of a multi-line message
1093 %Z end of a multi-line message
1094These can be used with '+' and '-', see |efm-ignore| below.
1095
Bram Moolenaarceaf7b82006-03-19 22:18:55 +00001096Using "\n" in the pattern won't work to match multi-line messages.
1097
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098Example: Your compiler happens to write out errors in the following format
1099(leading line numbers not being part of the actual output):
1100
Bram Moolenaarceaf7b82006-03-19 22:18:55 +00001101 1 Error 275 ~
1102 2 line 42 ~
1103 3 column 3 ~
1104 4 ' ' expected after '--' ~
Bram Moolenaar071d4272004-06-13 20:20:40 +00001105
1106The appropriate error format string has to look like this: >
1107 :set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
1108
1109And the |:clist| error message generated for this error is:
1110
1111 1:42 col 3 error 275: ' ' expected after '--'
1112
1113Another example: Think of a Python interpreter that produces the following
1114error message (line numbers are not part of the actual output):
1115
1116 1 ==============================================================
1117 2 FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)
1118 3 --------------------------------------------------------------
1119 4 Traceback (most recent call last):
1120 5 File "unittests/dbfacadeTest.py", line 89, in testFoo
1121 6 self.assertEquals(34, dtid)
1122 7 File "/usr/lib/python2.2/unittest.py", line 286, in
1123 8 failUnlessEqual
1124 9 raise self.failureException, \
1125 10 AssertionError: 34 != 33
1126 11
1127 12 --------------------------------------------------------------
1128 13 Ran 27 tests in 0.063s
1129
1130Say you want |:clist| write the relevant information of this message only,
1131namely:
1132 5 unittests/dbfacadeTest.py:89: AssertionError: 34 != 33
1133
1134Then the error format string could be defined as follows: >
1135 :set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
1136
1137Note that the %C string is given before the %A here: since the expression
1138' %.%#' (which stands for the regular expression ' .*') matches every line
1139starting with a space, followed by any characters to the end of the line,
1140it also hides line 7 which would trigger a separate error message otherwise.
1141Error format strings are always parsed pattern by pattern until the first
1142match occurs.
Bram Moolenaarb3656ed2006-03-20 21:59:49 +00001143 *efm-%>*
1144The %> item can be used to avoid trying patterns that appear earlier in
1145'errorformat'. This is useful for patterns that match just about anything.
1146For example, if the error looks like this:
1147
1148 Error in line 123 of foo.c: ~
1149 unknown variable "i" ~
1150
1151This can be found with: >
1152 :set efm=xxx,%E%>Error in line %l of %f:,%Z%m
1153Where "xxx" has a pattern that would also match the second line.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001154
Bram Moolenaarceaf7b82006-03-19 22:18:55 +00001155Important: There is no memory of what part of the errorformat matched before;
1156every line in the error file gets a complete new run through the error format
1157lines. For example, if one has: >
1158 setlocal efm=aa,bb,cc,dd,ee
1159Where aa, bb, etc. are error format strings. Each line of the error file will
1160be matched to the pattern aa, then bb, then cc, etc. Just because cc matched
1161the previous error line does _not_ mean that dd will be tried first on the
1162current line, even if cc and dd are multi-line errorformat strings.
1163
1164
Bram Moolenaar071d4272004-06-13 20:20:40 +00001165
1166Separate file name *errorformat-separate-filename*
1167
1168These prefixes are useful if the file name is given once and multiple messages
1169follow that refer to this file name.
1170 %O single-line file message: overread the matched part
1171 %P single-line file message: push file %f onto the stack
1172 %Q single-line file message: pop the last file from stack
1173
1174Example: Given a compiler that produces the following error logfile (without
1175leading line numbers):
1176
1177 1 [a1.tt]
1178 2 (1,17) error: ';' missing
1179 3 (21,2) warning: variable 'z' not defined
1180 4 (67,3) error: end of file found before string ended
1181 5
1182 6 [a2.tt]
1183 7
1184 8 [a3.tt]
1185 9 NEW compiler v1.1
1186 10 (2,2) warning: variable 'x' not defined
1187 11 (67,3) warning: 's' already defined
1188
1189This logfile lists several messages for each file enclosed in [...] which are
1190properly parsed by an error format like this: >
1191 :set efm=%+P[%f],(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%-Q
1192
1193A call of |:clist| writes them accordingly with their correct filenames:
1194
1195 2 a1.tt:1 col 17 error: ';' missing
1196 3 a1.tt:21 col 2 warning: variable 'z' not defined
1197 4 a1.tt:67 col 3 error: end of file found before string ended
1198 8 a3.tt:2 col 2 warning: variable 'x' not defined
1199 9 a3.tt:67 col 3 warning: 's' already defined
1200
1201Unlike the other prefixes that all match against whole lines, %P, %Q and %O
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001202can be used to match several patterns in the same line. Thus it is possible
Bram Moolenaar071d4272004-06-13 20:20:40 +00001203to parse even nested files like in the following line:
1204 {"file1" {"file2" error1} error2 {"file3" error3 {"file4" error4 error5}}}
1205The %O then parses over strings that do not contain any push/pop file name
1206information. See |errorformat-LaTeX| for an extended example.
1207
1208
1209Ignoring and using whole messages *efm-ignore*
1210
1211The codes '+' or '-' can be combined with the uppercase codes above; in that
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001212case they have to precede the letter, e.g. '%+A' or '%-G':
Bram Moolenaar071d4272004-06-13 20:20:40 +00001213 %- do not include the matching multi-line in any output
1214 %+ include the whole matching line in the %m error string
1215
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001216One prefix is only useful in combination with '+' or '-', namely %G. It parses
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217over lines containing general information like compiler version strings or
1218other headers that can be skipped.
1219 %-G ignore this message
1220 %+G general message
1221
1222
1223Pattern matching
1224
1225The scanf()-like "%*[]" notation is supported for backward-compatibility
1226with previous versions of Vim. However, it is also possible to specify
1227(nearly) any Vim supported regular expression in format strings.
1228Since meta characters of the regular expression language can be part of
1229ordinary matching strings or file names (and therefore internally have to
1230be escaped), meta symbols have to be written with leading '%':
Bram Moolenaarceaf7b82006-03-19 22:18:55 +00001231 %\ The single '\' character. Note that this has to be
Bram Moolenaar071d4272004-06-13 20:20:40 +00001232 escaped ("%\\") in ":set errorformat=" definitions.
Bram Moolenaarceaf7b82006-03-19 22:18:55 +00001233 %. The single '.' character.
1234 %# The single '*'(!) character.
1235 %^ The single '^' character. Note that this is not
1236 useful, the pattern already matches start of line.
1237 %$ The single '$' character. Note that this is not
1238 useful, the pattern already matches end of line.
1239 %[ The single '[' character for a [] character range.
1240 %~ The single '~' character.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001241When using character classes in expressions (see |/\i| for an overview),
1242terms containing the "\+" quantifier can be written in the scanf() "%*"
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001243notation. Example: "%\\d%\\+" ("\d\+", "any number") is equivalent to "%*\\d".
Bram Moolenaar071d4272004-06-13 20:20:40 +00001244Important note: The \(...\) grouping of sub-matches can not be used in format
1245specifications because it is reserved for internal conversions.
1246
1247
1248Multiple entries in 'errorformat' *efm-entries*
1249
1250To be able to detect output from several compilers, several format patterns
1251may be put in 'errorformat', separated by commas (note: blanks after the comma
1252are ignored). The first pattern that has a complete match is used. If no
1253match is found, matching parts from the last one will be used, although the
1254file name is removed and the error message is set to the whole message. If
1255there is a pattern that may match output from several compilers (but not in a
1256right way), put it after one that is more restrictive.
1257
1258To include a comma in a pattern precede it with a backslash (you have to type
1259two in a ":set" command). To include a backslash itself give two backslashes
1260(you have to type four in a ":set" command). You also need to put a backslash
1261before a space for ":set".
1262
1263
1264Valid matches *quickfix-valid*
1265
1266If a line does not completely match one of the entries in 'errorformat', the
1267whole line is put in the error message and the entry is marked "not valid"
1268These lines are skipped with the ":cn" and ":cp" commands (unless there is
1269no valid line at all). You can use ":cl!" to display all the error messages.
1270
1271If the error format does not contain a file name Vim cannot switch to the
1272correct file. You will have to do this by hand.
1273
1274
1275Examples
1276
1277The format of the file from the Amiga Aztec compiler is:
1278
1279 filename>linenumber:columnnumber:errortype:errornumber:errormessage
1280
1281 filename name of the file in which the error was detected
1282 linenumber line number where the error was detected
1283 columnnumber column number where the error was detected
1284 errortype type of the error, normally a single 'E' or 'W'
1285 errornumber number of the error (for lookup in the manual)
1286 errormessage description of the error
1287
1288This can be matched with this 'errorformat' entry:
1289 %f>%l:%c:%t:%n:%m
1290
1291Some examples for C compilers that produce single-line error outputs:
1292%f:%l:\ %t%*[^0123456789]%n:\ %m for Manx/Aztec C error messages
1293 (scanf() doesn't understand [0-9])
1294%f\ %l\ %t%*[^0-9]%n:\ %m for SAS C
1295\"%f\"\\,%*[^0-9]%l:\ %m for generic C compilers
1296%f:%l:\ %m for GCC
1297%f:%l:\ %m,%Dgmake[%*\\d]:\ Entering\ directory\ `%f',
1298%Dgmake[%*\\d]:\ Leaving\ directory\ `%f'
1299 for GCC with gmake (concat the lines!)
1300%f(%l)\ :\ %*[^:]:\ %m old SCO C compiler (pre-OS5)
1301%f(%l)\ :\ %t%*[^0-9]%n:\ %m idem, with error type and number
1302%f:%l:\ %m,In\ file\ included\ from\ %f:%l:,\^I\^Ifrom\ %f:%l%m
1303 for GCC, with some extras
1304
1305Extended examples for the handling of multi-line messages are given below,
1306see |errorformat-Jikes| and |errorformat-LaTeX|.
1307
1308Note the backslash in front of a space and double quote. It is required for
1309the :set command. There are two backslashes in front of a comma, one for the
1310:set command and one to avoid recognizing the comma as a separator of error
1311formats.
1312
1313
1314Filtering messages
1315
1316If you have a compiler that produces error messages that do not fit in the
1317format string, you could write a program that translates the error messages
1318into this format. You can use this program with the ":make" command by
1319changing the 'makeprg' option. For example: >
1320 :set mp=make\ \\\|&\ error_filter
1321The backslashes before the pipe character are required to avoid it to be
1322recognized as a command separator. The backslash before each space is
1323required for the set command.
1324
1325=============================================================================
13268. The directory stack *quickfix-directory-stack*
1327
1328Quickfix maintains a stack for saving all used directories parsed from the
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001329make output. For GNU-make this is rather simple, as it always prints the
1330absolute path of all directories it enters and leaves. Regardless if this is
Bram Moolenaar071d4272004-06-13 20:20:40 +00001331done via a 'cd' command in the makefile or with the parameter "-C dir" (change
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001332to directory before reading the makefile). It may be useful to use the switch
Bram Moolenaar071d4272004-06-13 20:20:40 +00001333"-w" to force GNU-make to print out the working directory before and after
1334processing.
1335
1336Maintaining the correct directory is more complicated if you don't use
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001337GNU-make. AIX-make for example doesn't print any information about its
1338working directory. Then you need to enhance the makefile. In the makefile of
1339LessTif there is a command which echoes "Making {target} in {dir}". The
Bram Moolenaar6dfc28b2010-02-11 14:19:15 +01001340special problem here is that it doesn't print information on leaving the
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001341directory and that it doesn't print the absolute path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342
1343To solve the problem with relative paths and missing "leave directory"
1344messages Vim uses following algorithm:
1345
13461) Check if the given directory is a subdirectory of the current directory.
1347 If this is true, store it as the current directory.
13482) If it is not a subdir of the current directory, try if this is a
1349 subdirectory of one of the upper directories.
13503) If the directory still isn't found, it is assumed to be a subdirectory
1351 of Vim's current directory.
1352
1353Additionally it is checked for every file, if it really exists in the
1354identified directory. If not, it is searched in all other directories of the
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001355directory stack (NOT the directory subtree!). If it is still not found, it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356assumed that it is in Vim's current directory.
1357
Bram Moolenaare667c952010-07-05 22:57:59 +02001358There are limitations in this algorithm. These examples assume that make just
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359prints information about entering a directory in the form "Making all in dir".
1360
13611) Assume you have following directories and files:
1362 ./dir1
1363 ./dir1/file1.c
1364 ./file1.c
1365
1366 If make processes the directory "./dir1" before the current directory and
1367 there is an error in the file "./file1.c", you will end up with the file
1368 "./dir1/file.c" loaded by Vim.
1369
1370 This can only be solved with a "leave directory" message.
1371
13722) Assume you have following directories and files:
1373 ./dir1
1374 ./dir1/dir2
1375 ./dir2
1376
1377 You get the following:
1378
1379 Make output Directory interpreted by Vim
1380 ------------------------ ----------------------------
1381 Making all in dir1 ./dir1
1382 Making all in dir2 ./dir1/dir2
1383 Making all in dir2 ./dir1/dir2
1384
1385 This can be solved by printing absolute directories in the "enter directory"
1386 message or by printing "leave directory" messages..
1387
Bram Moolenaar06b5d512010-05-22 15:37:44 +02001388To avoid this problem, ensure to print absolute directory names and "leave
Bram Moolenaar071d4272004-06-13 20:20:40 +00001389directory" messages.
1390
1391Examples for Makefiles:
1392
1393Unix:
1394 libs:
1395 for dn in $(LIBDIRS); do \
1396 (cd $$dn; echo "Entering dir '$$(pwd)'"; make); \
1397 echo "Leaving dir"; \
1398 done
1399
1400Add
1401 %DEntering\ dir\ '%f',%XLeaving\ dir
1402to your 'errorformat' to handle the above output.
1403
1404Note that Vim doesn't check if the directory name in a "leave directory"
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001405messages is the current directory. This is why you could just use the message
Bram Moolenaar071d4272004-06-13 20:20:40 +00001406"Leaving dir".
1407
1408=============================================================================
14099. Specific error file formats *errorformats*
1410
1411 *errorformat-Jikes*
1412Jikes(TM), a source-to-bytecode Java compiler published by IBM Research,
1413produces simple multi-line error messages.
1414
1415An 'errorformat' string matching the produced messages is shown below.
1416The following lines can be placed in the user's |vimrc| to overwrite Vim's
1417recognized default formats, or see |:set+=| how to install this format
1418additionally to the default. >
1419
1420 :set efm=%A%f:%l:%c:%*\\d:%*\\d:,
1421 \%C%*\\s%trror:%m,
1422 \%+C%*[^:]%trror:%m,
1423 \%C%*\\s%tarning:%m,
1424 \%C%m
1425<
1426Jikes(TM) produces a single-line error message when invoked with the option
1427"+E", and can be matched with the following: >
1428
Bram Moolenaar6b803a72007-05-06 14:25:46 +00001429 :setl efm=%f:%l:%v:%*\\d:%*\\d:%*\\s%m
Bram Moolenaar071d4272004-06-13 20:20:40 +00001430<
1431 *errorformat-javac*
1432This 'errorformat' has been reported to work well for javac, which outputs a
1433line with "^" to indicate the column of the error: >
Bram Moolenaar6b803a72007-05-06 14:25:46 +00001434 :setl efm=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435or: >
Bram Moolenaar6b803a72007-05-06 14:25:46 +00001436 :setl efm=%A%f:%l:\ %m,%+Z%p^,%+C%.%#,%-G%.%#
Bram Moolenaar071d4272004-06-13 20:20:40 +00001437<
Bram Moolenaar6b803a72007-05-06 14:25:46 +00001438Here is an alternative from Michael F. Lamb for Unix that filters the errors
1439first: >
1440 :setl errorformat=%Z%f:%l:\ %m,%A%p^,%-G%*[^sl]%.%#
Bram Moolenaar26df0922014-02-23 23:39:13 +01001441 :setl makeprg=javac\ %:S\ 2>&1\ \\\|\ vim-javac-filter
Bram Moolenaar6b803a72007-05-06 14:25:46 +00001442
1443You need to put the following in "vim-javac-filter" somewhere in your path
1444(e.g., in ~/bin) and make it executable: >
1445 #!/bin/sed -f
1446 /\^$/s/\t/\ /g;/:[0-9]\+:/{h;d};/^[ \t]*\^/G;
1447
1448In English, that sed script:
1449- Changes single tabs to single spaces and
1450- Moves the line with the filename, line number, error message to just after
1451 the pointer line. That way, the unused error text between doesn't break
1452 vim's notion of a "multi-line message" and also doesn't force us to include
1453 it as a "continuation of a multi-line message."
1454
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455 *errorformat-ant*
1456For ant (http://jakarta.apache.org/) the above errorformat has to be modified
1457to honour the leading [javac] in front of each javac output line: >
1458 :set efm=%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
1459
1460The 'errorformat' can also be configured to handle ant together with either
1461javac or jikes. If you're using jikes, you should tell ant to use jikes' +E
1462command line switch which forces jikes to generate one-line error messages.
1463This is what the second line (of a build.xml file) below does: >
1464 <property name = "build.compiler" value = "jikes"/>
1465 <property name = "build.compiler.emacs" value = "true"/>
1466
1467The 'errorformat' which handles ant with both javac and jikes is: >
1468 :set efm=\ %#[javac]\ %#%f:%l:%c:%*\\d:%*\\d:\ %t%[%^:]%#:%m,
1469 \%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
1470<
1471 *errorformat-jade*
1472parsing jade (see http://www.jclark.com/) errors is simple: >
1473 :set efm=jade:%f:%l:%c:%t:%m
1474<
1475 *errorformat-LaTeX*
1476The following is an example how an 'errorformat' string can be specified
1477for the (La)TeX typesetting system which displays error messages over
1478multiple lines. The output of ":clist" and ":cc" etc. commands displays
1479multi-lines in a single line, leading white space is removed.
1480It should be easy to adopt the above LaTeX errorformat to any compiler output
1481consisting of multi-line errors.
1482
1483The commands can be placed in a |vimrc| file or some other Vim script file,
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001484e.g. a script containing LaTeX related stuff which is loaded only when editing
Bram Moolenaar071d4272004-06-13 20:20:40 +00001485LaTeX sources.
1486Make sure to copy all lines of the example (in the given order), afterwards
1487remove the comment lines. For the '\' notation at the start of some lines see
1488|line-continuation|.
1489
1490 First prepare 'makeprg' such that LaTeX will report multiple
1491 errors; do not stop when the first error has occurred: >
1492 :set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}
1493<
1494 Start of multi-line error messages: >
1495 :set efm=%E!\ LaTeX\ %trror:\ %m,
1496 \%E!\ %m,
1497< Start of multi-line warning messages; the first two also
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001498 include the line number. Meaning of some regular expressions:
Bram Moolenaar071d4272004-06-13 20:20:40 +00001499 - "%.%#" (".*") matches a (possibly empty) string
1500 - "%*\\d" ("\d\+") matches a number >
1501 \%+WLaTeX\ %.%#Warning:\ %.%#line\ %l%.%#,
1502 \%+W%.%#\ at\ lines\ %l--%*\\d,
1503 \%WLaTeX\ %.%#Warning:\ %m,
1504< Possible continuations of error/warning messages; the first
1505 one also includes the line number: >
1506 \%Cl.%l\ %m,
1507 \%+C\ \ %m.,
1508 \%+C%.%#-%.%#,
1509 \%+C%.%#[]%.%#,
1510 \%+C[]%.%#,
1511 \%+C%.%#%[{}\\]%.%#,
1512 \%+C<%.%#>%.%#,
1513 \%C\ \ %m,
1514< Lines that match the following patterns do not contain any
1515 important information; do not include them in messages: >
1516 \%-GSee\ the\ LaTeX%m,
1517 \%-GType\ \ H\ <return>%m,
1518 \%-G\ ...%.%#,
1519 \%-G%.%#\ (C)\ %.%#,
1520 \%-G(see\ the\ transcript%.%#),
1521< Generally exclude any empty or whitespace-only line from
1522 being displayed: >
1523 \%-G\\s%#,
1524< The LaTeX output log does not specify the names of erroneous
1525 source files per line; rather they are given globally,
1526 enclosed in parentheses.
1527 The following patterns try to match these names and store
1528 them in an internal stack. The patterns possibly scan over
1529 the same input line (one after another), the trailing "%r"
1530 conversion indicates the "rest" of the line that will be
1531 parsed in the next go until the end of line is reached.
1532
1533 Overread a file name enclosed in '('...')'; do not push it
1534 on a stack since the file apparently does not contain any
1535 error: >
1536 \%+O(%f)%r,
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001537< Push a file name onto the stack. The name is given after '(': >
Bram Moolenaar071d4272004-06-13 20:20:40 +00001538 \%+P(%f%r,
1539 \%+P\ %\\=(%f%r,
1540 \%+P%*[^()](%f%r,
1541 \%+P[%\\d%[^()]%#(%f%r,
1542< Pop the last stored file name when a ')' is scanned: >
1543 \%+Q)%r,
1544 \%+Q%*[^()])%r,
1545 \%+Q[%\\d%*[^()])%r
1546
1547Note that in some cases file names in the LaTeX output log cannot be parsed
1548properly. The parser might have been messed up by unbalanced parentheses
1549then. The above example tries to catch the most relevant cases only.
1550You can customize the given setting to suit your own purposes, for example,
1551all the annoying "Overfull ..." warnings could be excluded from being
1552recognized as an error.
1553Alternatively to filtering the LaTeX compiler output, it is also possible
1554to directly read the *.log file that is produced by the [La]TeX compiler.
1555This contains even more useful information about possible error causes.
1556However, to properly parse such a complex file, an external filter should
1557be used. See the description further above how to make such a filter known
1558by Vim.
1559
1560 *errorformat-Perl*
1561In $VIMRUNTIME/tools you can find the efm_perl.pl script, which filters Perl
1562error messages into a format that quickfix mode will understand. See the
Bram Moolenaar8c8de832008-06-24 22:58:06 +00001563start of the file about how to use it. (This script is deprecated, see
1564|compiler-perl|.)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001565
1566
1567
1568 vim:tw=78:ts=8:ft=help:norl: