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