blob: 5430be0764c95e64a8ea93e6b532c121ca1532fe [file] [log] [blame]
Bram Moolenaar1ef15e32006-02-01 21:56:25 +00001*quickfix.txt* For Vim version 7.0aa. Last change: 2006 Jan 30
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
Bram Moolenaar1ef15e32006-02-01 21:56:25 +0000314FileType event. Then the BufReadPost event is triggered, using "quickfix" for
315the buffer name. This can be used to perform some action on the listed
316errors. Example: >
Bram Moolenaar280f1262006-01-30 00:14:18 +0000317 au BufReadPost quickfix setlocal modifiable
318 \ | silent exe 'g/^/s//\=line(".")." "/'
319 \ | setlocal nomodifiable
Bram Moolenaar071d4272004-06-13 20:20:40 +0000320This prepends the line number to each line. Note the use of "\=" in the
321substitute string of the ":s" command, which is used to evaluate an
322expression.
Bram Moolenaar1ef15e32006-02-01 21:56:25 +0000323The BufWinEnter event is also triggered, again using "quickfix" for the buffer
324name.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000325
326Note: Making changes in the quickfix window has no effect on the list of
327errors. 'modifiable' is off to avoid making changes. If you delete or insert
328lines anyway, the relation between the text and the error number is messed up.
329If you really want to do this, you could write the contents of the quickfix
330window to a file and use ":cfile" to have it parsed and used as the new error
331list.
332
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000333 *location-list-window*
Bram Moolenaar280f1262006-01-30 00:14:18 +0000334The location list window displays the entries in a location list. When you
335open a location list window, it is created below the current window and
336displays the location list for the current window. The location list window
337is similar to the quickfix window, except that you can have more than one
Bram Moolenaar1ef15e32006-02-01 21:56:25 +0000338location list window open at a time. When you use a location list command in
339this window, the displayed location list is used.
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000340
Bram Moolenaar280f1262006-01-30 00:14:18 +0000341When you select a file from the location list window, the following steps are
342used to find a window to edit the file:
343
3441. If a window with the location list displayed in the location list window is
345 present, then the file is opened in that window.
3462. If the above step fails and if the file is already opened in another
347 window, then that window is used.
3483. If the above step fails then an existing window showing a buffer with
349 'buftype' not set is used.
3504. If the above step fails, then the file is edited in a new window.
351
352In all of the above cases, if the location list for the selected window is not
353yet set, then it is set to the location list displayed in the location list
354window.
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000355
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356=============================================================================
3573. Using more than one list of errors *quickfix-error-lists*
358
359So far has been assumed that there is only one list of errors. Actually the
360ten last used lists are remembered. When starting a new list, the previous
361ones are automatically kept. Two commands can be used to access older error
362lists. They set one of the existing error lists as the current one.
363
364 *:colder* *:col* *E380*
365:col[der] [count] Go to older error list. When [count] is given, do
366 this [count] times. When already at the oldest error
367 list, an error message is given.
368
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000369 *:lolder* *:lol*
370:lol[der] [count] Same as ":colder", except use the location list for
371 the current window instead of the quickfix list.
372
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373 *:cnewer* *:cnew* *E381*
374:cnew[er] [count] Go to newer error list. When [count] is given, do
375 this [count] times. When already at the newest error
376 list, an error message is given.
377
Bram Moolenaard12f5c12006-01-25 22:10:52 +0000378 *:lnewer* *:lnew*
379:lnew[er] [count] Same as ":cnewer", except use the location list for
380 the current window instead of the quickfix list.
381
Bram Moolenaar071d4272004-06-13 20:20:40 +0000382When adding a new error list, it becomes the current list.
383
384When ":colder" has been used and ":make" or ":grep" is used to add a new error
385list, one newer list is overwritten. This is especially useful if you are
386browsing with ":grep" |grep|. If you want to keep the more recent error
387lists, use ":cnewer 99" first.
388
389=============================================================================
3904. Using :make *:make_makeprg*
391
392 *:mak* *:make*
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000393:mak[e][!] [arguments] 1. If vim was built with |+autocmd|, all relevant
394 |QuickFixCmdPre| autocommands are executed.
395 2. If the 'autowrite' option is on, write any changed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000396 buffers
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000397 3. An errorfile name is made from 'makeef'. If
Bram Moolenaar071d4272004-06-13 20:20:40 +0000398 'makeef' doesn't contain "##", and a file with this
399 name already exists, it is deleted.
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000400 4. The program given with the 'makeprg' option is
Bram Moolenaar071d4272004-06-13 20:20:40 +0000401 started (default "make") with the optional
402 [arguments] and the output is saved in the
403 errorfile (for Unix it is also echoed on the
404 screen).
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000405 5. The errorfile is read using 'errorformat'.
406 6. If [!] is not given the first error is jumped to.
407 7. The errorfile is deleted.
408 8. If vim was built with |+autocmd|, all relevant
409 |QuickFixCmdPost| autocommands are executed.
410 9. You can now move through the errors with commands
Bram Moolenaar071d4272004-06-13 20:20:40 +0000411 like |:cnext| and |:cprevious|, see above.
412 This command does not accept a comment, any "
413 characters are considered part of the arguments.
414
415The ":make" command executes the command given with the 'makeprg' option.
416This is done by passing the command to the shell given with the 'shell'
417option. This works almost like typing
418
419 ":!{makeprg} [arguments] {shellpipe} {errorfile}".
420
421{makeprg} is the string given with the 'makeprg' option. Any command can be
422used, not just "make". Characters '%' and '#' are expanded as usual on a
423command-line. You can use "%<" to insert the current file name without
424extension, or "#<" to insert the alternate file name without extension, for
425example: >
426 :set makeprg=make\ #<.o
427
428[arguments] is anything that is typed after ":make".
429{shellpipe} is the 'shellpipe' option.
430{errorfile} is the 'makeef' option, with ## replaced to make it unique.
431
432The placeholder "$*" can be used for the argument list in {makeprog} if the
433command needs some additional characters after its arguments. The $* is
434replaced then by all arguments. Example: >
435 :set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}
436or simpler >
437 :let &mp = 'latex \\nonstopmode \\input\{$*}'
438"$*" can be given multiple times, for example: >
439 :set makeprg=gcc\ -o\ $*\ $*
440
441The 'shellpipe' option defaults to ">" for the Amiga, MS-DOS and Win32. This
442means that the output of the compiler is saved in a file and not shown on the
443screen directly. For Unix "| tee" is used. The compiler output is shown on
444the screen and saved in a file the same time. Depending on the shell used
445"|& tee" or "2>&1| tee" is the default, so stderr output will be included.
446
447If 'shellpipe' is empty, the {errorfile} part will be omitted. This is useful
448for compilers that write to an errorfile themselves (e.g., Manx's Amiga C).
449
450==============================================================================
Bram Moolenaar86b68352004-12-27 21:59:20 +00004515. Using :vimgrep and :grep *grep* *lid*
452
453Vim has two ways to find matches for a pattern: Internal and external. The
454advantage of the internal grep is that it works on all systems and uses the
455powerful Vim search patterns. An external grep program can be used when the
456Vim grep does not do what you want.
457
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000458The internal method will be slower, because files are read into memory. The
459advantages are:
460- Line separators and encoding are automatically recognized, as if a file is
461 being edited.
462- Uses Vim search patterns. Multi-line patterns can be used.
463- When plugins are enabled: compressed and remote files can be searched.
464 |gzip| |netrw|
Bram Moolenaardcaf10e2005-01-21 11:55:25 +0000465- When 'hidden' is set the files are kept loaded, thus repeating a search is
466 much faster. Uses a lot of memory though!
Bram Moolenaar86b68352004-12-27 21:59:20 +0000467
468
4695.1 using Vim's internal grep
470
Bram Moolenaare49b69a2005-01-08 16:11:57 +0000471 *:vim* *:vimgrep* *E682* *E683*
Bram Moolenaar05159a02005-02-26 23:04:13 +0000472:vim[grep][!] /{pattern}/[g][j] {file} ...
Bram Moolenaar86b68352004-12-27 21:59:20 +0000473 Search for {pattern} in the files {file} ... and set
474 the error list to the matches.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000475 Without the 'g' flag each line is added only once.
476 With 'g' every match is added.
477
478 {pattern} is a Vim search pattern. Instead of
479 enclosing it in / any non-ID character (see
480 |'isident'|) can be used, so long as it does not
481 appear in {pattern}.
482 'ignorecase' applies. To overrule it put |/\c| in the
483 pattern to ignore case or |/\C| to match case.
484 'smartcase' is not used.
485
486 Without the 'j' flag Vim jumps to the first match.
487 With 'j' only the quickfix list is updated.
488 With the [!] any changes in the current buffer are
489 abandoned.
490
Bram Moolenaardcaf10e2005-01-21 11:55:25 +0000491 Every second or so the searched file name is displayed
492 to give you an idea of the progress made.
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000493 Examples: >
494 :vimgrep /an error/ *.c
495 :vimgrep /\<FileName\>/ *.h include/*
Bram Moolenaar231334e2005-07-25 20:46:57 +0000496 :vimgrep /myfunc/ **/*.c
497< For the use of "**" see |starstar-wildcard|.
Bram Moolenaar86b68352004-12-27 21:59:20 +0000498
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000499:vim[grep][!] {pattern} {file} ...
500 Like above, but instead of enclosing the pattern in a
501 non-ID character use a white-separated pattern. The
502 pattern must start with an ID character.
503 Example: >
504 :vimgrep Error *.c
505<
Bram Moolenaar86b68352004-12-27 21:59:20 +0000506 *:vimgrepa* *:vimgrepadd*
Bram Moolenaar05159a02005-02-26 23:04:13 +0000507:vimgrepa[dd][!] /{pattern}/[g][j] {file} ...
508:vimgrepa[dd][!] {pattern} {file} ...
Bram Moolenaar86b68352004-12-27 21:59:20 +0000509 Just like ":vimgrep", but instead of making a new list
510 of errors the matches are appended to the current
511 list.
512
513
5145.2 External grep
Bram Moolenaar071d4272004-06-13 20:20:40 +0000515
516Vim can interface with "grep" and grep-like programs (such as the GNU
517id-utils) in a similar way to its compiler integration (see |:make| above).
518
519[Unix trivia: The name for the Unix "grep" command comes from ":g/re/p", where
520"re" stands for Regular Expression.]
521
522 *:gr* *:grep*
523:gr[ep][!] [arguments] Just like ":make", but use 'grepprg' instead of
524 'makeprg' and 'grepformat' instead of 'errorformat'.
Bram Moolenaar86b68352004-12-27 21:59:20 +0000525 When 'grepprg' is "internal" this works like
526 |:vimgrep|. Note that the pattern needs to be
527 enclosed in separator characters then.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000528 *:grepa* *:grepadd*
529:grepa[dd][!] [arguments]
530 Just like ":grep", but instead of making a new list of
531 errors the matches are appended to the current list.
532 Example: >
533 :grep nothing %
534 :bufdo grepadd! something %
535< The first command makes a new error list which is
536 empty. The second command executes "grepadd" for each
537 listed buffer. Note the use of ! to avoid that
538 ":grepadd" jumps to the first error, which is not
539 allowed with |:bufdo|.
540
Bram Moolenaar86b68352004-12-27 21:59:20 +00005415.3 Setting up external grep
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542
543If you have a standard "grep" program installed, the :grep command may work
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000544well with the defaults. The syntax is very similar to the standard command: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545
546 :grep foo *.c
547
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000548Will search all files with the .c extension for the substring "foo". The
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549arguments to :grep are passed straight to the "grep" program, so you can use
550whatever options your "grep" supports.
551
552By default, :grep invokes grep with the -n option (show file and line
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000553numbers). You can change this with the 'grepprg' option. You will need to set
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554'grepprg' if:
555
556a) You are using a program that isn't called "grep"
557b) You have to call grep with a full path
558c) You want to pass other options automatically (e.g. case insensitive
559 search.)
560
561Once "grep" has executed, Vim parses the results using the 'grepformat'
562option. This option works in the same way as the 'errorformat' option - see
563that for details. You may need to change 'grepformat' from the default if
564your grep outputs in a non-standard format, or you are using some other
565program with a special format.
566
567Once the results are parsed, Vim loads the first file containing a match and
568jumps to the appropriate line, in the same way that it jumps to a compiler
569error in |quickfix| mode. You can then use the |:cnext|, |:clist|, etc.
570commands to see the other matches.
571
572
Bram Moolenaar86b68352004-12-27 21:59:20 +00005735.4 Using :grep with id-utils
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574
575You can set up :grep to work with the GNU id-utils like this: >
576
577 :set grepprg=lid\ -Rgrep\ -s
578 :set grepformat=%f:%l:%m
579
580then >
581 :grep (regexp)
582
583works just as you'd expect.
584(provided you remembered to mkid first :)
585
586
Bram Moolenaar86b68352004-12-27 21:59:20 +00005875.5 Browsing source code with :vimgrep or :grep
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588
589Using the stack of error lists that Vim keeps, you can browse your files to
590look for functions and the functions they call. For example, suppose that you
591have to add an argument to the read_file() function. You enter this command: >
592
Bram Moolenaar86b68352004-12-27 21:59:20 +0000593 :vimgrep /\<read_file\>/ *.c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594
595You use ":cn" to go along the list of matches and add the argument. At one
596place you have to get the new argument from a higher level function msg(), and
597need to change that one too. Thus you use: >
598
Bram Moolenaar86b68352004-12-27 21:59:20 +0000599 :vimgrep /\<msg\>/ *.c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600
601While changing the msg() functions, you find another function that needs to
Bram Moolenaar86b68352004-12-27 21:59:20 +0000602get the argument from a higher level. You can again use ":vimgrep" to find
603these functions. Once you are finished with one function, you can use >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000604
605 :colder
606
607to go back to the previous one.
608
Bram Moolenaar86b68352004-12-27 21:59:20 +0000609This works like browsing a tree: ":vimgrep" goes one level deeper, creating a
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610list of branches. ":colder" goes back to the previous level. You can mix
Bram Moolenaar86b68352004-12-27 21:59:20 +0000611this use of ":vimgrep" and "colder" to browse all the locations in a tree-like
Bram Moolenaar071d4272004-06-13 20:20:40 +0000612way. If you do this consistently, you will find all locations without the
613need to write down a "todo" list.
614
615=============================================================================
6166. Selecting a compiler *compiler-select*
617
618 *:comp* *:compiler* *E666*
619:comp[iler][!] {name} Set options to work with compiler {name}.
620 Without the "!" options are set for the
621 current buffer. With "!" global options are
622 set.
623 If you use ":compiler foo" in "file.foo" and
624 then ":compiler! bar" in another buffer, Vim
625 will keep on using "foo" in "file.foo".
626 {not available when compiled without the
627 |+eval| feature}
628
629
630The Vim plugins in the "compiler" directory will set options to use the
631selected compiler. For ":compiler" local options are set, for ":compiler!"
632global options.
633 *current_compiler*
634To support older Vim versions, the plugins always use "current_compiler" and
635not "b:current_compiler". What the command actually does is the following:
636
637- Delete the "current_compiler" and "b:current_compiler" variables.
638- Define the "CompilerSet" user command. With "!" it does ":set", without "!"
639 it does ":setlocal".
640- Execute ":runtime! compiler/{name}.vim". The plugins are expected to set
641 options with "CompilerSet" and set the "current_compiler" variable to the
642 name of the compiler.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000643- Delete the "CompilerSet" user command.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000644- Set "b:current_compiler" to the value of "current_compiler".
645- Without "!" the old value of "current_compiler" is restored.
646
647
648For writing a compiler plugin, see |write-compiler-plugin|.
649
650
651MANX AZTEC C *quickfix-manx* *compiler-manx*
652
653To use Vim with Manx's Aztec C compiler on the Amiga you should do the
654following:
655- Set the CCEDIT environment variable with the command: >
656 mset "CCEDIT=vim -q"
657- Compile with the -qf option. If the compiler finds any errors, Vim is
658 started and the cursor is positioned on the first error. The error message
659 will be displayed on the last line. You can go to other errors with the
660 commands mentioned above. You can fix the errors and write the file(s).
661- If you exit Vim normally the compiler will re-compile the same file. If you
662 exit with the :cq command, the compiler will terminate. Do this if you
663 cannot fix the error, or if another file needs to be compiled first.
664
665There are some restrictions to the Quickfix mode on the Amiga. The
666compiler only writes the first 25 errors to the errorfile (Manx's
667documentation does not say how to get more). If you want to find the others,
668you will have to fix a few errors and exit the editor. After recompiling,
669up to 25 remaining errors will be found.
670
671If Vim was started from the compiler, the :sh and some :! commands will not
672work, because Vim is then running in the same process as the compiler and
673stdin (standard input) will not be interactive.
674
675
676PYUNIT COMPILER *compiler-pyunit*
677
678This is not actually a compiler, but a unit testing framework for the
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000679Python language. It is included into standard Python distribution
680starting from version 2.0. For older versions, you can get it from
Bram Moolenaar071d4272004-06-13 20:20:40 +0000681http://pyunit.sourceforge.net.
682
683When you run your tests with the help of the framework, possible errors
684are parsed by Vim and presented for you in quick-fix mode.
685
686Unfortunately, there is no standard way to run the tests.
687The alltests.py script seems to be used quite often, that's all.
688Useful values for the 'makeprg' options therefore are:
689 setlocal makeprg=./alltests.py " Run a testsuite
690 setlocal makeprg=python % " Run a single testcase
691
692Also see http://vim.sourceforge.net/tip_view.php?tip_id=280.
693
694
695TEX COMPILER *compiler-tex*
696
697Included in the distribution compiler for TeX ($VIMRUNTIME/compiler/tex.vim)
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000698uses make command if possible. If the compiler finds a file named "Makefile"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000699or "makefile" in the current directory, it supposes that you want to process
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000700your *TeX files with make, and the makefile does the right work. In this case
701compiler sets 'errorformat' for *TeX output and leaves 'makeprg' untouched. If
Bram Moolenaar071d4272004-06-13 20:20:40 +0000702neither "Makefile" nor "makefile" is found, the compiler will not use make.
703You can force the compiler to ignore makefiles by defining
704b:tex_ignore_makefile or g:tex_ignore_makefile variable (they are checked for
705existence only).
706
707If the compiler chose not to use make, it need to choose a right program for
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000708processing your input. If b:tex_flavor or g:tex_flavor (in this precedence)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000709variable exists, it defines TeX flavor for :make (actually, this is the name
710of executed command), and if both variables do not exist, it defaults to
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000711"latex". For example, while editing chapter2.tex \input-ed from mypaper.tex
Bram Moolenaar071d4272004-06-13 20:20:40 +0000712written in AMS-TeX: >
713
714 :let b:tex_flavor = 'amstex'
715 :compiler tex
716< [editing...] >
717 :make mypaper
718
719Note that you must specify a name of the file to process as an argument (to
720process the right file when editing \input-ed or \include-ed file; portable
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000721solution for substituting % for no arguments is welcome). This is not in the
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722semantics of make, where you specify a target, not source, but you may specify
723filename without extension ".tex" and mean this as "make filename.dvi or
724filename.pdf or filename.some_result_extension according to compiler".
725
726Note: tex command line syntax is set to usable both for MikTeX (suggestion
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000727by Srinath Avadhanula) and teTeX (checked by Artem Chuprina). Suggestion
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728from |errorformat-LaTeX| is too complex to keep it working for different
729shells and OSes and also does not allow to use other available TeX options,
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000730if any. If your TeX doesn't support "-interaction=nonstopmode", please
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731report it with different means to express \nonstopmode from the command line.
732
733=============================================================================
7347. The error format *error-file-format*
735
736 *errorformat* *E372* *E373* *E374*
737 *E375* *E376* *E377* *E378*
738The 'errorformat' option specifies a list of formats that are recognized. The
739first format that matches with an error message is used. You can add several
740formats for different messages your compiler produces, or even entries for
741multiple compilers. See |efm-entries|.
742
743Each entry in 'errorformat' is a scanf-like string that describes the format.
744First, you need to know how scanf works. Look in the documentation of your
745C compiler. Below you find the % items that Vim understands. Others are
746invalid.
747
748Special characters in 'errorformat' are comma and backslash. See
749|efm-entries| for how to deal with them. Note that a literal "%" is matched
750by "%%", thus it is not escaped with a backslash.
751
752Note: By default the difference between upper and lowercase is ignored. If
753you want to match case, add "\C" to the pattern |/\C|.
754
755
756Basic items
757
758 %f file name (finds a string)
759 %l line number (finds a number)
760 %c column number (finds a number representing character
761 column of the error, (1 <tab> == 1 character column))
762 %v virtual column number (finds a number representing
763 screen column of the error (1 <tab> == 8 screen
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000764 columns))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000765 %t error type (finds a single character)
766 %n error number (finds a number)
767 %m error message (finds a string)
768 %r matches the "rest" of a single-line file message %O/P/Q
769 %p pointer line (finds a sequence of '-', '.' or ' ' and
770 uses the length for the column number)
771 %*{conv} any scanf non-assignable conversion
772 %% the single '%' character
Bram Moolenaar2641f772005-03-25 21:58:17 +0000773 %s search text (finds a string)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774
Bram Moolenaare344bea2005-09-01 20:46:49 +0000775The "%f" conversion may depend on the current 'isfname' setting. "~/" is
Bram Moolenaarf4630b62005-05-20 21:31:17 +0000776expanded to the home directory and environment variables are expanded.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000777
Bram Moolenaare344bea2005-09-01 20:46:49 +0000778The "%f" and "%m" conversions have to detect the end of the string. This
Bram Moolenaar482aaeb2005-09-29 18:26:07 +0000779normally happens by matching following characters and items. When nothing is
Bram Moolenaare344bea2005-09-01 20:46:49 +0000780following the rest of the line is matched. If "%f" is followed by a '%' or a
781backslash, it will look for a sequence of 'isfname' characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782
783On MS-DOS, MS-Windows and OS/2 a leading "C:" will be included in "%f", even
784when using "%f:". This means that a file name which is a single alphabetical
785letter will not be detected.
786
787The "%p" conversion is normally followed by a "^". It's used for compilers
788that output a line like: >
789 ^
790or >
791 ---------^
792to indicate the column of the error. This is to be used in a multi-line error
793message. See |errorformat-javac| for a useful example.
794
Bram Moolenaar2641f772005-03-25 21:58:17 +0000795The "%s" conversion specifies the text to search for to locate the error line.
796The text is used as a literal string. The anchors "^" and "$" are added to
797the text to locate the error line exactly matching the search text and the
798text is prefixed with the "\V" atom to make it "very nomagic". The "%s"
799conversion can be used to locate lines without a line number in the error
800output. Like the output of the "grep" shell command.
801When the pattern is present the line number will not be used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000802
803Changing directory
804
805The following uppercase conversion characters specify the type of special
806format strings. At most one of them may be given as a prefix at the begin
807of a single comma-separated format pattern.
808Some compilers produce messages that consist of directory names that have to
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000809be prepended to each file name read by %f (example: GNU make). The following
Bram Moolenaar071d4272004-06-13 20:20:40 +0000810codes can be used to scan these directory names; they will be stored in an
811internal directory stack. *E379*
812 %D "enter directory" format string; expects a following
813 %f that finds the directory name
814 %X "leave directory" format string; expects following %f
815
816When defining an "enter directory" or "leave directory" format, the "%D" or
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000817"%X" has to be given at the start of that substring. Vim tracks the directory
Bram Moolenaar071d4272004-06-13 20:20:40 +0000818changes and prepends the current directory to each erroneous file found with a
819relative path. See |quickfix-directory-stack| for details, tips and
820limitations.
821
822
823Multi-line messages *errorformat-multi-line*
824
825It is possible to read the output of programs that produce multi-line
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000826messages, i.e. error strings that consume more than one line. Possible
Bram Moolenaar071d4272004-06-13 20:20:40 +0000827prefixes are:
828 %E start of a multi-line error message
829 %W start of a multi-line warning message
830 %I start of a multi-line informational message
831 %A start of a multi-line message (unspecified type)
832 %C continuation of a multi-line message
833 %Z end of a multi-line message
834These can be used with '+' and '-', see |efm-ignore| below.
835
836Example: Your compiler happens to write out errors in the following format
837(leading line numbers not being part of the actual output):
838
839 1 Error 275
840 2 line 42
841 3 column 3
842 4 ' ' expected after '--'
843
844The appropriate error format string has to look like this: >
845 :set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
846
847And the |:clist| error message generated for this error is:
848
849 1:42 col 3 error 275: ' ' expected after '--'
850
851Another example: Think of a Python interpreter that produces the following
852error message (line numbers are not part of the actual output):
853
854 1 ==============================================================
855 2 FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)
856 3 --------------------------------------------------------------
857 4 Traceback (most recent call last):
858 5 File "unittests/dbfacadeTest.py", line 89, in testFoo
859 6 self.assertEquals(34, dtid)
860 7 File "/usr/lib/python2.2/unittest.py", line 286, in
861 8 failUnlessEqual
862 9 raise self.failureException, \
863 10 AssertionError: 34 != 33
864 11
865 12 --------------------------------------------------------------
866 13 Ran 27 tests in 0.063s
867
868Say you want |:clist| write the relevant information of this message only,
869namely:
870 5 unittests/dbfacadeTest.py:89: AssertionError: 34 != 33
871
872Then the error format string could be defined as follows: >
873 :set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
874
875Note that the %C string is given before the %A here: since the expression
876' %.%#' (which stands for the regular expression ' .*') matches every line
877starting with a space, followed by any characters to the end of the line,
878it also hides line 7 which would trigger a separate error message otherwise.
879Error format strings are always parsed pattern by pattern until the first
880match occurs.
881
882
883Separate file name *errorformat-separate-filename*
884
885These prefixes are useful if the file name is given once and multiple messages
886follow that refer to this file name.
887 %O single-line file message: overread the matched part
888 %P single-line file message: push file %f onto the stack
889 %Q single-line file message: pop the last file from stack
890
891Example: Given a compiler that produces the following error logfile (without
892leading line numbers):
893
894 1 [a1.tt]
895 2 (1,17) error: ';' missing
896 3 (21,2) warning: variable 'z' not defined
897 4 (67,3) error: end of file found before string ended
898 5
899 6 [a2.tt]
900 7
901 8 [a3.tt]
902 9 NEW compiler v1.1
903 10 (2,2) warning: variable 'x' not defined
904 11 (67,3) warning: 's' already defined
905
906This logfile lists several messages for each file enclosed in [...] which are
907properly parsed by an error format like this: >
908 :set efm=%+P[%f],(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%-Q
909
910A call of |:clist| writes them accordingly with their correct filenames:
911
912 2 a1.tt:1 col 17 error: ';' missing
913 3 a1.tt:21 col 2 warning: variable 'z' not defined
914 4 a1.tt:67 col 3 error: end of file found before string ended
915 8 a3.tt:2 col 2 warning: variable 'x' not defined
916 9 a3.tt:67 col 3 warning: 's' already defined
917
918Unlike the other prefixes that all match against whole lines, %P, %Q and %O
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000919can be used to match several patterns in the same line. Thus it is possible
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920to parse even nested files like in the following line:
921 {"file1" {"file2" error1} error2 {"file3" error3 {"file4" error4 error5}}}
922The %O then parses over strings that do not contain any push/pop file name
923information. See |errorformat-LaTeX| for an extended example.
924
925
926Ignoring and using whole messages *efm-ignore*
927
928The codes '+' or '-' can be combined with the uppercase codes above; in that
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000929case they have to precede the letter, e.g. '%+A' or '%-G':
Bram Moolenaar071d4272004-06-13 20:20:40 +0000930 %- do not include the matching multi-line in any output
931 %+ include the whole matching line in the %m error string
932
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000933One prefix is only useful in combination with '+' or '-', namely %G. It parses
Bram Moolenaar071d4272004-06-13 20:20:40 +0000934over lines containing general information like compiler version strings or
935other headers that can be skipped.
936 %-G ignore this message
937 %+G general message
938
939
940Pattern matching
941
942The scanf()-like "%*[]" notation is supported for backward-compatibility
943with previous versions of Vim. However, it is also possible to specify
944(nearly) any Vim supported regular expression in format strings.
945Since meta characters of the regular expression language can be part of
946ordinary matching strings or file names (and therefore internally have to
947be escaped), meta symbols have to be written with leading '%':
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000948 %\ the single '\' character. Note that this has to be
Bram Moolenaar071d4272004-06-13 20:20:40 +0000949 escaped ("%\\") in ":set errorformat=" definitions.
950 %. the single '.' character.
951 %# the single '*'(!) character.
952 %^ the single '^' character.
953 %$ the single '$' character.
954 %[ the single '[' character for a [] character range.
955 %~ the single '~' character.
956When using character classes in expressions (see |/\i| for an overview),
957terms containing the "\+" quantifier can be written in the scanf() "%*"
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000958notation. Example: "%\\d%\\+" ("\d\+", "any number") is equivalent to "%*\\d".
Bram Moolenaar071d4272004-06-13 20:20:40 +0000959Important note: The \(...\) grouping of sub-matches can not be used in format
960specifications because it is reserved for internal conversions.
961
962
963Multiple entries in 'errorformat' *efm-entries*
964
965To be able to detect output from several compilers, several format patterns
966may be put in 'errorformat', separated by commas (note: blanks after the comma
967are ignored). The first pattern that has a complete match is used. If no
968match is found, matching parts from the last one will be used, although the
969file name is removed and the error message is set to the whole message. If
970there is a pattern that may match output from several compilers (but not in a
971right way), put it after one that is more restrictive.
972
973To include a comma in a pattern precede it with a backslash (you have to type
974two in a ":set" command). To include a backslash itself give two backslashes
975(you have to type four in a ":set" command). You also need to put a backslash
976before a space for ":set".
977
978
979Valid matches *quickfix-valid*
980
981If a line does not completely match one of the entries in 'errorformat', the
982whole line is put in the error message and the entry is marked "not valid"
983These lines are skipped with the ":cn" and ":cp" commands (unless there is
984no valid line at all). You can use ":cl!" to display all the error messages.
985
986If the error format does not contain a file name Vim cannot switch to the
987correct file. You will have to do this by hand.
988
989
990Examples
991
992The format of the file from the Amiga Aztec compiler is:
993
994 filename>linenumber:columnnumber:errortype:errornumber:errormessage
995
996 filename name of the file in which the error was detected
997 linenumber line number where the error was detected
998 columnnumber column number where the error was detected
999 errortype type of the error, normally a single 'E' or 'W'
1000 errornumber number of the error (for lookup in the manual)
1001 errormessage description of the error
1002
1003This can be matched with this 'errorformat' entry:
1004 %f>%l:%c:%t:%n:%m
1005
1006Some examples for C compilers that produce single-line error outputs:
1007%f:%l:\ %t%*[^0123456789]%n:\ %m for Manx/Aztec C error messages
1008 (scanf() doesn't understand [0-9])
1009%f\ %l\ %t%*[^0-9]%n:\ %m for SAS C
1010\"%f\"\\,%*[^0-9]%l:\ %m for generic C compilers
1011%f:%l:\ %m for GCC
1012%f:%l:\ %m,%Dgmake[%*\\d]:\ Entering\ directory\ `%f',
1013%Dgmake[%*\\d]:\ Leaving\ directory\ `%f'
1014 for GCC with gmake (concat the lines!)
1015%f(%l)\ :\ %*[^:]:\ %m old SCO C compiler (pre-OS5)
1016%f(%l)\ :\ %t%*[^0-9]%n:\ %m idem, with error type and number
1017%f:%l:\ %m,In\ file\ included\ from\ %f:%l:,\^I\^Ifrom\ %f:%l%m
1018 for GCC, with some extras
1019
1020Extended examples for the handling of multi-line messages are given below,
1021see |errorformat-Jikes| and |errorformat-LaTeX|.
1022
1023Note the backslash in front of a space and double quote. It is required for
1024the :set command. There are two backslashes in front of a comma, one for the
1025:set command and one to avoid recognizing the comma as a separator of error
1026formats.
1027
1028
1029Filtering messages
1030
1031If you have a compiler that produces error messages that do not fit in the
1032format string, you could write a program that translates the error messages
1033into this format. You can use this program with the ":make" command by
1034changing the 'makeprg' option. For example: >
1035 :set mp=make\ \\\|&\ error_filter
1036The backslashes before the pipe character are required to avoid it to be
1037recognized as a command separator. The backslash before each space is
1038required for the set command.
1039
1040=============================================================================
10418. The directory stack *quickfix-directory-stack*
1042
1043Quickfix maintains a stack for saving all used directories parsed from the
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001044make output. For GNU-make this is rather simple, as it always prints the
1045absolute path of all directories it enters and leaves. Regardless if this is
Bram Moolenaar071d4272004-06-13 20:20:40 +00001046done via a 'cd' command in the makefile or with the parameter "-C dir" (change
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001047to directory before reading the makefile). It may be useful to use the switch
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048"-w" to force GNU-make to print out the working directory before and after
1049processing.
1050
1051Maintaining the correct directory is more complicated if you don't use
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001052GNU-make. AIX-make for example doesn't print any information about its
1053working directory. Then you need to enhance the makefile. In the makefile of
1054LessTif there is a command which echoes "Making {target} in {dir}". The
1055special problem here is that it doesn't print informations on leaving the
1056directory and that it doesn't print the absolute path.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057
1058To solve the problem with relative paths and missing "leave directory"
1059messages Vim uses following algorithm:
1060
10611) Check if the given directory is a subdirectory of the current directory.
1062 If this is true, store it as the current directory.
10632) If it is not a subdir of the current directory, try if this is a
1064 subdirectory of one of the upper directories.
10653) If the directory still isn't found, it is assumed to be a subdirectory
1066 of Vim's current directory.
1067
1068Additionally it is checked for every file, if it really exists in the
1069identified directory. If not, it is searched in all other directories of the
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001070directory stack (NOT the directory subtree!). If it is still not found, it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071assumed that it is in Vim's current directory.
1072
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001073There are limitation in this algorithm. This examples assume that make just
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074prints information about entering a directory in the form "Making all in dir".
1075
10761) Assume you have following directories and files:
1077 ./dir1
1078 ./dir1/file1.c
1079 ./file1.c
1080
1081 If make processes the directory "./dir1" before the current directory and
1082 there is an error in the file "./file1.c", you will end up with the file
1083 "./dir1/file.c" loaded by Vim.
1084
1085 This can only be solved with a "leave directory" message.
1086
10872) Assume you have following directories and files:
1088 ./dir1
1089 ./dir1/dir2
1090 ./dir2
1091
1092 You get the following:
1093
1094 Make output Directory interpreted by Vim
1095 ------------------------ ----------------------------
1096 Making all in dir1 ./dir1
1097 Making all in dir2 ./dir1/dir2
1098 Making all in dir2 ./dir1/dir2
1099
1100 This can be solved by printing absolute directories in the "enter directory"
1101 message or by printing "leave directory" messages..
1102
1103To avoid this problems, ensure to print absolute directory names and "leave
1104directory" messages.
1105
1106Examples for Makefiles:
1107
1108Unix:
1109 libs:
1110 for dn in $(LIBDIRS); do \
1111 (cd $$dn; echo "Entering dir '$$(pwd)'"; make); \
1112 echo "Leaving dir"; \
1113 done
1114
1115Add
1116 %DEntering\ dir\ '%f',%XLeaving\ dir
1117to your 'errorformat' to handle the above output.
1118
1119Note that Vim doesn't check if the directory name in a "leave directory"
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001120messages is the current directory. This is why you could just use the message
Bram Moolenaar071d4272004-06-13 20:20:40 +00001121"Leaving dir".
1122
1123=============================================================================
11249. Specific error file formats *errorformats*
1125
1126 *errorformat-Jikes*
1127Jikes(TM), a source-to-bytecode Java compiler published by IBM Research,
1128produces simple multi-line error messages.
1129
1130An 'errorformat' string matching the produced messages is shown below.
1131The following lines can be placed in the user's |vimrc| to overwrite Vim's
1132recognized default formats, or see |:set+=| how to install this format
1133additionally to the default. >
1134
1135 :set efm=%A%f:%l:%c:%*\\d:%*\\d:,
1136 \%C%*\\s%trror:%m,
1137 \%+C%*[^:]%trror:%m,
1138 \%C%*\\s%tarning:%m,
1139 \%C%m
1140<
1141Jikes(TM) produces a single-line error message when invoked with the option
1142"+E", and can be matched with the following: >
1143
1144 :set efm=%f:%l:%v:%*\\d:%*\\d:%*\\s%m
1145<
1146 *errorformat-javac*
1147This 'errorformat' has been reported to work well for javac, which outputs a
1148line with "^" to indicate the column of the error: >
1149 :set efm=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
1150or: >
1151 :set efm=%A%f:%l:\ %m,%+Z%p^,%+C%.%#,%-G%.%#
1152<
1153 *errorformat-ant*
1154For ant (http://jakarta.apache.org/) the above errorformat has to be modified
1155to honour the leading [javac] in front of each javac output line: >
1156 :set efm=%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
1157
1158The 'errorformat' can also be configured to handle ant together with either
1159javac or jikes. If you're using jikes, you should tell ant to use jikes' +E
1160command line switch which forces jikes to generate one-line error messages.
1161This is what the second line (of a build.xml file) below does: >
1162 <property name = "build.compiler" value = "jikes"/>
1163 <property name = "build.compiler.emacs" value = "true"/>
1164
1165The 'errorformat' which handles ant with both javac and jikes is: >
1166 :set efm=\ %#[javac]\ %#%f:%l:%c:%*\\d:%*\\d:\ %t%[%^:]%#:%m,
1167 \%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
1168<
1169 *errorformat-jade*
1170parsing jade (see http://www.jclark.com/) errors is simple: >
1171 :set efm=jade:%f:%l:%c:%t:%m
1172<
1173 *errorformat-LaTeX*
1174The following is an example how an 'errorformat' string can be specified
1175for the (La)TeX typesetting system which displays error messages over
1176multiple lines. The output of ":clist" and ":cc" etc. commands displays
1177multi-lines in a single line, leading white space is removed.
1178It should be easy to adopt the above LaTeX errorformat to any compiler output
1179consisting of multi-line errors.
1180
1181The commands can be placed in a |vimrc| file or some other Vim script file,
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001182e.g. a script containing LaTeX related stuff which is loaded only when editing
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183LaTeX sources.
1184Make sure to copy all lines of the example (in the given order), afterwards
1185remove the comment lines. For the '\' notation at the start of some lines see
1186|line-continuation|.
1187
1188 First prepare 'makeprg' such that LaTeX will report multiple
1189 errors; do not stop when the first error has occurred: >
1190 :set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}
1191<
1192 Start of multi-line error messages: >
1193 :set efm=%E!\ LaTeX\ %trror:\ %m,
1194 \%E!\ %m,
1195< Start of multi-line warning messages; the first two also
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001196 include the line number. Meaning of some regular expressions:
Bram Moolenaar071d4272004-06-13 20:20:40 +00001197 - "%.%#" (".*") matches a (possibly empty) string
1198 - "%*\\d" ("\d\+") matches a number >
1199 \%+WLaTeX\ %.%#Warning:\ %.%#line\ %l%.%#,
1200 \%+W%.%#\ at\ lines\ %l--%*\\d,
1201 \%WLaTeX\ %.%#Warning:\ %m,
1202< Possible continuations of error/warning messages; the first
1203 one also includes the line number: >
1204 \%Cl.%l\ %m,
1205 \%+C\ \ %m.,
1206 \%+C%.%#-%.%#,
1207 \%+C%.%#[]%.%#,
1208 \%+C[]%.%#,
1209 \%+C%.%#%[{}\\]%.%#,
1210 \%+C<%.%#>%.%#,
1211 \%C\ \ %m,
1212< Lines that match the following patterns do not contain any
1213 important information; do not include them in messages: >
1214 \%-GSee\ the\ LaTeX%m,
1215 \%-GType\ \ H\ <return>%m,
1216 \%-G\ ...%.%#,
1217 \%-G%.%#\ (C)\ %.%#,
1218 \%-G(see\ the\ transcript%.%#),
1219< Generally exclude any empty or whitespace-only line from
1220 being displayed: >
1221 \%-G\\s%#,
1222< The LaTeX output log does not specify the names of erroneous
1223 source files per line; rather they are given globally,
1224 enclosed in parentheses.
1225 The following patterns try to match these names and store
1226 them in an internal stack. The patterns possibly scan over
1227 the same input line (one after another), the trailing "%r"
1228 conversion indicates the "rest" of the line that will be
1229 parsed in the next go until the end of line is reached.
1230
1231 Overread a file name enclosed in '('...')'; do not push it
1232 on a stack since the file apparently does not contain any
1233 error: >
1234 \%+O(%f)%r,
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +00001235< Push a file name onto the stack. The name is given after '(': >
Bram Moolenaar071d4272004-06-13 20:20:40 +00001236 \%+P(%f%r,
1237 \%+P\ %\\=(%f%r,
1238 \%+P%*[^()](%f%r,
1239 \%+P[%\\d%[^()]%#(%f%r,
1240< Pop the last stored file name when a ')' is scanned: >
1241 \%+Q)%r,
1242 \%+Q%*[^()])%r,
1243 \%+Q[%\\d%*[^()])%r
1244
1245Note that in some cases file names in the LaTeX output log cannot be parsed
1246properly. The parser might have been messed up by unbalanced parentheses
1247then. The above example tries to catch the most relevant cases only.
1248You can customize the given setting to suit your own purposes, for example,
1249all the annoying "Overfull ..." warnings could be excluded from being
1250recognized as an error.
1251Alternatively to filtering the LaTeX compiler output, it is also possible
1252to directly read the *.log file that is produced by the [La]TeX compiler.
1253This contains even more useful information about possible error causes.
1254However, to properly parse such a complex file, an external filter should
1255be used. See the description further above how to make such a filter known
1256by Vim.
1257
1258 *errorformat-Perl*
1259In $VIMRUNTIME/tools you can find the efm_perl.pl script, which filters Perl
1260error messages into a format that quickfix mode will understand. See the
1261start of the file about how to use it.
1262
1263
1264
1265 vim:tw=78:ts=8:ft=help:norl: