blob: f9a56af8985d9cc7ba00ce378654a5991cf2e2f8 [file] [log] [blame]
Bram Moolenaar05159a02005-02-26 23:04:13 +00001*quickfix.txt* For Vim version 7.0aa. Last change: 2005 Feb 24
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
35use the positions in a script with the |errorlist()| function. Thus you can
36do 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
45The following quickfix commands can be used:
46
47 *:cc*
48:cc[!] [nr] Display error [nr]. If [nr] is omitted, the same
49 error is displayed again. Without [!] this doesn't
50 work when jumping to another buffer, the current buffer
51 has been changed, there is the only window for the
52 buffer and both 'hidden' and 'autowrite' are off.
53 When jumping to another buffer with [!] any changes to
54 the current buffer are lost, unless 'hidden' is set or
55 there is another window for this buffer.
56 The 'switchbuf' settings are respected when jumping
57 to a buffer.
58
59 *:cn* *:cnext* *E553*
60:[count]cn[ext][!] Display the [count] next error in the list that
61 includes a file name. If there are no file names at
62 all, go to the [count] next error. See |:cc| for
63 [!] and 'switchbuf'.
64
65:[count]cN[ext][!] *:cp* *:cprevious* *:cN* *:cNext*
66:[count]cp[revious][!] Display the [count] previous error in the list that
67 includes a file name. If there are no file names at
68 all, go to the [count] previous error. See |:cc| for
69 [!] and 'switchbuf'.
70
71 *:cnf* *:cnfile*
72:[count]cnf[ile][!] Display the first error in the [count] next file in
73 the list that includes a file name. If there are no
74 file names at all or if there is no next file, go to
75 the [count] next error. See |:cc| for [!] and
76 'switchbuf'.
77
78:[count]cNf[ile][!] *:cpf* *:cpfile* *:cNf* *:cNfile*
79:[count]cpf[ile][!] Display the last error in the [count] previous file in
80 the list that includes a file name. If there are no
81 file names at all or if there is no next file, go to
82 the [count] previous error. See |:cc| for [!] and
83 'switchbuf'.
84
85 *:crewind* *:cr*
86:cr[ewind][!] [nr] Display error [nr]. If [nr] is omitted, the FIRST
87 error is displayed. See |:cc|.
88
89 *:cfirst* *:cfir*
90:cfir[st][!] [nr] Same as ":crewind".
91
92 *:clast* *:cla*
93:cla[st][!] [nr] Display error [nr]. If [nr] is omitted, the LAST
94 error is displayed. See |:cc|.
95
96 *:cq* *:cquit*
97:cq[uit] Quit Vim with an error code, so that the compiler
98 will not compile the same file again.
99
100 *:cf* *:cfile*
101:cf[ile][!] [errorfile] Read the error file and jump to the first error.
102 This is done automatically when Vim is started with
103 the -q option. You can use this command when you
104 keep Vim running while compiling. If you give the
105 name of the errorfile, the 'errorfile' option will
106 be set to [errorfile]. See |:cc| for [!].
107
108 *:cg* *:cgetfile*
109:cg[etfile][!] [errorfile]
110 Read the error file. Just like ":cfile" but don't
111 jump to the first error.
112
Bram Moolenaar86b68352004-12-27 21:59:20 +0000113 *:cb* *:cbuffer* *E681*
114:cb[uffer] [bufnr] Read the error list from the current buffer.
115 When [bufnr] is given it must be the number of a
116 loaded buffer. That buffer will then be used instead
117 of the current buffer.
118 A range can be specified for the lines to be used.
119 Otherwise all lines in the buffer are used.
120
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121 *:cl* *:clist*
122:cl[ist] [from] [, [to]]
123 List all errors that are valid |quickfix-valid|.
124 If numbers [from] and/or [to] are given, the respective
125 range of errors is listed. A negative number counts
126 from the last error backwards, -1 being the last error.
127 The 'switchbuf' settings are respected when jumping
128 to a buffer.
129
130:cl[ist]! [from] [, [to]]
131 List all errors.
132
133If you insert or delete lines, mostly the correct error location is still
134found because hidden marks are used. Sometimes, when the mark has been
135deleted for some reason, the message "line changed" is shown to warn you that
136the error location may not be correct. If you quit Vim and start again the
137marks are lost and the error locations may not be correct anymore.
138
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000139If vim is built with |+autocmd| support, two autocommands are available for
140running commands before and after a quickfix command (':make', ':grep' and so
141on) is executed. See |QuickFixCmdPre| and |QuickFixCmdPost| for details.
142
Bram Moolenaar071d4272004-06-13 20:20:40 +0000143=============================================================================
1442. The error window *quickfix-window*
145
146 *:cope* *:copen*
147:cope[n] [height] Open a window to show the current list of errors.
148 When [height] is given, the window becomes that high
149 (if there is room). Otherwise the window is made ten
150 lines high.
151 The window will contain a special buffer, with
152 'buftype' equal to "quickfix". Don't change this!
153 If there already is a quickfix window, it will be made
154 the current window. It is not possible to open a
155 second quickfix window.
156
157 *:ccl* *:cclose*
158:ccl[ose] Close the quickfix window.
159
160 *:cw* *:cwindow*
161:cw[indow] [height] Open the quickfix window when there are recognized
162 errors. If the window is already open and there are
163 no recognized errors, close the window.
164
165
166Normally the quickfix window is at the bottom of the screen. If there are
167vertical splits, it's at the bottom of the rightmost column of windows. To
168make it always occupy the full width: >
169 :botright cwindow
170You can move the window around with |window-moving| commands.
171For example, to move it to the top: CTRL-W K
172The 'winfixheight' option will be set, which means that the window will mostly
173keep its height, ignoring 'winheight' and 'equalalways'. You can change the
174height manually (e.g., by dragging the status line above it with the mouse).
175
176In the quickfix window, each line is one error. The line number is equal to
177the error number. You can use ":.cc" to jump to the error under the cursor.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000178Hitting the <Enter> key or double-clicking the mouse on a line has the same
Bram Moolenaar071d4272004-06-13 20:20:40 +0000179effect. The file containing the error is opened in the window above the
180quickfix window. If there already is a window for that file, it is used
181instead. If the buffer in the used window has changed, and the error is in
182another file, jumping to the error will fail. You will first have to make
183sure the window contains a buffer which can be abandoned.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000184 *CTRL-W_<Enter>* *CTRL-W_<CR>*
185You can use CTRL-W <Enter> to open a new window and jump to the error there.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000186
187When the quickfix window has been filled, two autocommand events are
188triggered. First the 'filetype' option is set to "qf", which triggers the
189FileType event. Then the BufReadPost event is triggered. This can be used to
190perform some action on the listed errors. Example: >
191 au BufReadPost quickfix setlocal nomodifiable
192 \ | silent g/^/s//\=line(".")." "/
193 \ | setlocal modifiable
194This prepends the line number to each line. Note the use of "\=" in the
195substitute string of the ":s" command, which is used to evaluate an
196expression.
197
198Note: Making changes in the quickfix window has no effect on the list of
199errors. 'modifiable' is off to avoid making changes. If you delete or insert
200lines anyway, the relation between the text and the error number is messed up.
201If you really want to do this, you could write the contents of the quickfix
202window to a file and use ":cfile" to have it parsed and used as the new error
203list.
204
205=============================================================================
2063. Using more than one list of errors *quickfix-error-lists*
207
208So far has been assumed that there is only one list of errors. Actually the
209ten last used lists are remembered. When starting a new list, the previous
210ones are automatically kept. Two commands can be used to access older error
211lists. They set one of the existing error lists as the current one.
212
213 *:colder* *:col* *E380*
214:col[der] [count] Go to older error list. When [count] is given, do
215 this [count] times. When already at the oldest error
216 list, an error message is given.
217
218 *:cnewer* *:cnew* *E381*
219:cnew[er] [count] Go to newer error list. When [count] is given, do
220 this [count] times. When already at the newest error
221 list, an error message is given.
222
223When adding a new error list, it becomes the current list.
224
225When ":colder" has been used and ":make" or ":grep" is used to add a new error
226list, one newer list is overwritten. This is especially useful if you are
227browsing with ":grep" |grep|. If you want to keep the more recent error
228lists, use ":cnewer 99" first.
229
230=============================================================================
2314. Using :make *:make_makeprg*
232
233 *:mak* *:make*
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000234:mak[e][!] [arguments] 1. If vim was built with |+autocmd|, all relevant
235 |QuickFixCmdPre| autocommands are executed.
236 2. If the 'autowrite' option is on, write any changed
Bram Moolenaar071d4272004-06-13 20:20:40 +0000237 buffers
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000238 3. An errorfile name is made from 'makeef'. If
Bram Moolenaar071d4272004-06-13 20:20:40 +0000239 'makeef' doesn't contain "##", and a file with this
240 name already exists, it is deleted.
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000241 4. The program given with the 'makeprg' option is
Bram Moolenaar071d4272004-06-13 20:20:40 +0000242 started (default "make") with the optional
243 [arguments] and the output is saved in the
244 errorfile (for Unix it is also echoed on the
245 screen).
Bram Moolenaarb11bd7e2005-02-07 22:05:52 +0000246 5. The errorfile is read using 'errorformat'.
247 6. If [!] is not given the first error is jumped to.
248 7. The errorfile is deleted.
249 8. If vim was built with |+autocmd|, all relevant
250 |QuickFixCmdPost| autocommands are executed.
251 9. You can now move through the errors with commands
Bram Moolenaar071d4272004-06-13 20:20:40 +0000252 like |:cnext| and |:cprevious|, see above.
253 This command does not accept a comment, any "
254 characters are considered part of the arguments.
255
256The ":make" command executes the command given with the 'makeprg' option.
257This is done by passing the command to the shell given with the 'shell'
258option. This works almost like typing
259
260 ":!{makeprg} [arguments] {shellpipe} {errorfile}".
261
262{makeprg} is the string given with the 'makeprg' option. Any command can be
263used, not just "make". Characters '%' and '#' are expanded as usual on a
264command-line. You can use "%<" to insert the current file name without
265extension, or "#<" to insert the alternate file name without extension, for
266example: >
267 :set makeprg=make\ #<.o
268
269[arguments] is anything that is typed after ":make".
270{shellpipe} is the 'shellpipe' option.
271{errorfile} is the 'makeef' option, with ## replaced to make it unique.
272
273The placeholder "$*" can be used for the argument list in {makeprog} if the
274command needs some additional characters after its arguments. The $* is
275replaced then by all arguments. Example: >
276 :set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}
277or simpler >
278 :let &mp = 'latex \\nonstopmode \\input\{$*}'
279"$*" can be given multiple times, for example: >
280 :set makeprg=gcc\ -o\ $*\ $*
281
282The 'shellpipe' option defaults to ">" for the Amiga, MS-DOS and Win32. This
283means that the output of the compiler is saved in a file and not shown on the
284screen directly. For Unix "| tee" is used. The compiler output is shown on
285the screen and saved in a file the same time. Depending on the shell used
286"|& tee" or "2>&1| tee" is the default, so stderr output will be included.
287
288If 'shellpipe' is empty, the {errorfile} part will be omitted. This is useful
289for compilers that write to an errorfile themselves (e.g., Manx's Amiga C).
290
291==============================================================================
Bram Moolenaar86b68352004-12-27 21:59:20 +00002925. Using :vimgrep and :grep *grep* *lid*
293
294Vim has two ways to find matches for a pattern: Internal and external. The
295advantage of the internal grep is that it works on all systems and uses the
296powerful Vim search patterns. An external grep program can be used when the
297Vim grep does not do what you want.
298
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000299The internal method will be slower, because files are read into memory. The
300advantages are:
301- Line separators and encoding are automatically recognized, as if a file is
302 being edited.
303- Uses Vim search patterns. Multi-line patterns can be used.
304- When plugins are enabled: compressed and remote files can be searched.
305 |gzip| |netrw|
Bram Moolenaardcaf10e2005-01-21 11:55:25 +0000306- When 'hidden' is set the files are kept loaded, thus repeating a search is
307 much faster. Uses a lot of memory though!
Bram Moolenaar86b68352004-12-27 21:59:20 +0000308
309
3105.1 using Vim's internal grep
311
Bram Moolenaare49b69a2005-01-08 16:11:57 +0000312 *:vim* *:vimgrep* *E682* *E683*
Bram Moolenaar05159a02005-02-26 23:04:13 +0000313:vim[grep][!] /{pattern}/[g][j] {file} ...
Bram Moolenaar86b68352004-12-27 21:59:20 +0000314 Search for {pattern} in the files {file} ... and set
315 the error list to the matches.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000316 Without the 'g' flag each line is added only once.
317 With 'g' every match is added.
318
319 {pattern} is a Vim search pattern. Instead of
320 enclosing it in / any non-ID character (see
321 |'isident'|) can be used, so long as it does not
322 appear in {pattern}.
323 'ignorecase' applies. To overrule it put |/\c| in the
324 pattern to ignore case or |/\C| to match case.
325 'smartcase' is not used.
326
327 Without the 'j' flag Vim jumps to the first match.
328 With 'j' only the quickfix list is updated.
329 With the [!] any changes in the current buffer are
330 abandoned.
331
Bram Moolenaardcaf10e2005-01-21 11:55:25 +0000332 Every second or so the searched file name is displayed
333 to give you an idea of the progress made.
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000334 Examples: >
335 :vimgrep /an error/ *.c
336 :vimgrep /\<FileName\>/ *.h include/*
Bram Moolenaar86b68352004-12-27 21:59:20 +0000337
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000338:vim[grep][!] {pattern} {file} ...
339 Like above, but instead of enclosing the pattern in a
340 non-ID character use a white-separated pattern. The
341 pattern must start with an ID character.
342 Example: >
343 :vimgrep Error *.c
344<
Bram Moolenaar86b68352004-12-27 21:59:20 +0000345 *:vimgrepa* *:vimgrepadd*
Bram Moolenaar05159a02005-02-26 23:04:13 +0000346:vimgrepa[dd][!] /{pattern}/[g][j] {file} ...
347:vimgrepa[dd][!] {pattern} {file} ...
Bram Moolenaar86b68352004-12-27 21:59:20 +0000348 Just like ":vimgrep", but instead of making a new list
349 of errors the matches are appended to the current
350 list.
351
352
3535.2 External grep
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354
355Vim can interface with "grep" and grep-like programs (such as the GNU
356id-utils) in a similar way to its compiler integration (see |:make| above).
357
358[Unix trivia: The name for the Unix "grep" command comes from ":g/re/p", where
359"re" stands for Regular Expression.]
360
361 *:gr* *:grep*
362:gr[ep][!] [arguments] Just like ":make", but use 'grepprg' instead of
363 'makeprg' and 'grepformat' instead of 'errorformat'.
Bram Moolenaar86b68352004-12-27 21:59:20 +0000364 When 'grepprg' is "internal" this works like
365 |:vimgrep|. Note that the pattern needs to be
366 enclosed in separator characters then.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000367 *:grepa* *:grepadd*
368:grepa[dd][!] [arguments]
369 Just like ":grep", but instead of making a new list of
370 errors the matches are appended to the current list.
371 Example: >
372 :grep nothing %
373 :bufdo grepadd! something %
374< The first command makes a new error list which is
375 empty. The second command executes "grepadd" for each
376 listed buffer. Note the use of ! to avoid that
377 ":grepadd" jumps to the first error, which is not
378 allowed with |:bufdo|.
379
Bram Moolenaar86b68352004-12-27 21:59:20 +00003805.3 Setting up external grep
Bram Moolenaar071d4272004-06-13 20:20:40 +0000381
382If you have a standard "grep" program installed, the :grep command may work
383well with the defaults. The syntax is very similar to the standard command: >
384
385 :grep foo *.c
386
387Will search all files with the .c extension for the substring "foo". The
388arguments to :grep are passed straight to the "grep" program, so you can use
389whatever options your "grep" supports.
390
391By default, :grep invokes grep with the -n option (show file and line
392numbers). You can change this with the 'grepprg' option. You will need to set
393'grepprg' if:
394
395a) You are using a program that isn't called "grep"
396b) You have to call grep with a full path
397c) You want to pass other options automatically (e.g. case insensitive
398 search.)
399
400Once "grep" has executed, Vim parses the results using the 'grepformat'
401option. This option works in the same way as the 'errorformat' option - see
402that for details. You may need to change 'grepformat' from the default if
403your grep outputs in a non-standard format, or you are using some other
404program with a special format.
405
406Once the results are parsed, Vim loads the first file containing a match and
407jumps to the appropriate line, in the same way that it jumps to a compiler
408error in |quickfix| mode. You can then use the |:cnext|, |:clist|, etc.
409commands to see the other matches.
410
411
Bram Moolenaar86b68352004-12-27 21:59:20 +00004125.4 Using :grep with id-utils
Bram Moolenaar071d4272004-06-13 20:20:40 +0000413
414You can set up :grep to work with the GNU id-utils like this: >
415
416 :set grepprg=lid\ -Rgrep\ -s
417 :set grepformat=%f:%l:%m
418
419then >
420 :grep (regexp)
421
422works just as you'd expect.
423(provided you remembered to mkid first :)
424
425
Bram Moolenaar86b68352004-12-27 21:59:20 +00004265.5 Browsing source code with :vimgrep or :grep
Bram Moolenaar071d4272004-06-13 20:20:40 +0000427
428Using the stack of error lists that Vim keeps, you can browse your files to
429look for functions and the functions they call. For example, suppose that you
430have to add an argument to the read_file() function. You enter this command: >
431
Bram Moolenaar86b68352004-12-27 21:59:20 +0000432 :vimgrep /\<read_file\>/ *.c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000433
434You use ":cn" to go along the list of matches and add the argument. At one
435place you have to get the new argument from a higher level function msg(), and
436need to change that one too. Thus you use: >
437
Bram Moolenaar86b68352004-12-27 21:59:20 +0000438 :vimgrep /\<msg\>/ *.c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000439
440While changing the msg() functions, you find another function that needs to
Bram Moolenaar86b68352004-12-27 21:59:20 +0000441get the argument from a higher level. You can again use ":vimgrep" to find
442these functions. Once you are finished with one function, you can use >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000443
444 :colder
445
446to go back to the previous one.
447
Bram Moolenaar86b68352004-12-27 21:59:20 +0000448This works like browsing a tree: ":vimgrep" goes one level deeper, creating a
Bram Moolenaar071d4272004-06-13 20:20:40 +0000449list of branches. ":colder" goes back to the previous level. You can mix
Bram Moolenaar86b68352004-12-27 21:59:20 +0000450this use of ":vimgrep" and "colder" to browse all the locations in a tree-like
Bram Moolenaar071d4272004-06-13 20:20:40 +0000451way. If you do this consistently, you will find all locations without the
452need to write down a "todo" list.
453
454=============================================================================
4556. Selecting a compiler *compiler-select*
456
457 *:comp* *:compiler* *E666*
458:comp[iler][!] {name} Set options to work with compiler {name}.
459 Without the "!" options are set for the
460 current buffer. With "!" global options are
461 set.
462 If you use ":compiler foo" in "file.foo" and
463 then ":compiler! bar" in another buffer, Vim
464 will keep on using "foo" in "file.foo".
465 {not available when compiled without the
466 |+eval| feature}
467
468
469The Vim plugins in the "compiler" directory will set options to use the
470selected compiler. For ":compiler" local options are set, for ":compiler!"
471global options.
472 *current_compiler*
473To support older Vim versions, the plugins always use "current_compiler" and
474not "b:current_compiler". What the command actually does is the following:
475
476- Delete the "current_compiler" and "b:current_compiler" variables.
477- Define the "CompilerSet" user command. With "!" it does ":set", without "!"
478 it does ":setlocal".
479- Execute ":runtime! compiler/{name}.vim". The plugins are expected to set
480 options with "CompilerSet" and set the "current_compiler" variable to the
481 name of the compiler.
Bram Moolenaar05159a02005-02-26 23:04:13 +0000482- Delete the "CompilerSet" user command.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000483- Set "b:current_compiler" to the value of "current_compiler".
484- Without "!" the old value of "current_compiler" is restored.
485
486
487For writing a compiler plugin, see |write-compiler-plugin|.
488
489
490MANX AZTEC C *quickfix-manx* *compiler-manx*
491
492To use Vim with Manx's Aztec C compiler on the Amiga you should do the
493following:
494- Set the CCEDIT environment variable with the command: >
495 mset "CCEDIT=vim -q"
496- Compile with the -qf option. If the compiler finds any errors, Vim is
497 started and the cursor is positioned on the first error. The error message
498 will be displayed on the last line. You can go to other errors with the
499 commands mentioned above. You can fix the errors and write the file(s).
500- If you exit Vim normally the compiler will re-compile the same file. If you
501 exit with the :cq command, the compiler will terminate. Do this if you
502 cannot fix the error, or if another file needs to be compiled first.
503
504There are some restrictions to the Quickfix mode on the Amiga. The
505compiler only writes the first 25 errors to the errorfile (Manx's
506documentation does not say how to get more). If you want to find the others,
507you will have to fix a few errors and exit the editor. After recompiling,
508up to 25 remaining errors will be found.
509
510If Vim was started from the compiler, the :sh and some :! commands will not
511work, because Vim is then running in the same process as the compiler and
512stdin (standard input) will not be interactive.
513
514
515PYUNIT COMPILER *compiler-pyunit*
516
517This is not actually a compiler, but a unit testing framework for the
518Python language. It is included into standard Python distribution
519starting from version 2.0. For older versions, you can get it from
520http://pyunit.sourceforge.net.
521
522When you run your tests with the help of the framework, possible errors
523are parsed by Vim and presented for you in quick-fix mode.
524
525Unfortunately, there is no standard way to run the tests.
526The alltests.py script seems to be used quite often, that's all.
527Useful values for the 'makeprg' options therefore are:
528 setlocal makeprg=./alltests.py " Run a testsuite
529 setlocal makeprg=python % " Run a single testcase
530
531Also see http://vim.sourceforge.net/tip_view.php?tip_id=280.
532
533
534TEX COMPILER *compiler-tex*
535
536Included in the distribution compiler for TeX ($VIMRUNTIME/compiler/tex.vim)
537uses make command if possible. If the compiler finds a file named "Makefile"
538or "makefile" in the current directory, it supposes that you want to process
539your *TeX files with make, and the makefile does the right work. In this case
540compiler sets 'errorformat' for *TeX output and leaves 'makeprg' untouched. If
541neither "Makefile" nor "makefile" is found, the compiler will not use make.
542You can force the compiler to ignore makefiles by defining
543b:tex_ignore_makefile or g:tex_ignore_makefile variable (they are checked for
544existence only).
545
546If the compiler chose not to use make, it need to choose a right program for
547processing your input. If b:tex_flavor or g:tex_flavor (in this precedence)
548variable exists, it defines TeX flavor for :make (actually, this is the name
549of executed command), and if both variables do not exist, it defaults to
550"latex". For example, while editing chapter2.tex \input-ed from mypaper.tex
551written in AMS-TeX: >
552
553 :let b:tex_flavor = 'amstex'
554 :compiler tex
555< [editing...] >
556 :make mypaper
557
558Note that you must specify a name of the file to process as an argument (to
559process the right file when editing \input-ed or \include-ed file; portable
560solution for substituting % for no arguments is welcome). This is not in the
561semantics of make, where you specify a target, not source, but you may specify
562filename without extension ".tex" and mean this as "make filename.dvi or
563filename.pdf or filename.some_result_extension according to compiler".
564
565Note: tex command line syntax is set to usable both for MikTeX (suggestion
566by Srinath Avadhanula) and teTeX (checked by Artem Chuprina). Suggestion
567from |errorformat-LaTeX| is too complex to keep it working for different
568shells and OSes and also does not allow to use other available TeX options,
569if any. If your TeX doesn't support "-interaction=nonstopmode", please
570report it with different means to express \nonstopmode from the command line.
571
572=============================================================================
5737. The error format *error-file-format*
574
575 *errorformat* *E372* *E373* *E374*
576 *E375* *E376* *E377* *E378*
577The 'errorformat' option specifies a list of formats that are recognized. The
578first format that matches with an error message is used. You can add several
579formats for different messages your compiler produces, or even entries for
580multiple compilers. See |efm-entries|.
581
582Each entry in 'errorformat' is a scanf-like string that describes the format.
583First, you need to know how scanf works. Look in the documentation of your
584C compiler. Below you find the % items that Vim understands. Others are
585invalid.
586
587Special characters in 'errorformat' are comma and backslash. See
588|efm-entries| for how to deal with them. Note that a literal "%" is matched
589by "%%", thus it is not escaped with a backslash.
590
591Note: By default the difference between upper and lowercase is ignored. If
592you want to match case, add "\C" to the pattern |/\C|.
593
594
595Basic items
596
597 %f file name (finds a string)
598 %l line number (finds a number)
599 %c column number (finds a number representing character
600 column of the error, (1 <tab> == 1 character column))
601 %v virtual column number (finds a number representing
602 screen column of the error (1 <tab> == 8 screen
603 columns)
604 %t error type (finds a single character)
605 %n error number (finds a number)
606 %m error message (finds a string)
607 %r matches the "rest" of a single-line file message %O/P/Q
608 %p pointer line (finds a sequence of '-', '.' or ' ' and
609 uses the length for the column number)
610 %*{conv} any scanf non-assignable conversion
611 %% the single '%' character
612
613The "%f" conversion depends on the current 'isfname' setting.
614
615The "%f" and "%m" conversions have to detect the end of the string. They
616should be followed by a character that cannot be in the string. Everything
617up to that character is included in the string. But when the next character
618is a '%' or a backslash, "%f" will look for any 'isfname' character and "%m"
619finds anything. If the "%f" or "%m" is at the end, everything up to the end
620of the line is included.
621
622On MS-DOS, MS-Windows and OS/2 a leading "C:" will be included in "%f", even
623when using "%f:". This means that a file name which is a single alphabetical
624letter will not be detected.
625
626The "%p" conversion is normally followed by a "^". It's used for compilers
627that output a line like: >
628 ^
629or >
630 ---------^
631to indicate the column of the error. This is to be used in a multi-line error
632message. See |errorformat-javac| for a useful example.
633
634
635Changing directory
636
637The following uppercase conversion characters specify the type of special
638format strings. At most one of them may be given as a prefix at the begin
639of a single comma-separated format pattern.
640Some compilers produce messages that consist of directory names that have to
641be prepended to each file name read by %f (example: GNU make). The following
642codes can be used to scan these directory names; they will be stored in an
643internal directory stack. *E379*
644 %D "enter directory" format string; expects a following
645 %f that finds the directory name
646 %X "leave directory" format string; expects following %f
647
648When defining an "enter directory" or "leave directory" format, the "%D" or
649"%X" has to be given at the start of that substring. Vim tracks the directory
650changes and prepends the current directory to each erroneous file found with a
651relative path. See |quickfix-directory-stack| for details, tips and
652limitations.
653
654
655Multi-line messages *errorformat-multi-line*
656
657It is possible to read the output of programs that produce multi-line
658messages, ie. error strings that consume more than one line. Possible
659prefixes are:
660 %E start of a multi-line error message
661 %W start of a multi-line warning message
662 %I start of a multi-line informational message
663 %A start of a multi-line message (unspecified type)
664 %C continuation of a multi-line message
665 %Z end of a multi-line message
666These can be used with '+' and '-', see |efm-ignore| below.
667
668Example: Your compiler happens to write out errors in the following format
669(leading line numbers not being part of the actual output):
670
671 1 Error 275
672 2 line 42
673 3 column 3
674 4 ' ' expected after '--'
675
676The appropriate error format string has to look like this: >
677 :set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
678
679And the |:clist| error message generated for this error is:
680
681 1:42 col 3 error 275: ' ' expected after '--'
682
683Another example: Think of a Python interpreter that produces the following
684error message (line numbers are not part of the actual output):
685
686 1 ==============================================================
687 2 FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)
688 3 --------------------------------------------------------------
689 4 Traceback (most recent call last):
690 5 File "unittests/dbfacadeTest.py", line 89, in testFoo
691 6 self.assertEquals(34, dtid)
692 7 File "/usr/lib/python2.2/unittest.py", line 286, in
693 8 failUnlessEqual
694 9 raise self.failureException, \
695 10 AssertionError: 34 != 33
696 11
697 12 --------------------------------------------------------------
698 13 Ran 27 tests in 0.063s
699
700Say you want |:clist| write the relevant information of this message only,
701namely:
702 5 unittests/dbfacadeTest.py:89: AssertionError: 34 != 33
703
704Then the error format string could be defined as follows: >
705 :set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
706
707Note that the %C string is given before the %A here: since the expression
708' %.%#' (which stands for the regular expression ' .*') matches every line
709starting with a space, followed by any characters to the end of the line,
710it also hides line 7 which would trigger a separate error message otherwise.
711Error format strings are always parsed pattern by pattern until the first
712match occurs.
713
714
715Separate file name *errorformat-separate-filename*
716
717These prefixes are useful if the file name is given once and multiple messages
718follow that refer to this file name.
719 %O single-line file message: overread the matched part
720 %P single-line file message: push file %f onto the stack
721 %Q single-line file message: pop the last file from stack
722
723Example: Given a compiler that produces the following error logfile (without
724leading line numbers):
725
726 1 [a1.tt]
727 2 (1,17) error: ';' missing
728 3 (21,2) warning: variable 'z' not defined
729 4 (67,3) error: end of file found before string ended
730 5
731 6 [a2.tt]
732 7
733 8 [a3.tt]
734 9 NEW compiler v1.1
735 10 (2,2) warning: variable 'x' not defined
736 11 (67,3) warning: 's' already defined
737
738This logfile lists several messages for each file enclosed in [...] which are
739properly parsed by an error format like this: >
740 :set efm=%+P[%f],(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%-Q
741
742A call of |:clist| writes them accordingly with their correct filenames:
743
744 2 a1.tt:1 col 17 error: ';' missing
745 3 a1.tt:21 col 2 warning: variable 'z' not defined
746 4 a1.tt:67 col 3 error: end of file found before string ended
747 8 a3.tt:2 col 2 warning: variable 'x' not defined
748 9 a3.tt:67 col 3 warning: 's' already defined
749
750Unlike the other prefixes that all match against whole lines, %P, %Q and %O
751can be used to match several patterns in the same line. Thus it is possible
752to parse even nested files like in the following line:
753 {"file1" {"file2" error1} error2 {"file3" error3 {"file4" error4 error5}}}
754The %O then parses over strings that do not contain any push/pop file name
755information. See |errorformat-LaTeX| for an extended example.
756
757
758Ignoring and using whole messages *efm-ignore*
759
760The codes '+' or '-' can be combined with the uppercase codes above; in that
761case they have to precede the letter, eg. '%+A' or '%-G':
762 %- do not include the matching multi-line in any output
763 %+ include the whole matching line in the %m error string
764
765One prefix is only useful in combination with '+' or '-', namely %G. It parses
766over lines containing general information like compiler version strings or
767other headers that can be skipped.
768 %-G ignore this message
769 %+G general message
770
771
772Pattern matching
773
774The scanf()-like "%*[]" notation is supported for backward-compatibility
775with previous versions of Vim. However, it is also possible to specify
776(nearly) any Vim supported regular expression in format strings.
777Since meta characters of the regular expression language can be part of
778ordinary matching strings or file names (and therefore internally have to
779be escaped), meta symbols have to be written with leading '%':
780 %\ the single '\' character. Note that this has to be
781 escaped ("%\\") in ":set errorformat=" definitions.
782 %. the single '.' character.
783 %# the single '*'(!) character.
784 %^ the single '^' character.
785 %$ the single '$' character.
786 %[ the single '[' character for a [] character range.
787 %~ the single '~' character.
788When using character classes in expressions (see |/\i| for an overview),
789terms containing the "\+" quantifier can be written in the scanf() "%*"
790notation. Example: "%\\d%\\+" ("\d\+", "any number") is equivalent to "%*\\d".
791Important note: The \(...\) grouping of sub-matches can not be used in format
792specifications because it is reserved for internal conversions.
793
794
795Multiple entries in 'errorformat' *efm-entries*
796
797To be able to detect output from several compilers, several format patterns
798may be put in 'errorformat', separated by commas (note: blanks after the comma
799are ignored). The first pattern that has a complete match is used. If no
800match is found, matching parts from the last one will be used, although the
801file name is removed and the error message is set to the whole message. If
802there is a pattern that may match output from several compilers (but not in a
803right way), put it after one that is more restrictive.
804
805To include a comma in a pattern precede it with a backslash (you have to type
806two in a ":set" command). To include a backslash itself give two backslashes
807(you have to type four in a ":set" command). You also need to put a backslash
808before a space for ":set".
809
810
811Valid matches *quickfix-valid*
812
813If a line does not completely match one of the entries in 'errorformat', the
814whole line is put in the error message and the entry is marked "not valid"
815These lines are skipped with the ":cn" and ":cp" commands (unless there is
816no valid line at all). You can use ":cl!" to display all the error messages.
817
818If the error format does not contain a file name Vim cannot switch to the
819correct file. You will have to do this by hand.
820
821
822Examples
823
824The format of the file from the Amiga Aztec compiler is:
825
826 filename>linenumber:columnnumber:errortype:errornumber:errormessage
827
828 filename name of the file in which the error was detected
829 linenumber line number where the error was detected
830 columnnumber column number where the error was detected
831 errortype type of the error, normally a single 'E' or 'W'
832 errornumber number of the error (for lookup in the manual)
833 errormessage description of the error
834
835This can be matched with this 'errorformat' entry:
836 %f>%l:%c:%t:%n:%m
837
838Some examples for C compilers that produce single-line error outputs:
839%f:%l:\ %t%*[^0123456789]%n:\ %m for Manx/Aztec C error messages
840 (scanf() doesn't understand [0-9])
841%f\ %l\ %t%*[^0-9]%n:\ %m for SAS C
842\"%f\"\\,%*[^0-9]%l:\ %m for generic C compilers
843%f:%l:\ %m for GCC
844%f:%l:\ %m,%Dgmake[%*\\d]:\ Entering\ directory\ `%f',
845%Dgmake[%*\\d]:\ Leaving\ directory\ `%f'
846 for GCC with gmake (concat the lines!)
847%f(%l)\ :\ %*[^:]:\ %m old SCO C compiler (pre-OS5)
848%f(%l)\ :\ %t%*[^0-9]%n:\ %m idem, with error type and number
849%f:%l:\ %m,In\ file\ included\ from\ %f:%l:,\^I\^Ifrom\ %f:%l%m
850 for GCC, with some extras
851
852Extended examples for the handling of multi-line messages are given below,
853see |errorformat-Jikes| and |errorformat-LaTeX|.
854
855Note the backslash in front of a space and double quote. It is required for
856the :set command. There are two backslashes in front of a comma, one for the
857:set command and one to avoid recognizing the comma as a separator of error
858formats.
859
860
861Filtering messages
862
863If you have a compiler that produces error messages that do not fit in the
864format string, you could write a program that translates the error messages
865into this format. You can use this program with the ":make" command by
866changing the 'makeprg' option. For example: >
867 :set mp=make\ \\\|&\ error_filter
868The backslashes before the pipe character are required to avoid it to be
869recognized as a command separator. The backslash before each space is
870required for the set command.
871
872=============================================================================
8738. The directory stack *quickfix-directory-stack*
874
875Quickfix maintains a stack for saving all used directories parsed from the
876make output. For GNU-make this is rather simple, as it always prints the
877absolute path of all directories it enters and leaves. Regardless if this is
878done via a 'cd' command in the makefile or with the parameter "-C dir" (change
879to directory before reading the makefile). It may be useful to use the switch
880"-w" to force GNU-make to print out the working directory before and after
881processing.
882
883Maintaining the correct directory is more complicated if you don't use
884GNU-make. AIX-make for example doesn't print any information about its working
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000885directory. Then you need to enhance the makefile. In the makefile of LessTif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000886there is a command which echoes "Making {target} in {dir}". The special
887problem here is that it doesn't print informations on leaving the directory
888and that it doesn't print the absolute path.
889
890To solve the problem with relative paths and missing "leave directory"
891messages Vim uses following algorithm:
892
8931) Check if the given directory is a subdirectory of the current directory.
894 If this is true, store it as the current directory.
8952) If it is not a subdir of the current directory, try if this is a
896 subdirectory of one of the upper directories.
8973) If the directory still isn't found, it is assumed to be a subdirectory
898 of Vim's current directory.
899
900Additionally it is checked for every file, if it really exists in the
901identified directory. If not, it is searched in all other directories of the
902directory stack (NOT the directory subtree!). If it is still not found, it is
903assumed that it is in Vim's current directory.
904
905There are limitation in this algorithm. This examples assume that make just
906prints information about entering a directory in the form "Making all in dir".
907
9081) Assume you have following directories and files:
909 ./dir1
910 ./dir1/file1.c
911 ./file1.c
912
913 If make processes the directory "./dir1" before the current directory and
914 there is an error in the file "./file1.c", you will end up with the file
915 "./dir1/file.c" loaded by Vim.
916
917 This can only be solved with a "leave directory" message.
918
9192) Assume you have following directories and files:
920 ./dir1
921 ./dir1/dir2
922 ./dir2
923
924 You get the following:
925
926 Make output Directory interpreted by Vim
927 ------------------------ ----------------------------
928 Making all in dir1 ./dir1
929 Making all in dir2 ./dir1/dir2
930 Making all in dir2 ./dir1/dir2
931
932 This can be solved by printing absolute directories in the "enter directory"
933 message or by printing "leave directory" messages..
934
935To avoid this problems, ensure to print absolute directory names and "leave
936directory" messages.
937
938Examples for Makefiles:
939
940Unix:
941 libs:
942 for dn in $(LIBDIRS); do \
943 (cd $$dn; echo "Entering dir '$$(pwd)'"; make); \
944 echo "Leaving dir"; \
945 done
946
947Add
948 %DEntering\ dir\ '%f',%XLeaving\ dir
949to your 'errorformat' to handle the above output.
950
951Note that Vim doesn't check if the directory name in a "leave directory"
952messages is the current directory. This is why you could just use the message
953"Leaving dir".
954
955=============================================================================
9569. Specific error file formats *errorformats*
957
958 *errorformat-Jikes*
959Jikes(TM), a source-to-bytecode Java compiler published by IBM Research,
960produces simple multi-line error messages.
961
962An 'errorformat' string matching the produced messages is shown below.
963The following lines can be placed in the user's |vimrc| to overwrite Vim's
964recognized default formats, or see |:set+=| how to install this format
965additionally to the default. >
966
967 :set efm=%A%f:%l:%c:%*\\d:%*\\d:,
968 \%C%*\\s%trror:%m,
969 \%+C%*[^:]%trror:%m,
970 \%C%*\\s%tarning:%m,
971 \%C%m
972<
973Jikes(TM) produces a single-line error message when invoked with the option
974"+E", and can be matched with the following: >
975
976 :set efm=%f:%l:%v:%*\\d:%*\\d:%*\\s%m
977<
978 *errorformat-javac*
979This 'errorformat' has been reported to work well for javac, which outputs a
980line with "^" to indicate the column of the error: >
981 :set efm=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
982or: >
983 :set efm=%A%f:%l:\ %m,%+Z%p^,%+C%.%#,%-G%.%#
984<
985 *errorformat-ant*
986For ant (http://jakarta.apache.org/) the above errorformat has to be modified
987to honour the leading [javac] in front of each javac output line: >
988 :set efm=%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
989
990The 'errorformat' can also be configured to handle ant together with either
991javac or jikes. If you're using jikes, you should tell ant to use jikes' +E
992command line switch which forces jikes to generate one-line error messages.
993This is what the second line (of a build.xml file) below does: >
994 <property name = "build.compiler" value = "jikes"/>
995 <property name = "build.compiler.emacs" value = "true"/>
996
997The 'errorformat' which handles ant with both javac and jikes is: >
998 :set efm=\ %#[javac]\ %#%f:%l:%c:%*\\d:%*\\d:\ %t%[%^:]%#:%m,
999 \%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
1000<
1001 *errorformat-jade*
1002parsing jade (see http://www.jclark.com/) errors is simple: >
1003 :set efm=jade:%f:%l:%c:%t:%m
1004<
1005 *errorformat-LaTeX*
1006The following is an example how an 'errorformat' string can be specified
1007for the (La)TeX typesetting system which displays error messages over
1008multiple lines. The output of ":clist" and ":cc" etc. commands displays
1009multi-lines in a single line, leading white space is removed.
1010It should be easy to adopt the above LaTeX errorformat to any compiler output
1011consisting of multi-line errors.
1012
1013The commands can be placed in a |vimrc| file or some other Vim script file,
1014eg. a script containing LaTeX related stuff which is loaded only when editing
1015LaTeX sources.
1016Make sure to copy all lines of the example (in the given order), afterwards
1017remove the comment lines. For the '\' notation at the start of some lines see
1018|line-continuation|.
1019
1020 First prepare 'makeprg' such that LaTeX will report multiple
1021 errors; do not stop when the first error has occurred: >
1022 :set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}
1023<
1024 Start of multi-line error messages: >
1025 :set efm=%E!\ LaTeX\ %trror:\ %m,
1026 \%E!\ %m,
1027< Start of multi-line warning messages; the first two also
1028 include the line number. Meaning of some regular expressions:
1029 - "%.%#" (".*") matches a (possibly empty) string
1030 - "%*\\d" ("\d\+") matches a number >
1031 \%+WLaTeX\ %.%#Warning:\ %.%#line\ %l%.%#,
1032 \%+W%.%#\ at\ lines\ %l--%*\\d,
1033 \%WLaTeX\ %.%#Warning:\ %m,
1034< Possible continuations of error/warning messages; the first
1035 one also includes the line number: >
1036 \%Cl.%l\ %m,
1037 \%+C\ \ %m.,
1038 \%+C%.%#-%.%#,
1039 \%+C%.%#[]%.%#,
1040 \%+C[]%.%#,
1041 \%+C%.%#%[{}\\]%.%#,
1042 \%+C<%.%#>%.%#,
1043 \%C\ \ %m,
1044< Lines that match the following patterns do not contain any
1045 important information; do not include them in messages: >
1046 \%-GSee\ the\ LaTeX%m,
1047 \%-GType\ \ H\ <return>%m,
1048 \%-G\ ...%.%#,
1049 \%-G%.%#\ (C)\ %.%#,
1050 \%-G(see\ the\ transcript%.%#),
1051< Generally exclude any empty or whitespace-only line from
1052 being displayed: >
1053 \%-G\\s%#,
1054< The LaTeX output log does not specify the names of erroneous
1055 source files per line; rather they are given globally,
1056 enclosed in parentheses.
1057 The following patterns try to match these names and store
1058 them in an internal stack. The patterns possibly scan over
1059 the same input line (one after another), the trailing "%r"
1060 conversion indicates the "rest" of the line that will be
1061 parsed in the next go until the end of line is reached.
1062
1063 Overread a file name enclosed in '('...')'; do not push it
1064 on a stack since the file apparently does not contain any
1065 error: >
1066 \%+O(%f)%r,
1067< Push a file name onto the stack. The name is given after '(': >
1068 \%+P(%f%r,
1069 \%+P\ %\\=(%f%r,
1070 \%+P%*[^()](%f%r,
1071 \%+P[%\\d%[^()]%#(%f%r,
1072< Pop the last stored file name when a ')' is scanned: >
1073 \%+Q)%r,
1074 \%+Q%*[^()])%r,
1075 \%+Q[%\\d%*[^()])%r
1076
1077Note that in some cases file names in the LaTeX output log cannot be parsed
1078properly. The parser might have been messed up by unbalanced parentheses
1079then. The above example tries to catch the most relevant cases only.
1080You can customize the given setting to suit your own purposes, for example,
1081all the annoying "Overfull ..." warnings could be excluded from being
1082recognized as an error.
1083Alternatively to filtering the LaTeX compiler output, it is also possible
1084to directly read the *.log file that is produced by the [La]TeX compiler.
1085This contains even more useful information about possible error causes.
1086However, to properly parse such a complex file, an external filter should
1087be used. See the description further above how to make such a filter known
1088by Vim.
1089
1090 *errorformat-Perl*
1091In $VIMRUNTIME/tools you can find the efm_perl.pl script, which filters Perl
1092error messages into a format that quickfix mode will understand. See the
1093start of the file about how to use it.
1094
1095
1096
1097 vim:tw=78:ts=8:ft=help:norl: