Start anew
[git/jnareb-git.git] / share / vim / vim58 / doc / quickfix.txt
blobd3b9fb055d5fd4758ae2b0674bb22392404bd148
1 *quickfix.txt*  For Vim version 5.8.  Last change: 1999 Oct 28
4                   VIM REFERENCE MANUAL    by Bram Moolenaar
7 {Vi does not have any of these commands}
9 The quickfix commands are not available when the |+quickfix| feature was
10 disabled at compile time.
13 Using the QuickFix mode                                 *quickfix* *Quickfix*
15 Vim has a special mode to speedup the edit-compile-edit cycle.  This is
16 inspired by the quickfix option of the Manx's Aztec C compiler on the Amiga.
17 The idea is to save the error messages from the compiler in a file and use
18 Vim to jump to the errors one by one.  You can then examine each problem and
19 fix it, without having to remember all the error messages.
21 If you are using Manx's Aztec C compiler on the Amiga you should do the
22 following:
23 - Set the CCEDIT environment variable with the command
24         mset "CCEDIT=vim -q"
25 - Compile with the -qf option.  If the compiler finds any errors, Vim is
26   started and the cursor is positioned on the first error.  The error message
27   will be displayed on the last line.  You can go to other errors with the
28   commands mentioned below.  You can fix the errors and write the file(s).
29 - If you exit Vim normally the compiler will re-compile the same file.  If you
30   exit with the :cq command, the compiler will terminate.  Do this if you
31   cannot fix the error, or if another file needs to be compiled first.
33 If you are using another compiler you should save the error messages in a
34 file and start Vim with "vim -q filename".  An easy way to do this is with
35 the ":make" command (see below).  The 'errorformat' option should be set to
36 match the error messages from your compiler (see below).
38 The following commands can be used if you are in QuickFix mode:
40                                                         *:cc*
41 :cc[!] [nr]             Display error [nr].  If [nr] is omitted, the same
42                         error is displayed again.  Without [!] this doesn't
43                         work when jumping to another buffer, the current buffer
44                         has been changed, there is the only window for the
45                         buffer and both 'hidden' and 'autowrite' are off.
46                         When jumping to another buffer with [!] any changes to
47                         the current buffer are lost, unless 'hidden' is set or
48                         there is another window for this buffer.
49                         The 'switchbuf' settings are respected when jumping
50                         to a buffer.
52                                                         *:cn* *:cnext*
53 :[count]cn[ext][!]      Display the [count] next error in the list that
54                         includes a file name.  If there are no file names at
55                         all, go to the [count] next error.  See |:cc| for
56                         [!] and 'switchbuf'.
58 :[count]cN[ext][!]                      *:cp* *:cprevious* *:cN* *:cNext*
59 :[count]cp[revious][!]  Display the [count] previous error in the list that
60                         includes a file name.  If there are no file names at
61                         all, go to the [count] previous error.  See |:cc| for
62                         [!] and 'switchbuf'.
64                                                         *:cnf* *:cnfile*
65 :[count]cnf[ile][!]     Display the first error in the [count] next file in
66                         the list that includes a file name.  If there are no
67                         file names at all or if there is no next file, go to
68                         the [count] next error.  See |:cc| for [!] and
69                         'switchbuf'.
71                                                         *:crewind* *:cr*
72 :cr[ewind][!] [nr]      Display error [nr].  If [nr] is omitted, the FIRST
73                         error is displayed.  See |:cc|.
75                                                         *:clast* *:cla*
76 :cla[st][!] [nr]        Display error [nr].  If [nr] is omitted, the LAST
77                         error is displayed.  See |:cc|.
79                                                         *:cq* *:cquit*
80 :cq[uit]                Quit Vim with an error code, so that the compiler
81                         will not compile the same file again.
83                                                         *:cf* *:cfile*
84 :cf[ile][!] [errorfile] Read the error file and jump to the first error.
85                         This is done automatically when Vim is started with
86                         the -q option.  You can use this command when you
87                         keep Vim running while compiling.  If you give the
88                         name of the errorfile, the 'errorfile' option will
89                         be set to [errorfile].  See |:cc| for [!].
91                                                         *:cl* *:clist*
92 :cl[ist] [from] [, [to]]
93                         List all errors that include a file name.
94                         If numbers [from] and/or [to] are given, the respective
95                         range of errors is listed. A negative number counts
96                         from the last error backwards, -1 being the last error.
97                         The 'switchbuf' settings are respected when jumping
98                         to a buffer.
100 :cl[ist]! [from] [, [to]]
101                         List all errors.
103                                                         *:mak* *:make*
104 :mak[e] [arguments]     1. If the 'autowrite' option is on, write any changed
105                            buffers
106                         2. An errorfile name is made from 'makeef'.  If
107                            'makeef' doesn't contain "##", and a file with this
108                            name already exists, it is deleted.
109                         3. The program given with the 'makeprg' option is
110                            started (default "make") with the optional
111                            [arguments] and the output is saved in the
112                            errorfile (for Unix it is also echoed on the
113                            screen).
114                         4. The errorfile is then read and the first error is
115                            jumped to.
116                         5. The errorfile is deleted.
117                         This command does not accept a comment, any "
118                         characters are considered part of the arguments.
120                                                             *:gr* *:grep*
121 :gr[ep] [arguments]     Just like ":make", but use 'grepprg' instead of
122                         'makeprg' and 'grepformat' instead of 'errorformat'.
123                         See |grep|.
124                         [Unix trivia: The name for the Unix "grep" command
125                         comes from ":g/re/p", where "re" stands for Regular
126                         Expression.]
128 A template for the errorfile name can be set with the 'makeef' option.  If it
129 includes "##", Vim will replace this with a number to make it a unique name.
131 The format of the file from the Aztec compiler is:
133         filename>linenumber:columnnumber:errortype:errornumber:errormessage
135         filename        name of the file in which the error was detected
136         linenumber      line number where the error was detected
137         columnnumber    column number where the error was detected
138         errortype       type of the error, normally a single 'E' or 'W'
139         errornumber     number of the error (for lookup in the manual)
140         errormessage    description of the error
142                                                         *errorformat*
143 Another compiler is likely to use a different format.  You should set the
144 'errorformat' option to a scanf-like string that describes the format.
145 First, you need to know how scanf works.  Look in the documentation of your
146 C compiler.  Vim will understand the following conversion characters.
147 Others are invalid.
148         %f              file name (finds a string)
149         %l              line number (finds a number)
150         %c              column number (finds a number)
151         %t              error type (finds a single character)
152         %n              error number (finds a number)
153         %m              error message (finds a string)
154         %r              matches the "rest" of a single-line file message %O/P/Q
155         %*{conv}        any scanf non-assignable conversion
156         %%              the single '%' character
158 The following uppercase conversion characters specify the type of special
159 format strings.  At most one of them may be given as a prefix at the begin
160 of a single comma-separated format pattern.
161 Some compilers produce messages that consist of directory names that have to
162 be prepended to each file name read by %f (example: GUN make). The following
163 codes can be used to scan these directory names; they will be stored in an
164 internal directory stack.
165         %D              "enter directory" format string; expects a following
166                           %f that finds the directory name
167         %X              "leave directory" format string; expects following %f
169                                                 *errorformat-multi-line*
170 It is possible to read the output of programs that produce multi-line messages,
171 ie. error strings that consume more than one line. Possible prefixes are:
172         %A              start of a multi-line message (unspecified type)
173         %E              start of a multi-line error message
174         %W              start of a multi-line warning message
175         %C              continuation of a multi-line message
176         %Z              end of a multi-line message
177         %G              global; useful only in conjunction with '+' or '-'
178         %O              single-line file message: overread the matched part
179         %P              single-line file message: push file %f onto the stack
180         %Q              single-line file message: pop the last file from stack
181 The codes '+' or '-' can be combined with the uppercase codes above; in that
182 case they have to precede the letter, eg. '%+A' or '%-G':
183         %-              do not include the matching line in any output
184         %+              include the whole matching line in the %m error string
186 The scanf()-like "%*[]" notation is supported for backward-compatibility
187 with previous versions of Vim.  However, it is also possible to specify
188 (nearly) any Vim supported regular expression in format strings.
189 Since meta characters of the regular expression language can be part of
190 ordinary matching strings or file names (and therefore internally have to
191 be escaped), meta symbols have to be written with leading '%':
192         %\              the single '\' character. Note that this has to be
193                         escaped ("%\\") in ":set errorformat=" definitions.
194         %.              the single '.' character.
195         %#              the single '*'(!) character.
196         %^              the single '^' character.
197         %$              the single '$' character.
198         %[              the single '[' character.
199         %~              the single '~' character.
200 When using character classes in expressions (see |/\i| for an overview),
201 terms containing the "\+" quantifier can be written in the scanf() "%*"
202 notation. Example: "%\\d%\\+" ("\d\+", "any number") is equivalent to "%*\\d".
203 Important note: The \(...\) grouping of expressions can not be used in format
204 specifications because it is reserved for internal conversions.
206 Some examples for C compilers that produce single-line error outputs:
207 %f>%l:%c:%t:%n:%m"                      for the AztecC.Err file
208 %f:%l:\ %t%*[^0123456789]%n:\ %m        for Manx/Aztec C error messages
209                                         (scanf() doesn't understand [0-9])
210 %f\ %l\ %t%*[^0-9]%n:\ %m               for SAS C
211 \"%f\"\\,%*[^0-9]%l:\ %m                for generic C compilers
212 %f:%l:\ %m                              for GCC
213 %f:%l:\ %m,%Dgmake[%*\\d]:\ Entering\ directory\ `%f',
214 %Dgmake[%*\\d]:\ Leaving\ directory\ `%f'
215                                         for GCC with gmake (concat the lines!)
216 %f(%l)\ :\ %*[^:]:\ %m                  old SCO C compiler (pre-OS5)
217 %f(%l)\ :\ %t%*[^0-9]%n:\ %m            idem, with error type and number
218 %f:%l:\ %m,In\ file\ included\ from\ %f:%l:,\^I\^Ifrom\ %f:%l%m
219                                         for GCC, with some extras
221 Extended examples for the handling of multi-line messages are given below,
222 see |errorformat-Jikes| and |errorformat-LaTeX|.
224 Note the backslash in front of a space and double quote.  It is required for
225 the :set command.  There are two backslashes in front of a comma, one for the
226 :set command and one to avoid recognizing the comma as a separator of error
227 formats.
229 The "%f" conversion depends on the current 'isfname' setting.
231 The "%f" and "%m" conversions have to detect the end of the string.  They
232 should be followed by a character that cannot be in the string.  Everything
233 up to that character is included in the string.  Be careful: "%f%l" will
234 include everything up to the first '%' in the file name.  If the "%f" or "%m"
235 is at the end, everything up to the end of the line is included.
237 When defining an "enter directory" or "leave directory" format, the "%D" or
238 "%X" has to be given at the start of that substring. Vim tracks the directory
239 changes and prepends the current directory to each erroneous file found with a
240 relative path.  See |quickfix-directory-stack| for details, tips and
241 limitations.
243 To be able to detect output from several compilers, several format patterns
244 may be put in 'errorformat', separated by commas (note: blanks after the comma
245 are ignored).  The first pattern that has a complete match is used.  If no
246 match is found, matching parts from the last one will be used, although the
247 file name is removed and the error message is set to the whole message.  If
248 there is a pattern that may match output from several compilers (but not in a
249 right way), put it after one that is more restrictive.  To include a comma in
250 a pattern precede it with a backslash (you have to type two in a set command).
251 To include a backslash itself give two backslashes (you have to type four in a
252 set command).
254 If a line is detected that does not completely match the 'errorformat', the
255 whole line is put in the error message and the entry is marked "not valid"
256 These lines are skipped with the ":cn" and ":cp" commands (unless there is
257 no valid line at all).  You can use ":cl!" to display all the error messages.
259 If the error format does not contain a file name Vim cannot switch to the
260 correct file.  You will have to do this by hand.
262 If you have a compiler that produces error messages that do not fit in the
263 format string, you could write a program that translates the error messages
264 into this format.  You can use this program with the ":make" command by
265 changing the 'makeprg' option.  For example:
266 >  :set mp=make\ \\\|&\ error_filter
267 The backslashes before the pipe character are required to avoid it to be
268 recognized as a command separator.  The backslash before each space is
269 required for the set command.
271                                                 *quickfix-directory-stack*
272 Quickfix maintains a stack for saving all used directories parsed from the
273 make output. For GNU-make this is rather simple, as it always prints the
274 absolute path of all directories it enters and leaves. Regardless if this is
275 done via a 'cd' command in the makefile or with the parameter "-C dir" (change
276 to directory before reading the makefile). It may be useful to use the switch
277 "-w" to force GNU-make to print out the working directory before and after
278 processing.
280 Maintaining the correct directory is more complicated if you don't use
281 GNU-make. AIX-make for example doesn't print any information about its working
282 directory. Then you need to enhance the makefile. In the makefile of lesstiff
283 their is a command which echos "Making {target} in {dir}". The special problem
284 here is that it doesn't print informations on leaving the directory and that
285 it doesn't print the absolute path.
287 To solve the problem with relative paths and missing "leave directory"
288 messages Vim uses following algorithm:
290 1) Check if the given directory is a subdirectory of the current directory.
291    If this is true, store it as the current directory.
292 2) If it is not a subdir of the current directory, try if this is a
293    subdirectory of one of the upper directories.
294 3) If the directory still isn't found, it is assumed to be a subdirectory
295    of Vim's current directory.
297 Additionally it is checked for every file, if it really exists in the
298 identified directory.  If not, it is searched in all other directories of the
299 directory stack (NOT the directory subtree!). If it is still not found, it is
300 assumed that it is in Vim's current directory.
302 There are limitation in this algorithm. This examples assume that make just
303 prints information about entering a directory in the form "Making all in dir".
305 1) Assume you have following directories and files:
306    ./dir1
307    ./dir1/file1.c
308    ./file1.c
310    If make processes the directory "./dir1" before the current directory and
311    there is an error in the file "./file1.c", you will end up with the file
312    "./dir1/file.c" loaded by Vim.
314    This can only be solved with a "leave directory" message.
316 2) Assume you have following directories and files:
317    ./dir1
318    ./dir1/dir2
319    ./dir2
321    You get the following:
323    Make output                    Directory interpreted by Vim
324    ------------------------       ----------------------------
325    Making all in dir1             ./dir1
326    Making all in dir2             ./dir1/dir2
327    Making all in dir2             ./dir1/dir2
329    This can be solved by printing absolute directories in the "enter directory"
330    message or by printing "leave directory" messages..
332 To avoid this problems, ensure to print absolute directory names and "leave
333 directory" messages.
335 Examples for Makefiles:
337 Unix:
338     libs:
339             for dn in $(LIBDIRS); do                            \
340                 (cd $$dn; echo "Entering dir '$$(pwd)'"; make); \
341                 echo "Leaving dir";                             \
342             done
345     %DEntering\ dir\ '%f',%XLeaving\ dir
346 to your 'errorformat' to handle the above output.
348 Note that Vim doesn't check if the directory name in a "leave directory"
349 messages is the current directory. This is why you could just use the message
350 "Leaving dir".
353                                                 *errorformat-Jikes*
354 Jikes(TM), a source-to-bytecode Java compiler published by IBM Research.
355 produces simple multi-line error messages when invoked with the option "+E".
357 An 'errorformat' string matching the produced messages is shown below.
358 The following lines can be placed in the user's |vimrc| to overwrite Vim's
359 recognized default formats, or see |:set+=| how to install this format
360 additionally to the default.
362 >set efm=%A%f:%l:%c:%*\\d:%*\\d:,
363 >       \%C%*\\s%trror:%m,
364 >       \%+C%*[^:]%trror:%m,
365 >       \%C%*\\s%tarning:%m,
366 >       \%C%m
368 Note: when copying the command from this help text, please do not forget to
369 remove the leading '>' characters that mark examples.
372                                                 *errorformat-LaTeX*
373 The following is an example how an 'errorformat' string can be specified
374 for the (La)TeX type setting system which displays error messages over
375 multiple lines.  The output of ":clist" and ":cc" etc. commands displays
376 multi-lines in a single line, leading white space is removed.
377 It should be easy to adopt the above LaTeX errorformat to any compiler output
378 consisting of multi-line errors.
380 The commands can be placed in a |vimrc| file or some other Vim script file,
381 eg. a script containing LaTeX related stuff which is loaded only when editing
382 LaTeX sources.
383 Make sure to copy all lines of the example (in the given order), afterwards
384 remove the comment lines and also leading '>' characters.  For the '\' notation
385 at the start of some lines see |line-continuation|.
387                 First prepare 'makeprg' such that LaTeX will report multiple
388                 errors; do not stop when the first error has occurred:
389 >set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}
391                 Start of multi-line error messages:
392 >set efm=%E!\ LaTeX\ %trror:\ %m,
393 >       \%E!\ %m,
394                 Start of multi-line warning messages; the first two also
395                 include the line number. Meaning of some regular expressions:
396                   - "%.%#"  (".*")   matches a (possibly empty) string
397                   - "%*\\d" ("\d\+") matches a number
398 >       \%+WLaTeX\ %.%#Warning:\ %.%#line\ %l%.%#,
399 >       \%+W%.%#\ at\ lines\ %l--%*\\d,
400 >       \%WLaTeX\ %.%#Warning:\ %m,
401                 Possible continuations of error/warning messages; the first
402                 one also includes the line number:
403 >       \%Cl.%l\ %m,
404 >       \%+C\ \ %m.,
405 >       \%+C%.%#-%.%#,
406 >       \%+C%.%#[]%.%#,
407 >       \%+C[]%.%#,
408 >       \%+C%.%#%[{}\\]%.%#,
409 >       \%+C<%.%#>%.%#,
410 >       \%C\ \ %m,
411                 Lines that match the following patterns do not contain any
412                 important information; do not include them in messages:
413 >       \%-GSee\ the\ LaTeX%m,
414 >       \%-GType\ \ H\ <return>%m,
415 >       \%-G\ ...%.%#,
416 >       \%-G%.%#\ (C)\ %.%#,
417 >       \%-G(see\ the\ transcript%.%#),
418                 Generally exclude any empty or whitespace-only line from
419                 being displayed:
420 >       \%-G%*\\s,
421                 The LaTeX output log does not specify the names of erroneous
422                 source files per line; rather they are given globally,
423                 enclosed in parentheses.
424                 The following patterns try to match these names and store
425                 them in an internal stack.  The patterns possibly scan over
426                 the same input line (one after another), the trailing "%r"
427                 conversion indicates the "rest" of the line that will be
428                 parsed in the next go until the end of line is reached.
430                 Overread a file name enclosed in '('...')'; do not push it
431                 on a stack since the file apparently does not contain any
432                 error:
433 >       \%+O(%f)%r,
434                 Push a file name onto the stack. The name is given after '(':
435 >       \%+P(%f%r,
436 >       \%+P\ %\\=(%f%r,
437 >       \%+P%*[^()](%f%r,
438 >       \%+P[%\\d%[^()]%#(%f%r,
439                 Pop the last stored file name when a ')' is scanned:
440 >       \%+Q)%r,
441 >       \%+Q%*[^()])%r,
442 >       \%+Q[%\\d%*[^()])%r
444 Note that in some cases file names in the LaTeX output log cannot be parsed
445 properly.  The parser might have been messed up by unbalanced parentheses
446 then.  The above example tries to catch the most relevant cases only.
447 You can customize the given setting to suit your own purposes, for example,
448 all the annoying "Overfull ..." warnings could be excluded from being
449 recognized as an error.
450 Alternatively to filtering the LaTeX compiler output, it is also possible
451 to directly read the *.log file that is produced by the [La]TeX compiler.
452 This contains even more useful information about possible error causes.
453 However, to properly parse such a complex file, an external filter should
454 be used.  See the description further above how to make such a filter known
455 by Vim.
458                                                 *quickfix-error-lists*
459 So far has been assumed that there is only one list of errors.  Actually the
460 ten last used lists are remembered.  When starting a new list, the previous
461 ones are automatically kept.  Two commands can be used to access older error
462 lists.  They set one of the existing error lists as the current one.
464                                                 *:colder* *:col*
465 :col[der] [count]       Go to older error list.  When [count] is given, do
466                         this [count] times.  When already at the oldest error
467                         list, an error message is given.
469                                                 *:cnewer* *:cnew*
470 :cnew[er] [count]       Go to newer error list.  When [count] is given, do
471                         this [count] times.  When already at the newest error
472                         list, an error message is given.
474 When adding a new error list, it becomes the current list.
477                                                 *:make_makeprg*
478 The ":make" command executes the command given with the 'makeprg' option.
479 This is done by passing the command to the shell given with the 'shell'
480 option.  This works almost like typing
482         ":!{makeprg} [arguments] {shellpipe} {errorfile}".
484 {makeprg} is the string given with the 'makeprg' option.  Any command can be
485 used, not just "make".  Characters '%' and '#' are expanded as usual on a
486 command-line.  You can use "#<" to insert the current file name without
487 extension, for example:
488 >  :set makeprg=make\ #<.o
490 [arguments] is anything that is typed after ":make".
491 {shellpipe} is the 'shellpipe' option.
492 {errorfile} is the 'makeef' option, with ## replaced to make it unique.
494 The placeholder "$*" can be used for the argument list in {makeprog} if the
495 command needs some additional characters after its arguments.  The $* is
496 replaced then by all arguments.  Example:
497 >  :set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}
498 or simpler
499 >  :let &mp = 'latex \\nonstopmode \\input\{$*}'
500 "$*" can be given multiple times, for example:
501 >  :set makeprg=gcc\ -o\ $*\ $*
503 The 'shellpipe' option defaults to ">" for the Amiga, MS-DOS and Win32.  This
504 means that the output of the compiler is saved in a file and not shown on the
505 screen directly.  For Unix "| tee" is used.  The compiler output is shown on
506 the screen and saved in a file the same time.  Depending on the shell used
507 "|& tee" or "2>&1| tee" is the default, so stderr output will be included.
509 If 'shellpipe' is empty, the {errorfile} part will be omitted.  This is useful
510 for compilers that write to an errorfile themselves (Manx's Amiga C).
512 There are some restrictions to the Quickfix mode on the Amiga.  The
513 compiler only writes the first 25 errors to the errorfile (Manx's
514 documentation does not say how to get more).  If you want to find the others,
515 you will have to fix a few errors and exit the editor.  After recompiling,
516 up to 25 remaining errors will be found.
518 On the Amiga, if Vim was started from the compiler, the :sh and some :!
519 commands will not work, because Vim is then running in the same process as the
520 compiler and stdin (standard input) will not be interactive.
522 If you insert or delete lines, mostly the correct error location is still
523 found because hidden marks are used (Manx's Z editor does not do this).
524 Sometimes, when the mark has been deleted for some reason, the message "line
525 changed" is shown to warn you that the error location may not be correct.  If
526 you quit Vim and start again the marks are lost and the error locations may
527 not be correct anymore.
529  vim:tw=78:ts=8:sw=8: