blob: bdda74fc65aef820f9af6becb47fd421d03e6d43 [file] [log] [blame]
Bram Moolenaar280f1262006-01-30 00:14:18 +00001*quickfix.txt* For Vim version 7.0aa. Last change: 2006 Jan 29
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 Moolenaar071d4272004-06-13 20:20:40 +000038If you are using Manx's Aztec C compiler on the Amiga look here for how to use
39it with Vim: |quickfix-manx|. If you are using another compiler you should
40save the error messages in a file and start Vim with "vim -q filename". An
41easy way to do this is with the |:make| command (see below). The
42'errorformat' option should be set to match the error messages from your
43compiler (see |errorformat| below).
44
Bram Moolenaard12f5c12006-01-25 22:10:52 +000045 *location-list* *E776*
Bram Moolenaar280f1262006-01-30 00:14:18 +000046A location list is similar to a quickfix list and contains a list of positions
47in files. A location list is associated with a window and each window can
48have a separate location list. A location list can be associated with only
49one window. The location list is independent of the quickfix list.
Bram Moolenaard12f5c12006-01-25 22:10:52 +000050
Bram Moolenaar280f1262006-01-30 00:14:18 +000051When a window with a location list is split, the new window gets a copy of the
52location list. When there are no references to a location list, the location
53list is destroyed.
54
55The following quickfix commands can be used. The location list commands are
56similar to the quickfix commands, replacing the 'c' prefix in the quickfix
57command with 'l'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000058
59 *:cc*
60:cc[!] [nr] Display error [nr]. If [nr] is omitted, the same
61 error is displayed again. Without [!] this doesn't
62 work when jumping to another buffer, the current buffer
63 has been changed, there is the only window for the
64 buffer and both 'hidden' and 'autowrite' are off.
65 When jumping to another buffer with [!] any changes to
66 the current buffer are lost, unless 'hidden' is set or
67 there is another window for this buffer.
68 The 'switchbuf' settings are respected when jumping
69 to a buffer.
70
Bram Moolenaard12f5c12006-01-25 22:10:52 +000071 *:ll*
72:ll[!] [nr] Same as ":cc", except the location list for the
73 current window is used instead of the quickfix list.
74
Bram Moolenaar071d4272004-06-13 20:20:40 +000075 *:cn* *:cnext* *E553*
76:[count]cn[ext][!] Display the [count] next error in the list that
77 includes a file name. If there are no file names at
78 all, go to the [count] next error. See |:cc| for
79 [!] and 'switchbuf'.
80
Bram Moolenaar17c7c012006-01-26 22:25:15 +000081 *:lne* *:lnext*
82:[count]lne[xt][!] Same as ":cnext", except the location list for the
Bram Moolenaard12f5c12006-01-25 22:10:52 +000083 current window is used instead of the quickfix list.
84
Bram Moolenaar071d4272004-06-13 20:20:40 +000085:[count]cN[ext][!] *:cp* *:cprevious* *:cN* *:cNext*
86:[count]cp[revious][!] Display the [count] previous error in the list that
87 includes a file name. If there are no file names at
88 all, go to the [count] previous error. See |:cc| for
89 [!] and 'switchbuf'.
90
Bram Moolenaar17c7c012006-01-26 22:25:15 +000091
92:[count]lN[ext][!] *:lp* *:lprevious* *:lN* *:lNext*
Bram Moolenaard12f5c12006-01-25 22:10:52 +000093:[count]lp[revious][!] Same as ":cNext" and ":cprevious", except the location
94 list for the current window is used instead of the
95 quickfix list.
96
Bram Moolenaar071d4272004-06-13 20:20:40 +000097 *:cnf* *:cnfile*
98:[count]cnf[ile][!] Display the first error in the [count] next file in
99 the list that includes a file name. If there are no
100 file names at all or if there is no next file, go to
101 the [count] next error. See |:cc| for [!] and
102 'switchbuf'.
103
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000104 *:lnf* *:lnfile*
105:[count]lnf[ile][!] Same as ":cnfile", except the location list for the
106 current window is used instead of the quickfix list.
107
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108:[count]cNf[ile][!] *:cpf* *:cpfile* *:cNf* *:cNfile*
109:[count]cpf[ile][!] Display the last error in the [count] previous file in
110 the list that includes a file name. If there are no
111 file names at all or if there is no next file, go to
112 the [count] previous error. See |:cc| for [!] and
113 'switchbuf'.
114
Bram Moolenaar17c7c012006-01-26 22:25:15 +0000115
116:[count]lNf[ile][!] *:lpf* *:lpfile* *:lNf* *:lNfile*
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000117:[count]lpf[ile][!] Same as ":cNfile" and ":cpfile", except the location
118 list for the current window is used instead of the
119 quickfix list.
120
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121 *:crewind* *:cr*
122:cr[ewind][!] [nr] Display error [nr]. If [nr] is omitted, the FIRST
123 error is displayed. See |:cc|.
124
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000125 *:lrewind* *:lr*
126:lr[ewind][!] [nr] Same as ":crewind", except the location list for the
127 current window is used instead of the quickfix list.
128
Bram Moolenaar071d4272004-06-13 20:20:40 +0000129 *:cfirst* *:cfir*
130:cfir[st][!] [nr] Same as ":crewind".
131
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000132 *:lfirst* *:lfir*
133:lfir[st][!] [nr] Same as ":lrewind".
134
Bram Moolenaar071d4272004-06-13 20:20:40 +0000135 *:clast* *:cla*
136:cla[st][!] [nr] Display error [nr]. If [nr] is omitted, the LAST
137 error is displayed. See |:cc|.
138
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000139 *:llast* *:lla*
140:lla[st][!] [nr] Same as ":clast", except the location list for the
141 current window is used instead of the quickfix list.
142
Bram Moolenaar071d4272004-06-13 20:20:40 +0000143 *:cq* *:cquit*
144:cq[uit] Quit Vim with an error code, so that the compiler
145 will not compile the same file again.
146
147 *:cf* *:cfile*
148:cf[ile][!] [errorfile] Read the error file and jump to the first error.
149 This is done automatically when Vim is started with
150 the -q option. You can use this command when you
151 keep Vim running while compiling. If you give the
152 name of the errorfile, the 'errorfile' option will
153 be set to [errorfile]. See |:cc| for [!].
154
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000155 *:lf* *:lfile*
156:lf[ile][!] [errorfile] Same as ":cfile", except the location list for the
157 current window is used instead of the quickfix list.
158 You can not use the -q command-line option to set
159 the location list.
160
Bram Moolenaar17c7c012006-01-26 22:25:15 +0000161
162:cg[etfile][!] [errorfile] *:cg* *:cgetfile*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000163 Read the error file. Just like ":cfile" but don't
164 jump to the first error.
165
Bram Moolenaar17c7c012006-01-26 22:25:15 +0000166
167:lg[etfile][!] [errorfile] *:lg* *:lgetfile*
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000168 Same as ":cgetfile", except the location list for the
169 current window is used instead of the quickfix list.
170
Bram Moolenaar4770d092006-01-12 23:22:24 +0000171 *:caddf* *:caddfile*
172:caddf[ile] [errorfile] Read the error file and add the errors from the
Bram Moolenaar87e25fd2005-07-27 21:13:01 +0000173 errorfile to the current quickfix list. If a quickfix
174 list is not present, then a new list is created.
175
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000176 *:laddf* *:laddfile*
177:laddf[ile] [errorfile] Same as ":caddfile", except the location list for the
178 current window is used instead of the quickfix list.
179
Bram Moolenaar86b68352004-12-27 21:59:20 +0000180 *:cb* *:cbuffer* *E681*
181:cb[uffer] [bufnr] Read the error list from the current buffer.
182 When [bufnr] is given it must be the number of a
183 loaded buffer. That buffer will then be used instead
184 of the current buffer.
185 A range can be specified for the lines to be used.
186 Otherwise all lines in the buffer are used.
187
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000188 *:lb* *:lbuffer*
189:lb[uffer] [bufnr] Same as ":cbuffer", except the location list for the
190 current window is used instead of the quickfix list.
191
Bram Moolenaara40ceaf2006-01-13 22:35:40 +0000192 *:cex* *:cexpr* *E777*
Bram Moolenaar4770d092006-01-12 23:22:24 +0000193:cex[pr][!] {expr} Create a quickfix list using the result of {expr} and
194 jump to the first error. If {expr} is a String, then
195 each new-line terminated line in the String is
196 processed using 'errorformat' and the result is added
197 to the quickfix list. If {expr} is a List, then each
198 String item in the list is processed and added to the
199 quickfix list. Non String items in the List are
200 ignored. See |:cc|
Bram Moolenaar87e25fd2005-07-27 21:13:01 +0000201 for [!].
202 Examples: >
203 :cexpr system('grep -n xyz *')
204 :cexpr getline(1, '$')
205<
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000206 *: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
Bram Moolenaar4770d092006-01-12 23:22:24 +0000210 *:cad* *:caddexpr*
211:cad[dexpr][!] {expr} Evaluate {expr} and add the resulting lines to the
212 current quickfix list. If a quickfix list is not
213 present, then a new list is created. The current
214 cursor position will not be changed. See |:cexpr| for
215 more information.
216 Example: >
217 :g/mypattern/caddexpr expand("%") . ":" . line(".") . ":" . getline(".")
218<
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000219 *:lad* *:laddexpr*
220:lad[dexpr][!] {expr} Same as ":caddexpr", except the location list for the
221 current window is used instead of the quickfix list.
222
Bram Moolenaar071d4272004-06-13 20:20:40 +0000223 *:cl* *:clist*
224:cl[ist] [from] [, [to]]
225 List all errors that are valid |quickfix-valid|.
226 If numbers [from] and/or [to] are given, the respective
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000227 range of errors is listed. A negative number counts
Bram Moolenaar071d4272004-06-13 20:20:40 +0000228 from the last error backwards, -1 being the last error.
229 The 'switchbuf' settings are respected when jumping
230 to a buffer.
231
232:cl[ist]! [from] [, [to]]
233 List all errors.
234
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000235 *:lli* *:llist*
236:lli[st] [from] [, [to]]
237 Same as ":clist", except the location list for the
238 current window is used instead of the quickfix list.
239
240:lli[st]! [from] [, [to]]
241 List all the entries in the location list for the
242 current window.
243
Bram Moolenaar071d4272004-06-13 20:20:40 +0000244If you insert or delete lines, mostly the correct error location is still
245found because hidden marks are used. Sometimes, when the mark has been
246deleted for some reason, the message "line changed" is shown to warn you that
247the error location may not be correct. If you quit Vim and start again the
248marks are lost and the error locations may not be correct anymore.
249
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000250If vim is built with |+autocmd| support, two autocommands are available for
251running commands before and after a quickfix command (':make', ':grep' and so
252on) is executed. See |QuickFixCmdPre| and |QuickFixCmdPost| for details.
253
Bram Moolenaar071d4272004-06-13 20:20:40 +0000254=============================================================================
2552. The error window *quickfix-window*
256
257 *:cope* *:copen*
258:cope[n] [height] Open a window to show the current list of errors.
259 When [height] is given, the window becomes that high
260 (if there is room). Otherwise the window is made ten
261 lines high.
262 The window will contain a special buffer, with
263 'buftype' equal to "quickfix". Don't change this!
264 If there already is a quickfix window, it will be made
265 the current window. It is not possible to open a
266 second quickfix window.
267
Bram Moolenaar17c7c012006-01-26 22:25:15 +0000268 *:lop* *:lopen*
269:lop[en] [height] Open a window to show the location list for the
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000270 current window. Works only when the location list for
Bram Moolenaar17c7c012006-01-26 22:25:15 +0000271 the current window is present. You can have more than
272 one location window opened at a time. Otherwise, it
Bram Moolenaar280f1262006-01-30 00:14:18 +0000273 acts the same as ":copen".
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000274
Bram Moolenaar071d4272004-06-13 20:20:40 +0000275 *:ccl* *:cclose*
276:ccl[ose] Close the quickfix window.
277
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000278 *:lcl* *:lclose*
279:lcl[ose] Close the window showing the location list for the
280 current window.
281
Bram Moolenaar071d4272004-06-13 20:20:40 +0000282 *:cw* *:cwindow*
283:cw[indow] [height] Open the quickfix window when there are recognized
284 errors. If the window is already open and there are
285 no recognized errors, close the window.
286
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000287 *:lw* *:lwindow*
288:lw[indow] [height] Same as ":cwindow", except use the window showing the
289 location list for the current window.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290
291Normally the quickfix window is at the bottom of the screen. If there are
292vertical splits, it's at the bottom of the rightmost column of windows. To
293make it always occupy the full width: >
294 :botright cwindow
295You can move the window around with |window-moving| commands.
296For example, to move it to the top: CTRL-W K
297The 'winfixheight' option will be set, which means that the window will mostly
298keep its height, ignoring 'winheight' and 'equalalways'. You can change the
299height manually (e.g., by dragging the status line above it with the mouse).
300
301In the quickfix window, each line is one error. The line number is equal to
302the error number. You can use ":.cc" to jump to the error under the cursor.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000303Hitting the <Enter> key or double-clicking the mouse on a line has the same
Bram Moolenaar071d4272004-06-13 20:20:40 +0000304effect. The file containing the error is opened in the window above the
305quickfix window. If there already is a window for that file, it is used
306instead. If the buffer in the used window has changed, and the error is in
307another file, jumping to the error will fail. You will first have to make
308sure the window contains a buffer which can be abandoned.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000309 *CTRL-W_<Enter>* *CTRL-W_<CR>*
310You can use CTRL-W <Enter> to open a new window and jump to the error there.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311
312When the quickfix window has been filled, two autocommand events are
313triggered. First the 'filetype' option is set to "qf", which triggers the
314FileType event. Then the BufReadPost event is triggered. This can be used to
315perform some action on the listed errors. Example: >
Bram Moolenaar280f1262006-01-30 00:14:18 +0000316 au BufReadPost quickfix setlocal modifiable
317 \ | silent exe 'g/^/s//\=line(".")." "/'
318 \ | setlocal nomodifiable
Bram Moolenaar071d4272004-06-13 20:20:40 +0000319This prepends the line number to each line. Note the use of "\=" in the
320substitute string of the ":s" command, which is used to evaluate an
321expression.
322
323Note: Making changes in the quickfix window has no effect on the list of
324errors. 'modifiable' is off to avoid making changes. If you delete or insert
325lines anyway, the relation between the text and the error number is messed up.
326If you really want to do this, you could write the contents of the quickfix
327window to a file and use ":cfile" to have it parsed and used as the new error
328list.
329
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000330 *location-list-window*
Bram Moolenaar280f1262006-01-30 00:14:18 +0000331The location list window displays the entries in a location list. When you
332open a location list window, it is created below the current window and
333displays the location list for the current window. The location list window
334is similar to the quickfix window, except that you can have more than one
335location list window open at a time.
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000336
Bram Moolenaar280f1262006-01-30 00:14:18 +0000337When you select a file from the location list window, the following steps are
338used to find a window to edit the file:
339
3401. If a window with the location list displayed in the location list window is
341 present, then the file is opened in that window.
3422. If the above step fails and if the file is already opened in another
343 window, then that window is used.
3443. If the above step fails then an existing window showing a buffer with
345 'buftype' not set is used.
3464. If the above step fails, then the file is edited in a new window.
347
348In all of the above cases, if the location list for the selected window is not
349yet set, then it is set to the location list displayed in the location list
350window.
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000351
Bram Moolenaar071d4272004-06-13 20:20:40 +0000352=============================================================================
3533. Using more than one list of errors *quickfix-error-lists*
354
355So far has been assumed that there is only one list of errors. Actually the
356ten last used lists are remembered. When starting a new list, the previous
357ones are automatically kept. Two commands can be used to access older error
358lists. They set one of the existing error lists as the current one.
359
360 *:colder* *:col* *E380*
361:col[der] [count] Go to older error list. When [count] is given, do
362 this [count] times. When already at the oldest error
363 list, an error message is given.
364
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000365 *:lolder* *:lol*
366:lol[der] [count] Same as ":colder", except use the location list for
367 the current window instead of the quickfix list.
368
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369 *:cnewer* *:cnew* *E381*
370:cnew[er] [count] Go to newer error list. When [count] is given, do
371 this [count] times. When already at the newest error
372 list, an error message is given.
373
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000374 *:lnewer* *:lnew*
375:lnew[er] [count] Same as ":cnewer", except use the location list for
376 the current window instead of the quickfix list.
377
Bram Moolenaar071d4272004-06-13 20:20:40 +0000378When adding a new error list, it becomes the current list.
379
380When ":colder" has been used and ":make" or ":grep" is used to add a new error
381list, one newer list is overwritten. This is especially useful if you are
382browsing with ":grep" |grep|. If you want to keep the more recent error
383lists, use ":cnewer 99" first.
384
385=============================================================================
3864. Using :make *:make_makeprg*
387
388 *:mak* *:make*
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000389:mak[e][!] [arguments] 1. If vim was built with |+autocmd|, all relevant
390 |QuickFixCmdPre| autocommands are executed.
391 2. If the 'autowrite' option is on, write any changed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000392 buffers
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000393 3. An errorfile name is made from 'makeef'. If
Bram Moolenaar071d4272004-06-13 20:20:40 +0000394 'makeef' doesn't contain "##", and a file with this
395 name already exists, it is deleted.
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000396 4. The program given with the 'makeprg' option is
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397 started (default "make") with the optional
398 [arguments] and the output is saved in the
399 errorfile (for Unix it is also echoed on the
400 screen).
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000401 5. The errorfile is read using 'errorformat'.
402 6. If [!] is not given the first error is jumped to.
403 7. The errorfile is deleted.
404 8. If vim was built with |+autocmd|, all relevant
405 |QuickFixCmdPost| autocommands are executed.
406 9. You can now move through the errors with commands
Bram Moolenaar071d4272004-06-13 20:20:40 +0000407 like |:cnext| and |:cprevious|, see above.
408 This command does not accept a comment, any "
409 characters are considered part of the arguments.
410
411The ":make" command executes the command given with the 'makeprg' option.
412This is done by passing the command to the shell given with the 'shell'
413option. This works almost like typing
414
415 ":!{makeprg} [arguments] {shellpipe} {errorfile}".
416
417{makeprg} is the string given with the 'makeprg' option. Any command can be
418used, not just "make". Characters '%' and '#' are expanded as usual on a
419command-line. You can use "%<" to insert the current file name without
420extension, or "#<" to insert the alternate file name without extension, for
421example: >
422 :set makeprg=make\ #<.o
423
424[arguments] is anything that is typed after ":make".
425{shellpipe} is the 'shellpipe' option.
426{errorfile} is the 'makeef' option, with ## replaced to make it unique.
427
428The placeholder "$*" can be used for the argument list in {makeprog} if the
429command needs some additional characters after its arguments. The $* is
430replaced then by all arguments. Example: >
431 :set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}
432or simpler >
433 :let &mp = 'latex \\nonstopmode \\input\{$*}'
434"$*" can be given multiple times, for example: >
435 :set makeprg=gcc\ -o\ $*\ $*
436
437The 'shellpipe' option defaults to ">" for the Amiga, MS-DOS and Win32. This
438means that the output of the compiler is saved in a file and not shown on the
439screen directly. For Unix "| tee" is used. The compiler output is shown on
440the screen and saved in a file the same time. Depending on the shell used
441"|& tee" or "2>&1| tee" is the default, so stderr output will be included.
442
443If 'shellpipe' is empty, the {errorfile} part will be omitted. This is useful
444for compilers that write to an errorfile themselves (e.g., Manx's Amiga C).
445
446==============================================================================
Bram Moolenaar86b68352004-12-27 21:59:20 +00004475. Using :vimgrep and :grep *grep* *lid*
448
449Vim has two ways to find matches for a pattern: Internal and external. The
450advantage of the internal grep is that it works on all systems and uses the
451powerful Vim search patterns. An external grep program can be used when the
452Vim grep does not do what you want.
453
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000454The internal method will be slower, because files are read into memory. The
455advantages are:
456- Line separators and encoding are automatically recognized, as if a file is
457 being edited.
458- Uses Vim search patterns. Multi-line patterns can be used.
459- When plugins are enabled: compressed and remote files can be searched.
460 |gzip| |netrw|
Bram Moolenaardcaf10e2005-01-21 11:55:25 +0000461- When 'hidden' is set the files are kept loaded, thus repeating a search is
462 much faster. Uses a lot of memory though!
Bram Moolenaar86b68352004-12-27 21:59:20 +0000463
464
4655.1 using Vim's internal grep
466
Bram Moolenaare49b69a2005-01-08 16:11:57 +0000467 *:vim* *:vimgrep* *E682* *E683*
Bram Moolenaar05159a02005-02-26 23:04:13 +0000468:vim[grep][!] /{pattern}/[g][j] {file} ...
Bram Moolenaar86b68352004-12-27 21:59:20 +0000469 Search for {pattern} in the files {file} ... and set
470 the error list to the matches.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000471 Without the 'g' flag each line is added only once.
472 With 'g' every match is added.
473
474 {pattern} is a Vim search pattern. Instead of
475 enclosing it in / any non-ID character (see
476 |'isident'|) can be used, so long as it does not
477 appear in {pattern}.
478 'ignorecase' applies. To overrule it put |/\c| in the
479 pattern to ignore case or |/\C| to match case.
480 'smartcase' is not used.
481
482 Without the 'j' flag Vim jumps to the first match.
483 With 'j' only the quickfix list is updated.
484 With the [!] any changes in the current buffer are
485 abandoned.
486
Bram Moolenaardcaf10e2005-01-21 11:55:25 +0000487 Every second or so the searched file name is displayed
488 to give you an idea of the progress made.
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000489 Examples: >
490 :vimgrep /an error/ *.c
491 :vimgrep /\<FileName\>/ *.h include/*
Bram Moolenaar231334e2005-07-25 20:46:57 +0000492 :vimgrep /myfunc/ **/*.c
493< For the use of "**" see |starstar-wildcard|.
Bram Moolenaar86b68352004-12-27 21:59:20 +0000494
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000495:vim[grep][!] {pattern} {file} ...
496 Like above, but instead of enclosing the pattern in a
497 non-ID character use a white-separated pattern. The
498 pattern must start with an ID character.
499 Example: >
500 :vimgrep Error *.c
501<
Bram Moolenaar86b68352004-12-27 21:59:20 +0000502 *:vimgrepa* *:vimgrepadd*
Bram Moolenaar05159a02005-02-26 23:04:13 +0000503:vimgrepa[dd][!] /{pattern}/[g][j] {file} ...
504:vimgrepa[dd][!] {pattern} {file} ...
Bram Moolenaar86b68352004-12-27 21:59:20 +0000505 Just like ":vimgrep", but instead of making a new list
506 of errors the matches are appended to the current
507 list.
508
509
5105.2 External grep
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511
512Vim can interface with "grep" and grep-like programs (such as the GNU
513id-utils) in a similar way to its compiler integration (see |:make| above).
514
515[Unix trivia: The name for the Unix "grep" command comes from ":g/re/p", where
516"re" stands for Regular Expression.]
517
518 *:gr* *:grep*
519:gr[ep][!] [arguments] Just like ":make", but use 'grepprg' instead of
520 'makeprg' and 'grepformat' instead of 'errorformat'.
Bram Moolenaar86b68352004-12-27 21:59:20 +0000521 When 'grepprg' is "internal" this works like
522 |:vimgrep|. Note that the pattern needs to be
523 enclosed in separator characters then.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524 *:grepa* *:grepadd*
525:grepa[dd][!] [arguments]
526 Just like ":grep", but instead of making a new list of
527 errors the matches are appended to the current list.
528 Example: >
529 :grep nothing %
530 :bufdo grepadd! something %
531< The first command makes a new error list which is
532 empty. The second command executes "grepadd" for each
533 listed buffer. Note the use of ! to avoid that
534 ":grepadd" jumps to the first error, which is not
535 allowed with |:bufdo|.
536
Bram Moolenaar86b68352004-12-27 21:59:20 +00005375.3 Setting up external grep
Bram Moolenaar071d4272004-06-13 20:20:40 +0000538
539If you have a standard "grep" program installed, the :grep command may work
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000540well with the defaults. The syntax is very similar to the standard command: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000541
542 :grep foo *.c
543
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000544Will search all files with the .c extension for the substring "foo". The
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545arguments to :grep are passed straight to the "grep" program, so you can use
546whatever options your "grep" supports.
547
548By default, :grep invokes grep with the -n option (show file and line
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000549numbers). You can change this with the 'grepprg' option. You will need to set
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550'grepprg' if:
551
552a) You are using a program that isn't called "grep"
553b) You have to call grep with a full path
554c) You want to pass other options automatically (e.g. case insensitive
555 search.)
556
557Once "grep" has executed, Vim parses the results using the 'grepformat'
558option. This option works in the same way as the 'errorformat' option - see
559that for details. You may need to change 'grepformat' from the default if
560your grep outputs in a non-standard format, or you are using some other
561program with a special format.
562
563Once the results are parsed, Vim loads the first file containing a match and
564jumps to the appropriate line, in the same way that it jumps to a compiler
565error in |quickfix| mode. You can then use the |:cnext|, |:clist|, etc.
566commands to see the other matches.
567
568
Bram Moolenaar86b68352004-12-27 21:59:20 +00005695.4 Using :grep with id-utils
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570
571You can set up :grep to work with the GNU id-utils like this: >
572
573 :set grepprg=lid\ -Rgrep\ -s
574 :set grepformat=%f:%l:%m
575
576then >
577 :grep (regexp)
578
579works just as you'd expect.
580(provided you remembered to mkid first :)
581
582
Bram Moolenaar86b68352004-12-27 21:59:20 +00005835.5 Browsing source code with :vimgrep or :grep
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584
585Using the stack of error lists that Vim keeps, you can browse your files to
586look for functions and the functions they call. For example, suppose that you
587have to add an argument to the read_file() function. You enter this command: >
588
Bram Moolenaar86b68352004-12-27 21:59:20 +0000589 :vimgrep /\<read_file\>/ *.c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590
591You use ":cn" to go along the list of matches and add the argument. At one
592place you have to get the new argument from a higher level function msg(), and
593need to change that one too. Thus you use: >
594
Bram Moolenaar86b68352004-12-27 21:59:20 +0000595 :vimgrep /\<msg\>/ *.c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596
597While changing the msg() functions, you find another function that needs to
Bram Moolenaar86b68352004-12-27 21:59:20 +0000598get the argument from a higher level. You can again use ":vimgrep" to find
599these functions. Once you are finished with one function, you can use >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600
601 :colder
602
603to go back to the previous one.
604
Bram Moolenaar86b68352004-12-27 21:59:20 +0000605This works like browsing a tree: ":vimgrep" goes one level deeper, creating a
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606list of branches. ":colder" goes back to the previous level. You can mix
Bram Moolenaar86b68352004-12-27 21:59:20 +0000607this use of ":vimgrep" and "colder" to browse all the locations in a tree-like
Bram Moolenaar071d4272004-06-13 20:20:40 +0000608way. If you do this consistently, you will find all locations without the
609need to write down a "todo" list.
610
611=============================================================================
6126. Selecting a compiler *compiler-select*
613
614 *:comp* *:compiler* *E666*
615:comp[iler][!] {name} Set options to work with compiler {name}.
616 Without the "!" options are set for the
617 current buffer. With "!" global options are
618 set.
619 If you use ":compiler foo" in "file.foo" and
620 then ":compiler! bar" in another buffer, Vim
621 will keep on using "foo" in "file.foo".
622 {not available when compiled without the
623 |+eval| feature}
624
625
626The Vim plugins in the "compiler" directory will set options to use the
627selected compiler. For ":compiler" local options are set, for ":compiler!"
628global options.
629 *current_compiler*
630To support older Vim versions, the plugins always use "current_compiler" and
631not "b:current_compiler". What the command actually does is the following:
632
633- Delete the "current_compiler" and "b:current_compiler" variables.
634- Define the "CompilerSet" user command. With "!" it does ":set", without "!"
635 it does ":setlocal".
636- Execute ":runtime! compiler/{name}.vim". The plugins are expected to set
637 options with "CompilerSet" and set the "current_compiler" variable to the
638 name of the compiler.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000639- Delete the "CompilerSet" user command.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000640- Set "b:current_compiler" to the value of "current_compiler".
641- Without "!" the old value of "current_compiler" is restored.
642
643
644For writing a compiler plugin, see |write-compiler-plugin|.
645
646
647MANX AZTEC C *quickfix-manx* *compiler-manx*
648
649To use Vim with Manx's Aztec C compiler on the Amiga you should do the
650following:
651- Set the CCEDIT environment variable with the command: >
652 mset "CCEDIT=vim -q"
653- Compile with the -qf option. If the compiler finds any errors, Vim is
654 started and the cursor is positioned on the first error. The error message
655 will be displayed on the last line. You can go to other errors with the
656 commands mentioned above. You can fix the errors and write the file(s).
657- If you exit Vim normally the compiler will re-compile the same file. If you
658 exit with the :cq command, the compiler will terminate. Do this if you
659 cannot fix the error, or if another file needs to be compiled first.
660
661There are some restrictions to the Quickfix mode on the Amiga. The
662compiler only writes the first 25 errors to the errorfile (Manx's
663documentation does not say how to get more). If you want to find the others,
664you will have to fix a few errors and exit the editor. After recompiling,
665up to 25 remaining errors will be found.
666
667If Vim was started from the compiler, the :sh and some :! commands will not
668work, because Vim is then running in the same process as the compiler and
669stdin (standard input) will not be interactive.
670
671
672PYUNIT COMPILER *compiler-pyunit*
673
674This is not actually a compiler, but a unit testing framework for the
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000675Python language. It is included into standard Python distribution
676starting from version 2.0. For older versions, you can get it from
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677http://pyunit.sourceforge.net.
678
679When you run your tests with the help of the framework, possible errors
680are parsed by Vim and presented for you in quick-fix mode.
681
682Unfortunately, there is no standard way to run the tests.
683The alltests.py script seems to be used quite often, that's all.
684Useful values for the 'makeprg' options therefore are:
685 setlocal makeprg=./alltests.py " Run a testsuite
686 setlocal makeprg=python % " Run a single testcase
687
688Also see http://vim.sourceforge.net/tip_view.php?tip_id=280.
689
690
691TEX COMPILER *compiler-tex*
692
693Included in the distribution compiler for TeX ($VIMRUNTIME/compiler/tex.vim)
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000694uses make command if possible. If the compiler finds a file named "Makefile"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000695or "makefile" in the current directory, it supposes that you want to process
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000696your *TeX files with make, and the makefile does the right work. In this case
697compiler sets 'errorformat' for *TeX output and leaves 'makeprg' untouched. If
Bram Moolenaar071d4272004-06-13 20:20:40 +0000698neither "Makefile" nor "makefile" is found, the compiler will not use make.
699You can force the compiler to ignore makefiles by defining
700b:tex_ignore_makefile or g:tex_ignore_makefile variable (they are checked for
701existence only).
702
703If the compiler chose not to use make, it need to choose a right program for
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000704processing your input. If b:tex_flavor or g:tex_flavor (in this precedence)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705variable exists, it defines TeX flavor for :make (actually, this is the name
706of executed command), and if both variables do not exist, it defaults to
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000707"latex". For example, while editing chapter2.tex \input-ed from mypaper.tex
Bram Moolenaar071d4272004-06-13 20:20:40 +0000708written in AMS-TeX: >
709
710 :let b:tex_flavor = 'amstex'
711 :compiler tex
712< [editing...] >
713 :make mypaper
714
715Note that you must specify a name of the file to process as an argument (to
716process the right file when editing \input-ed or \include-ed file; portable
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000717solution for substituting % for no arguments is welcome). This is not in the
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718semantics of make, where you specify a target, not source, but you may specify
719filename without extension ".tex" and mean this as "make filename.dvi or
720filename.pdf or filename.some_result_extension according to compiler".
721
722Note: tex command line syntax is set to usable both for MikTeX (suggestion
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000723by Srinath Avadhanula) and teTeX (checked by Artem Chuprina). Suggestion
Bram Moolenaar071d4272004-06-13 20:20:40 +0000724from |errorformat-LaTeX| is too complex to keep it working for different
725shells and OSes and also does not allow to use other available TeX options,
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000726if any. If your TeX doesn't support "-interaction=nonstopmode", please
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727report it with different means to express \nonstopmode from the command line.
728
729=============================================================================
7307. The error format *error-file-format*
731
732 *errorformat* *E372* *E373* *E374*
733 *E375* *E376* *E377* *E378*
734The 'errorformat' option specifies a list of formats that are recognized. The
735first format that matches with an error message is used. You can add several
736formats for different messages your compiler produces, or even entries for
737multiple compilers. See |efm-entries|.
738
739Each entry in 'errorformat' is a scanf-like string that describes the format.
740First, you need to know how scanf works. Look in the documentation of your
741C compiler. Below you find the % items that Vim understands. Others are
742invalid.
743
744Special characters in 'errorformat' are comma and backslash. See
745|efm-entries| for how to deal with them. Note that a literal "%" is matched
746by "%%", thus it is not escaped with a backslash.
747
748Note: By default the difference between upper and lowercase is ignored. If
749you want to match case, add "\C" to the pattern |/\C|.
750
751
752Basic items
753
754 %f file name (finds a string)
755 %l line number (finds a number)
756 %c column number (finds a number representing character
757 column of the error, (1 <tab> == 1 character column))
758 %v virtual column number (finds a number representing
759 screen column of the error (1 <tab> == 8 screen
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000760 columns))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000761 %t error type (finds a single character)
762 %n error number (finds a number)
763 %m error message (finds a string)
764 %r matches the "rest" of a single-line file message %O/P/Q
765 %p pointer line (finds a sequence of '-', '.' or ' ' and
766 uses the length for the column number)
767 %*{conv} any scanf non-assignable conversion
768 %% the single '%' character
Bram Moolenaar2641f772005-03-25 21:58:17 +0000769 %s search text (finds a string)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000770
Bram Moolenaare344bea2005-09-01 20:46:49 +0000771The "%f" conversion may depend on the current 'isfname' setting. "~/" is
Bram Moolenaarf4630b62005-05-20 21:31:17 +0000772expanded to the home directory and environment variables are expanded.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000773
Bram Moolenaare344bea2005-09-01 20:46:49 +0000774The "%f" and "%m" conversions have to detect the end of the string. This
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000775normally happens by matching following characters and items. When nothing is
Bram Moolenaare344bea2005-09-01 20:46:49 +0000776following the rest of the line is matched. If "%f" is followed by a '%' or a
777backslash, it will look for a sequence of 'isfname' characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000778
779On MS-DOS, MS-Windows and OS/2 a leading "C:" will be included in "%f", even
780when using "%f:". This means that a file name which is a single alphabetical
781letter will not be detected.
782
783The "%p" conversion is normally followed by a "^". It's used for compilers
784that output a line like: >
785 ^
786or >
787 ---------^
788to indicate the column of the error. This is to be used in a multi-line error
789message. See |errorformat-javac| for a useful example.
790
Bram Moolenaar2641f772005-03-25 21:58:17 +0000791The "%s" conversion specifies the text to search for to locate the error line.
792The text is used as a literal string. The anchors "^" and "$" are added to
793the text to locate the error line exactly matching the search text and the
794text is prefixed with the "\V" atom to make it "very nomagic". The "%s"
795conversion can be used to locate lines without a line number in the error
796output. Like the output of the "grep" shell command.
797When the pattern is present the line number will not be used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000798
799Changing directory
800
801The following uppercase conversion characters specify the type of special
802format strings. At most one of them may be given as a prefix at the begin
803of a single comma-separated format pattern.
804Some compilers produce messages that consist of directory names that have to
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000805be prepended to each file name read by %f (example: GNU make). The following
Bram Moolenaar071d4272004-06-13 20:20:40 +0000806codes can be used to scan these directory names; they will be stored in an
807internal directory stack. *E379*
808 %D "enter directory" format string; expects a following
809 %f that finds the directory name
810 %X "leave directory" format string; expects following %f
811
812When defining an "enter directory" or "leave directory" format, the "%D" or
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000813"%X" has to be given at the start of that substring. Vim tracks the directory
Bram Moolenaar071d4272004-06-13 20:20:40 +0000814changes and prepends the current directory to each erroneous file found with a
815relative path. See |quickfix-directory-stack| for details, tips and
816limitations.
817
818
819Multi-line messages *errorformat-multi-line*
820
821It is possible to read the output of programs that produce multi-line
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000822messages, i.e. error strings that consume more than one line. Possible
Bram Moolenaar071d4272004-06-13 20:20:40 +0000823prefixes are:
824 %E start of a multi-line error message
825 %W start of a multi-line warning message
826 %I start of a multi-line informational message
827 %A start of a multi-line message (unspecified type)
828 %C continuation of a multi-line message
829 %Z end of a multi-line message
830These can be used with '+' and '-', see |efm-ignore| below.
831
832Example: Your compiler happens to write out errors in the following format
833(leading line numbers not being part of the actual output):
834
835 1 Error 275
836 2 line 42
837 3 column 3
838 4 ' ' expected after '--'
839
840The appropriate error format string has to look like this: >
841 :set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
842
843And the |:clist| error message generated for this error is:
844
845 1:42 col 3 error 275: ' ' expected after '--'
846
847Another example: Think of a Python interpreter that produces the following
848error message (line numbers are not part of the actual output):
849
850 1 ==============================================================
851 2 FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)
852 3 --------------------------------------------------------------
853 4 Traceback (most recent call last):
854 5 File "unittests/dbfacadeTest.py", line 89, in testFoo
855 6 self.assertEquals(34, dtid)
856 7 File "/usr/lib/python2.2/unittest.py", line 286, in
857 8 failUnlessEqual
858 9 raise self.failureException, \
859 10 AssertionError: 34 != 33
860 11
861 12 --------------------------------------------------------------
862 13 Ran 27 tests in 0.063s
863
864Say you want |:clist| write the relevant information of this message only,
865namely:
866 5 unittests/dbfacadeTest.py:89: AssertionError: 34 != 33
867
868Then the error format string could be defined as follows: >
869 :set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
870
871Note that the %C string is given before the %A here: since the expression
872' %.%#' (which stands for the regular expression ' .*') matches every line
873starting with a space, followed by any characters to the end of the line,
874it also hides line 7 which would trigger a separate error message otherwise.
875Error format strings are always parsed pattern by pattern until the first
876match occurs.
877
878
879Separate file name *errorformat-separate-filename*
880
881These prefixes are useful if the file name is given once and multiple messages
882follow that refer to this file name.
883 %O single-line file message: overread the matched part
884 %P single-line file message: push file %f onto the stack
885 %Q single-line file message: pop the last file from stack
886
887Example: Given a compiler that produces the following error logfile (without
888leading line numbers):
889
890 1 [a1.tt]
891 2 (1,17) error: ';' missing
892 3 (21,2) warning: variable 'z' not defined
893 4 (67,3) error: end of file found before string ended
894 5
895 6 [a2.tt]
896 7
897 8 [a3.tt]
898 9 NEW compiler v1.1
899 10 (2,2) warning: variable 'x' not defined
900 11 (67,3) warning: 's' already defined
901
902This logfile lists several messages for each file enclosed in [...] which are
903properly parsed by an error format like this: >
904 :set efm=%+P[%f],(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%-Q
905
906A call of |:clist| writes them accordingly with their correct filenames:
907
908 2 a1.tt:1 col 17 error: ';' missing
909 3 a1.tt:21 col 2 warning: variable 'z' not defined
910 4 a1.tt:67 col 3 error: end of file found before string ended
911 8 a3.tt:2 col 2 warning: variable 'x' not defined
912 9 a3.tt:67 col 3 warning: 's' already defined
913
914Unlike the other prefixes that all match against whole lines, %P, %Q and %O
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000915can be used to match several patterns in the same line. Thus it is possible
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916to parse even nested files like in the following line:
917 {"file1" {"file2" error1} error2 {"file3" error3 {"file4" error4 error5}}}
918The %O then parses over strings that do not contain any push/pop file name
919information. See |errorformat-LaTeX| for an extended example.
920
921
922Ignoring and using whole messages *efm-ignore*
923
924The codes '+' or '-' can be combined with the uppercase codes above; in that
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000925case they have to precede the letter, e.g. '%+A' or '%-G':
Bram Moolenaar071d4272004-06-13 20:20:40 +0000926 %- do not include the matching multi-line in any output
927 %+ include the whole matching line in the %m error string
928
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000929One prefix is only useful in combination with '+' or '-', namely %G. It parses
Bram Moolenaar071d4272004-06-13 20:20:40 +0000930over lines containing general information like compiler version strings or
931other headers that can be skipped.
932 %-G ignore this message
933 %+G general message
934
935
936Pattern matching
937
938The scanf()-like "%*[]" notation is supported for backward-compatibility
939with previous versions of Vim. However, it is also possible to specify
940(nearly) any Vim supported regular expression in format strings.
941Since meta characters of the regular expression language can be part of
942ordinary matching strings or file names (and therefore internally have to
943be escaped), meta symbols have to be written with leading '%':
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000944 %\ the single '\' character. Note that this has to be
Bram Moolenaar071d4272004-06-13 20:20:40 +0000945 escaped ("%\\") in ":set errorformat=" definitions.
946 %. the single '.' character.
947 %# the single '*'(!) character.
948 %^ the single '^' character.
949 %$ the single '$' character.
950 %[ the single '[' character for a [] character range.
951 %~ the single '~' character.
952When using character classes in expressions (see |/\i| for an overview),
953terms containing the "\+" quantifier can be written in the scanf() "%*"
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000954notation. Example: "%\\d%\\+" ("\d\+", "any number") is equivalent to "%*\\d".
Bram Moolenaar071d4272004-06-13 20:20:40 +0000955Important note: The \(...\) grouping of sub-matches can not be used in format
956specifications because it is reserved for internal conversions.
957
958
959Multiple entries in 'errorformat' *efm-entries*
960
961To be able to detect output from several compilers, several format patterns
962may be put in 'errorformat', separated by commas (note: blanks after the comma
963are ignored). The first pattern that has a complete match is used. If no
964match is found, matching parts from the last one will be used, although the
965file name is removed and the error message is set to the whole message. If
966there is a pattern that may match output from several compilers (but not in a
967right way), put it after one that is more restrictive.
968
969To include a comma in a pattern precede it with a backslash (you have to type
970two in a ":set" command). To include a backslash itself give two backslashes
971(you have to type four in a ":set" command). You also need to put a backslash
972before a space for ":set".
973
974
975Valid matches *quickfix-valid*
976
977If a line does not completely match one of the entries in 'errorformat', the
978whole line is put in the error message and the entry is marked "not valid"
979These lines are skipped with the ":cn" and ":cp" commands (unless there is
980no valid line at all). You can use ":cl!" to display all the error messages.
981
982If the error format does not contain a file name Vim cannot switch to the
983correct file. You will have to do this by hand.
984
985
986Examples
987
988The format of the file from the Amiga Aztec compiler is:
989
990 filename>linenumber:columnnumber:errortype:errornumber:errormessage
991
992 filename name of the file in which the error was detected
993 linenumber line number where the error was detected
994 columnnumber column number where the error was detected
995 errortype type of the error, normally a single 'E' or 'W'
996 errornumber number of the error (for lookup in the manual)
997 errormessage description of the error
998
999This can be matched with this 'errorformat' entry:
1000 %f>%l:%c:%t:%n:%m
1001
1002Some examples for C compilers that produce single-line error outputs:
1003%f:%l:\ %t%*[^0123456789]%n:\ %m for Manx/Aztec C error messages
1004 (scanf() doesn't understand [0-9])
1005%f\ %l\ %t%*[^0-9]%n:\ %m for SAS C
1006\"%f\"\\,%*[^0-9]%l:\ %m for generic C compilers
1007%f:%l:\ %m for GCC
1008%f:%l:\ %m,%Dgmake[%*\\d]:\ Entering\ directory\ `%f',
1009%Dgmake[%*\\d]:\ Leaving\ directory\ `%f'
1010 for GCC with gmake (concat the lines!)
1011%f(%l)\ :\ %*[^:]:\ %m old SCO C compiler (pre-OS5)
1012%f(%l)\ :\ %t%*[^0-9]%n:\ %m idem, with error type and number
1013%f:%l:\ %m,In\ file\ included\ from\ %f:%l:,\^I\^Ifrom\ %f:%l%m
1014 for GCC, with some extras
1015
1016Extended examples for the handling of multi-line messages are given below,
1017see |errorformat-Jikes| and |errorformat-LaTeX|.
1018
1019Note the backslash in front of a space and double quote. It is required for
1020the :set command. There are two backslashes in front of a comma, one for the
1021:set command and one to avoid recognizing the comma as a separator of error
1022formats.
1023
1024
1025Filtering messages
1026
1027If you have a compiler that produces error messages that do not fit in the
1028format string, you could write a program that translates the error messages
1029into this format. You can use this program with the ":make" command by
1030changing the 'makeprg' option. For example: >
1031 :set mp=make\ \\\|&\ error_filter
1032The backslashes before the pipe character are required to avoid it to be
1033recognized as a command separator. The backslash before each space is
1034required for the set command.
1035
1036=============================================================================
10378. The directory stack *quickfix-directory-stack*
1038
1039Quickfix maintains a stack for saving all used directories parsed from the
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001040make output. For GNU-make this is rather simple, as it always prints the
1041absolute path of all directories it enters and leaves. Regardless if this is
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042done via a 'cd' command in the makefile or with the parameter "-C dir" (change
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001043to directory before reading the makefile). It may be useful to use the switch
Bram Moolenaar071d4272004-06-13 20:20:40 +00001044"-w" to force GNU-make to print out the working directory before and after
1045processing.
1046
1047Maintaining the correct directory is more complicated if you don't use
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001048GNU-make. AIX-make for example doesn't print any information about its
1049working directory. Then you need to enhance the makefile. In the makefile of
1050LessTif there is a command which echoes "Making {target} in {dir}". The
1051special problem here is that it doesn't print informations on leaving the
1052directory and that it doesn't print the absolute path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053
1054To solve the problem with relative paths and missing "leave directory"
1055messages Vim uses following algorithm:
1056
10571) Check if the given directory is a subdirectory of the current directory.
1058 If this is true, store it as the current directory.
10592) If it is not a subdir of the current directory, try if this is a
1060 subdirectory of one of the upper directories.
10613) If the directory still isn't found, it is assumed to be a subdirectory
1062 of Vim's current directory.
1063
1064Additionally it is checked for every file, if it really exists in the
1065identified directory. If not, it is searched in all other directories of the
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001066directory stack (NOT the directory subtree!). If it is still not found, it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067assumed that it is in Vim's current directory.
1068
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001069There are limitation in this algorithm. This examples assume that make just
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070prints information about entering a directory in the form "Making all in dir".
1071
10721) Assume you have following directories and files:
1073 ./dir1
1074 ./dir1/file1.c
1075 ./file1.c
1076
1077 If make processes the directory "./dir1" before the current directory and
1078 there is an error in the file "./file1.c", you will end up with the file
1079 "./dir1/file.c" loaded by Vim.
1080
1081 This can only be solved with a "leave directory" message.
1082
10832) Assume you have following directories and files:
1084 ./dir1
1085 ./dir1/dir2
1086 ./dir2
1087
1088 You get the following:
1089
1090 Make output Directory interpreted by Vim
1091 ------------------------ ----------------------------
1092 Making all in dir1 ./dir1
1093 Making all in dir2 ./dir1/dir2
1094 Making all in dir2 ./dir1/dir2
1095
1096 This can be solved by printing absolute directories in the "enter directory"
1097 message or by printing "leave directory" messages..
1098
1099To avoid this problems, ensure to print absolute directory names and "leave
1100directory" messages.
1101
1102Examples for Makefiles:
1103
1104Unix:
1105 libs:
1106 for dn in $(LIBDIRS); do \
1107 (cd $$dn; echo "Entering dir '$$(pwd)'"; make); \
1108 echo "Leaving dir"; \
1109 done
1110
1111Add
1112 %DEntering\ dir\ '%f',%XLeaving\ dir
1113to your 'errorformat' to handle the above output.
1114
1115Note that Vim doesn't check if the directory name in a "leave directory"
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001116messages is the current directory. This is why you could just use the message
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117"Leaving dir".
1118
1119=============================================================================
11209. Specific error file formats *errorformats*
1121
1122 *errorformat-Jikes*
1123Jikes(TM), a source-to-bytecode Java compiler published by IBM Research,
1124produces simple multi-line error messages.
1125
1126An 'errorformat' string matching the produced messages is shown below.
1127The following lines can be placed in the user's |vimrc| to overwrite Vim's
1128recognized default formats, or see |:set+=| how to install this format
1129additionally to the default. >
1130
1131 :set efm=%A%f:%l:%c:%*\\d:%*\\d:,
1132 \%C%*\\s%trror:%m,
1133 \%+C%*[^:]%trror:%m,
1134 \%C%*\\s%tarning:%m,
1135 \%C%m
1136<
1137Jikes(TM) produces a single-line error message when invoked with the option
1138"+E", and can be matched with the following: >
1139
1140 :set efm=%f:%l:%v:%*\\d:%*\\d:%*\\s%m
1141<
1142 *errorformat-javac*
1143This 'errorformat' has been reported to work well for javac, which outputs a
1144line with "^" to indicate the column of the error: >
1145 :set efm=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
1146or: >
1147 :set efm=%A%f:%l:\ %m,%+Z%p^,%+C%.%#,%-G%.%#
1148<
1149 *errorformat-ant*
1150For ant (http://jakarta.apache.org/) the above errorformat has to be modified
1151to honour the leading [javac] in front of each javac output line: >
1152 :set efm=%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
1153
1154The 'errorformat' can also be configured to handle ant together with either
1155javac or jikes. If you're using jikes, you should tell ant to use jikes' +E
1156command line switch which forces jikes to generate one-line error messages.
1157This is what the second line (of a build.xml file) below does: >
1158 <property name = "build.compiler" value = "jikes"/>
1159 <property name = "build.compiler.emacs" value = "true"/>
1160
1161The 'errorformat' which handles ant with both javac and jikes is: >
1162 :set efm=\ %#[javac]\ %#%f:%l:%c:%*\\d:%*\\d:\ %t%[%^:]%#:%m,
1163 \%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
1164<
1165 *errorformat-jade*
1166parsing jade (see http://www.jclark.com/) errors is simple: >
1167 :set efm=jade:%f:%l:%c:%t:%m
1168<
1169 *errorformat-LaTeX*
1170The following is an example how an 'errorformat' string can be specified
1171for the (La)TeX typesetting system which displays error messages over
1172multiple lines. The output of ":clist" and ":cc" etc. commands displays
1173multi-lines in a single line, leading white space is removed.
1174It should be easy to adopt the above LaTeX errorformat to any compiler output
1175consisting of multi-line errors.
1176
1177The commands can be placed in a |vimrc| file or some other Vim script file,
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001178e.g. a script containing LaTeX related stuff which is loaded only when editing
Bram Moolenaar071d4272004-06-13 20:20:40 +00001179LaTeX sources.
1180Make sure to copy all lines of the example (in the given order), afterwards
1181remove the comment lines. For the '\' notation at the start of some lines see
1182|line-continuation|.
1183
1184 First prepare 'makeprg' such that LaTeX will report multiple
1185 errors; do not stop when the first error has occurred: >
1186 :set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}
1187<
1188 Start of multi-line error messages: >
1189 :set efm=%E!\ LaTeX\ %trror:\ %m,
1190 \%E!\ %m,
1191< Start of multi-line warning messages; the first two also
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001192 include the line number. Meaning of some regular expressions:
Bram Moolenaar071d4272004-06-13 20:20:40 +00001193 - "%.%#" (".*") matches a (possibly empty) string
1194 - "%*\\d" ("\d\+") matches a number >
1195 \%+WLaTeX\ %.%#Warning:\ %.%#line\ %l%.%#,
1196 \%+W%.%#\ at\ lines\ %l--%*\\d,
1197 \%WLaTeX\ %.%#Warning:\ %m,
1198< Possible continuations of error/warning messages; the first
1199 one also includes the line number: >
1200 \%Cl.%l\ %m,
1201 \%+C\ \ %m.,
1202 \%+C%.%#-%.%#,
1203 \%+C%.%#[]%.%#,
1204 \%+C[]%.%#,
1205 \%+C%.%#%[{}\\]%.%#,
1206 \%+C<%.%#>%.%#,
1207 \%C\ \ %m,
1208< Lines that match the following patterns do not contain any
1209 important information; do not include them in messages: >
1210 \%-GSee\ the\ LaTeX%m,
1211 \%-GType\ \ H\ <return>%m,
1212 \%-G\ ...%.%#,
1213 \%-G%.%#\ (C)\ %.%#,
1214 \%-G(see\ the\ transcript%.%#),
1215< Generally exclude any empty or whitespace-only line from
1216 being displayed: >
1217 \%-G\\s%#,
1218< The LaTeX output log does not specify the names of erroneous
1219 source files per line; rather they are given globally,
1220 enclosed in parentheses.
1221 The following patterns try to match these names and store
1222 them in an internal stack. The patterns possibly scan over
1223 the same input line (one after another), the trailing "%r"
1224 conversion indicates the "rest" of the line that will be
1225 parsed in the next go until the end of line is reached.
1226
1227 Overread a file name enclosed in '('...')'; do not push it
1228 on a stack since the file apparently does not contain any
1229 error: >
1230 \%+O(%f)%r,
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001231< Push a file name onto the stack. The name is given after '(': >
Bram Moolenaar071d4272004-06-13 20:20:40 +00001232 \%+P(%f%r,
1233 \%+P\ %\\=(%f%r,
1234 \%+P%*[^()](%f%r,
1235 \%+P[%\\d%[^()]%#(%f%r,
1236< Pop the last stored file name when a ')' is scanned: >
1237 \%+Q)%r,
1238 \%+Q%*[^()])%r,
1239 \%+Q[%\\d%*[^()])%r
1240
1241Note that in some cases file names in the LaTeX output log cannot be parsed
1242properly. The parser might have been messed up by unbalanced parentheses
1243then. The above example tries to catch the most relevant cases only.
1244You can customize the given setting to suit your own purposes, for example,
1245all the annoying "Overfull ..." warnings could be excluded from being
1246recognized as an error.
1247Alternatively to filtering the LaTeX compiler output, it is also possible
1248to directly read the *.log file that is produced by the [La]TeX compiler.
1249This contains even more useful information about possible error causes.
1250However, to properly parse such a complex file, an external filter should
1251be used. See the description further above how to make such a filter known
1252by Vim.
1253
1254 *errorformat-Perl*
1255In $VIMRUNTIME/tools you can find the efm_perl.pl script, which filters Perl
1256error messages into a format that quickfix mode will understand. See the
1257start of the file about how to use it.
1258
1259
1260
1261 vim:tw=78:ts=8:ft=help:norl: