Runtime files update
[MacVim.git] / runtime / doc / quickfix.txt
blob6dfdae3c5b2ee4ae6c59dc1e5f647ff148e81ba6
1 *quickfix.txt*  For Vim version 7.1.  Last change: 2007 Sep 30
4                   VIM REFERENCE MANUAL    by Bram Moolenaar
7 This subject is introduced in section |30.1| of the user manual.
9 1. Using QuickFix commands              |quickfix|
10 2. The error window                     |quickfix-window|
11 3. Using more than one list of errors   |quickfix-error-lists|
12 4. Using :make                          |:make_makeprg|
13 5. Using :grep                          |grep|
14 6. Selecting a compiler                 |compiler-select|
15 7. The error format                     |error-file-format|
16 8. The directory stack                  |quickfix-directory-stack|
17 9. Specific error file formats          |errorformats|
19 {Vi does not have any of these commands}
21 The quickfix commands are not available when the |+quickfix| feature was
22 disabled at compile time.
24 =============================================================================
25 1. Using QuickFix commands                      *quickfix* *Quickfix* *E42*
27 Vim has a special mode to speedup the edit-compile-edit cycle.  This is
28 inspired by the quickfix option of the Manx's Aztec C compiler on the Amiga.
29 The idea is to save the error messages from the compiler in a file and use Vim
30 to jump to the errors one by one.  You can examine each problem and fix it,
31 without having to remember all the error messages.
33 In Vim the quickfix commands are used more generally to find a list of
34 positions in files.  For example, |:vimgrep| finds pattern matches.  You can
35 use the positions in a script with the |getqflist()| function.  Thus you can
36 do a lot more than the edit/compile/fix cycle!
38 If you are using Manx's Aztec C compiler on the Amiga look here for how to use
39 it with Vim: |quickfix-manx|.  If you are using another compiler you should
40 save the error messages in a file and start Vim with "vim -q filename".  An
41 easy 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
43 compiler (see |errorformat| below).
45                                                 *location-list* *E776*
46 A location list is similar to a quickfix list and contains a list of positions
47 in files.  A location list is associated with a window and each window can
48 have a separate location list.  A location list can be associated with only
49 one window.  The location list is independent of the quickfix list.
51 When a window with a location list is split, the new window gets a copy of the
52 location list.  When there are no references to a location list, the location
53 list is destroyed.
55 The following quickfix commands can be used.  The location list commands are
56 similar to the quickfix commands, replacing the 'c' prefix in the quickfix
57 command with 'l'.
59                                                         *:cc*
60 :cc[!] [nr]             Display error [nr].  If [nr] is omitted, the same
61                         error is displayed again.  Without [!] this doesn't
62                         work when jumping to another buffer, the current buffer
63                         has been changed, there is the only window for the
64                         buffer and both 'hidden' and 'autowrite' are off.
65                         When jumping to another buffer with [!] any changes to
66                         the current buffer are lost, unless 'hidden' is set or
67                         there is another window for this buffer.
68                         The 'switchbuf' settings are respected when jumping
69                         to a buffer.
71                                                         *:ll*
72 :ll[!] [nr]             Same as ":cc", except the location list for the
73                         current window is used instead of the quickfix list.
75                                                         *:cn* *:cnext* *E553*
76 :[count]cn[ext][!]      Display the [count] next error in the list that
77                         includes a file name.  If there are no file names at
78                         all, go to the [count] next error.  See |:cc| for
79                         [!] and 'switchbuf'.
81                                                         *:lne* *:lnext*
82 :[count]lne[xt][!]      Same as ":cnext", except the location list for the
83                         current window is used instead of the quickfix list.
85 :[count]cN[ext][!]                      *:cp* *:cprevious* *:cN* *:cNext*
86 :[count]cp[revious][!]  Display the [count] previous error in the list that
87                         includes a file name.  If there are no file names at
88                         all, go to the [count] previous error.  See |:cc| for
89                         [!] and 'switchbuf'.
92 :[count]lN[ext][!]                      *:lp* *:lprevious* *:lN* *:lNext*
93 :[count]lp[revious][!]  Same as ":cNext" and ":cprevious", except the location
94                         list for the current window is used instead of the
95                         quickfix list.
97                                                         *:cnf* *:cnfile*
98 :[count]cnf[ile][!]     Display the first error in the [count] next file in
99                         the list that includes a file name.  If there are no
100                         file names at all or if there is no next file, go to
101                         the [count] next error.  See |:cc| for [!] and
102                         'switchbuf'.
104                                                         *:lnf* *:lnfile*
105 :[count]lnf[ile][!]     Same as ":cnfile", except the location list for the
106                         current window is used instead of the quickfix list.
108 :[count]cNf[ile][!]                     *:cpf* *:cpfile* *:cNf* *:cNfile*
109 :[count]cpf[ile][!]     Display the last error in the [count] previous file in
110                         the list that includes a file name.  If there are no
111                         file names at all or if there is no next file, go to
112                         the [count] previous error.  See |:cc| for [!] and
113                         'switchbuf'.
116 :[count]lNf[ile][!]                     *:lpf* *:lpfile* *:lNf* *:lNfile*
117 :[count]lpf[ile][!]     Same as ":cNfile" and ":cpfile", except the location
118                         list for the current window is used instead of the
119                         quickfix list.
121                                                         *:crewind* *:cr*
122 :cr[ewind][!] [nr]      Display error [nr].  If [nr] is omitted, the FIRST
123                         error is displayed.  See |:cc|.
125                                                         *:lrewind* *:lr*
126 :lr[ewind][!] [nr]      Same as ":crewind", except the location list for the
127                         current window is used instead of the quickfix list.
129                                                         *:cfirst* *:cfir*
130 :cfir[st][!] [nr]       Same as ":crewind".
132                                                         *:lfirst* *:lfir*
133 :lfir[st][!] [nr]       Same as ":lrewind".
135                                                         *:clast* *:cla*
136 :cla[st][!] [nr]        Display error [nr].  If [nr] is omitted, the LAST
137                         error is displayed.  See |:cc|.
139                                                         *:llast* *:lla*
140 :lla[st][!] [nr]        Same as ":clast", except the location list for the
141                         current window is used instead of the quickfix list.
143                                                         *:cq* *:cquit*
144 :cq[uit]                Quit Vim with an error code, so that the compiler
145                         will not compile the same file again.
147                                                         *:cf* *:cfile*
148 :cf[ile][!] [errorfile] Read the error file and jump to the first error.
149                         This is done automatically when Vim is started with
150                         the -q option.  You can use this command when you
151                         keep Vim running while compiling.  If you give the
152                         name of the errorfile, the 'errorfile' option will
153                         be set to [errorfile].  See |:cc| for [!].
155                                                         *:lf* *:lfile*
156 :lf[ile][!] [errorfile] Same as ":cfile", except the location list for the
157                         current window is used instead of the quickfix list.
158                         You can not use the -q command-line option to set
159                         the location list.
162 :cg[etfile][!] [errorfile]                              *:cg* *:cgetfile*
163                         Read the error file.  Just like ":cfile" but don't
164                         jump to the first error.
167 :lg[etfile][!] [errorfile]                              *:lg* *:lgetfile*
168                         Same as ":cgetfile", except the location list for the
169                         current window is used instead of the quickfix list.
171                                                         *:caddf* *:caddfile*
172 :caddf[ile] [errorfile] Read the error file and add the errors from the
173                         errorfile to the current quickfix list. If a quickfix
174                         list is not present, then a new list is created.
176                                                         *:laddf* *:laddfile*
177 :laddf[ile] [errorfile] Same as ":caddfile", except the location list for the
178                         current window is used instead of the quickfix list.
180                                                 *:cb* *:cbuffer* *E681*
181 :cb[uffer][!] [bufnr]   Read the error list from the current buffer.
182                         When [bufnr] is given it must be the number of a
183                         loaded buffer.  That buffer will then be used instead
184                         of the current buffer.
185                         A range can be specified for the lines to be used.
186                         Otherwise all lines in the buffer are used.
187                         See |:cc| for [!].
189                                                 *:lb* *:lbuffer*
190 :lb[uffer][!] [bufnr]   Same as ":cbuffer", except the location list for the
191                         current window is used instead of the quickfix list.
193                                                 *:cgetb* *:cgetbuffer*
194 :cgetb[uffer] [bufnr]   Read the error list from the current buffer.  Just
195                         like ":cbuffer" but don't jump to the first error.
197                                                 *:lgetb* *:lgetbuffer*
198 :lgetb[uffer] [bufnr]   Same as ":cgetbuffer", except the location list for
199                         the current window is used instead of the quickfix
200                         list.
202                                                         *:caddb* *:caddbuffer*
203 :caddb[uffer] [bufnr]   Read the error list from the current buffer and add
204                         the errors to the current quickfix list.  If a
205                         quickfix list is not present, then a new list is
206                         created. Otherwise, same as ":cbuffer".
208                                                         *:laddb* *:laddbuffer*
209 :laddb[uffer] [bufnr]   Same as ":caddbuffer", except the location list for
210                         the current window is used instead of the quickfix
211                         list.
213                                                         *:cex* *:cexpr* *E777*
214 :cex[pr][!] {expr}      Create a quickfix list using the result of {expr} and
215                         jump to the first error.  If {expr} is a String, then
216                         each new-line terminated line in the String is
217                         processed using 'errorformat' and the result is added
218                         to the quickfix list.  If {expr} is a List, then each
219                         String item in the list is processed and added to the
220                         quickfix list.  Non String items in the List are
221                         ignored. See |:cc|
222                         for [!].
223                         Examples: >
224                                 :cexpr system('grep -n xyz *')
225                                 :cexpr getline(1, '$')
227                                                         *:lex* *:lexpr*
228 :lex[pr][!] {expr}      Same as ":cexpr", except the location list for the
229                         current window is used instead of the quickfix list.
231                                                         *:cgete* *:cgetexpr*
232 :cgete[xpr][!] {expr}   Create a quickfix list using the result of {expr}.
233                         Just like ":cexpr", but don't jump to the first error.
235                                                         *:lgete* *:lgetexpr*
236 :lgete[xpr][!] {expr}   Same as ":cgetexpr", except the location list for the
237                         current window is used instead of the quickfix list.
239                                                         *:cad* *:caddexpr*
240 :cad[dexpr][!] {expr}   Evaluate {expr} and add the resulting lines to the
241                         current quickfix list. If a quickfix list is not
242                         present, then a new list is created. The current
243                         cursor position will not be changed. See |:cexpr| for
244                         more information.
245                         Example: >
246     :g/mypattern/caddexpr expand("%") . ":" . line(".") .  ":" . getline(".")
248                                                         *:lad* *:laddexpr*
249 :lad[dexpr][!] {expr}   Same as ":caddexpr", except the location list for the
250                         current window is used instead of the quickfix list.
252                                                         *:cl* *:clist*
253 :cl[ist] [from] [, [to]]
254                         List all errors that are valid |quickfix-valid|.
255                         If numbers [from] and/or [to] are given, the respective
256                         range of errors is listed.  A negative number counts
257                         from the last error backwards, -1 being the last error.
258                         The 'switchbuf' settings are respected when jumping
259                         to a buffer.
261 :cl[ist]! [from] [, [to]]
262                         List all errors.
264                                                         *:lli* *:llist*
265 :lli[st] [from] [, [to]]
266                         Same as ":clist", except the location list for the
267                         current window is used instead of the quickfix list.
269 :lli[st]! [from] [, [to]]
270                         List all the entries in the location list for the
271                         current window.
273 If you insert or delete lines, mostly the correct error location is still
274 found because hidden marks are used.  Sometimes, when the mark has been
275 deleted for some reason, the message "line changed" is shown to warn you that
276 the error location may not be correct.  If you quit Vim and start again the
277 marks are lost and the error locations may not be correct anymore.
279 If vim is built with |+autocmd| support, two autocommands are available for
280 running commands before and after a quickfix command (':make', ':grep' and so
281 on) is executed. See |QuickFixCmdPre| and |QuickFixCmdPost| for details.
283                                                 *QuickFixCmdPost-example*
284 When 'encoding' differs from the locale, the error messages may have a
285 different encoding from what Vim is using.  To convert the messages you can
286 use this code: >
287         function QfMakeConv()
288            let qflist = getqflist()
289            for i in qflist
290               let i.text = iconv(i.text, "cp936", "utf-8")
291            endfor
292            call setqflist(qflist)
293         endfunction
295         au QuickfixCmdPost make call QfMakeConv()
298 =============================================================================
299 2. The error window                                     *quickfix-window*
301                                                         *:cope* *:copen*
302 :cope[n] [height]       Open a window to show the current list of errors.
303                         When [height] is given, the window becomes that high
304                         (if there is room).  Otherwise the window is made ten
305                         lines high.
306                         The window will contain a special buffer, with
307                         'buftype' equal to "quickfix".  Don't change this!
308                         If there already is a quickfix window, it will be made
309                         the current window.  It is not possible to open a
310                         second quickfix window.
312                                                         *:lop* *:lopen*
313 :lop[en] [height]       Open a window to show the location list for the
314                         current window. Works only when the location list for
315                         the current window is present.  You can have more than
316                         one location window opened at a time.  Otherwise, it
317                         acts the same as ":copen".
319                                                         *:ccl* *:cclose*
320 :ccl[ose]               Close the quickfix window.
322                                                         *:lcl* *:lclose*
323 :lcl[ose]               Close the window showing the location list for the
324                         current window.
326                                                         *:cw* *:cwindow*
327 :cw[indow] [height]     Open the quickfix window when there are recognized
328                         errors.  If the window is already open and there are
329                         no recognized errors, close the window.
331                                                         *:lw* *:lwindow*
332 :lw[indow] [height]     Same as ":cwindow", except use the window showing the
333                         location list for the current window.
335 Normally the quickfix window is at the bottom of the screen.  If there are
336 vertical splits, it's at the bottom of the rightmost column of windows.  To
337 make it always occupy the full width: >
338         :botright cwindow
339 You can move the window around with |window-moving| commands.
340 For example, to move it to the top: CTRL-W K
341 The 'winfixheight' option will be set, which means that the window will mostly
342 keep its height, ignoring 'winheight' and 'equalalways'.  You can change the
343 height manually (e.g., by dragging the status line above it with the mouse).
345 In the quickfix window, each line is one error.  The line number is equal to
346 the error number.  You can use ":.cc" to jump to the error under the cursor.
347 Hitting the <Enter> key or double-clicking the mouse on a line has the same
348 effect.  The file containing the error is opened in the window above the
349 quickfix window.  If there already is a window for that file, it is used
350 instead.  If the buffer in the used window has changed, and the error is in
351 another file, jumping to the error will fail.  You will first have to make
352 sure the window contains a buffer which can be abandoned.
353                                         *CTRL-W_<Enter>* *CTRL-W_<CR>*
354 You can use CTRL-W <Enter> to open a new window and jump to the error there.
356 When the quickfix window has been filled, two autocommand events are
357 triggered.  First the 'filetype' option is set to "qf", which triggers the
358 FileType event.  Then the BufReadPost event is triggered, using "quickfix" for
359 the buffer name.  This can be used to perform some action on the listed
360 errors.  Example: >
361         au BufReadPost quickfix  setlocal modifiable
362                 \ | silent exe 'g/^/s//\=line(".")." "/'
363                 \ | setlocal nomodifiable
364 This prepends the line number to each line.  Note the use of "\=" in the
365 substitute string of the ":s" command, which is used to evaluate an
366 expression.
367 The BufWinEnter event is also triggered, again using "quickfix" for the buffer
368 name.
370 Note: Making changes in the quickfix window has no effect on the list of
371 errors.  'modifiable' is off to avoid making changes.  If you delete or insert
372 lines anyway, the relation between the text and the error number is messed up.
373 If you really want to do this, you could write the contents of the quickfix
374 window to a file and use ":cfile" to have it parsed and used as the new error
375 list.
377                                                 *location-list-window*
378 The location list window displays the entries in a location list.  When you
379 open a location list window, it is created below the current window and
380 displays the location list for the current window.  The location list window
381 is similar to the quickfix window, except that you can have more than one
382 location list window open at a time. When you use a location list command in
383 this window, the displayed location list is used.
385 When you select a file from the location list window, the following steps are
386 used to find a window to edit the file:
388 1. If a window with the location list displayed in the location list window is
389    present, then the file is opened in that window.
390 2. If the above step fails and if the file is already opened in another
391    window, then that window is used.
392 3. If the above step fails then an existing window showing a buffer with
393    'buftype' not set is used.
394 4. If the above step fails, then the file is edited in a new window.
396 In all of the above cases, if the location list for the selected window is not
397 yet set, then it is set to the location list displayed in the location list
398 window.
400 =============================================================================
401 3. Using more than one list of errors                   *quickfix-error-lists*
403 So far has been assumed that there is only one list of errors.  Actually the
404 ten last used lists are remembered.  When starting a new list, the previous
405 ones are automatically kept.  Two commands can be used to access older error
406 lists.  They set one of the existing error lists as the current one.
408                                                 *:colder* *:col* *E380*
409 :col[der] [count]       Go to older error list.  When [count] is given, do
410                         this [count] times.  When already at the oldest error
411                         list, an error message is given.
413                                                 *:lolder* *:lol*
414 :lol[der] [count]       Same as ":colder", except use the location list for
415                         the current window instead of the quickfix list.
417                                                 *:cnewer* *:cnew* *E381*
418 :cnew[er] [count]       Go to newer error list.  When [count] is given, do
419                         this [count] times.  When already at the newest error
420                         list, an error message is given.
422                                                 *:lnewer* *:lnew*
423 :lnew[er] [count]       Same as ":cnewer", except use the location list for
424                         the current window instead of the quickfix list.
426 When adding a new error list, it becomes the current list.
428 When ":colder" has been used and ":make" or ":grep" is used to add a new error
429 list, one newer list is overwritten.  This is especially useful if you are
430 browsing with ":grep" |grep|.  If you want to keep the more recent error
431 lists, use ":cnewer 99" first.
433 =============================================================================
434 4. Using :make                                          *:make_makeprg*
436                                                         *:mak* *:make*
437 :mak[e][!] [arguments]  1. If vim was built with |+autocmd|, all relevant
438                            |QuickFixCmdPre| autocommands are executed.
439                         2. If the 'autowrite' option is on, write any changed
440                            buffers
441                         3. An errorfile name is made from 'makeef'.  If
442                            'makeef' doesn't contain "##", and a file with this
443                            name already exists, it is deleted.
444                         4. The program given with the 'makeprg' option is
445                            started (default "make") with the optional
446                            [arguments] and the output is saved in the
447                            errorfile (for Unix it is also echoed on the
448                            screen).
449                         5. The errorfile is read using 'errorformat'.
450                         6. If vim was built with |+autocmd|, all relevant
451                            |QuickFixCmdPost| autocommands are executed.
452                            See example below.
453                         7. If [!] is not given the first error is jumped to.
454                         8. The errorfile is deleted.
455                         9. You can now move through the errors with commands
456                            like |:cnext| and |:cprevious|, see above.
457                         This command does not accept a comment, any "
458                         characters are considered part of the arguments.
460                                                         *:lmak* *:lmake*
461 :lmak[e][!] [arguments]
462                         Same as ":make", except the location list for the
463                         current window is used instead of the quickfix list.
465 The ":make" command executes the command given with the 'makeprg' option.
466 This is done by passing the command to the shell given with the 'shell'
467 option.  This works almost like typing
469         ":!{makeprg} [arguments] {shellpipe} {errorfile}".
471 {makeprg} is the string given with the 'makeprg' option.  Any command can be
472 used, not just "make".  Characters '%' and '#' are expanded as usual on a
473 command-line.  You can use "%<" to insert the current file name without
474 extension, or "#<" to insert the alternate file name without extension, for
475 example: >
476    :set makeprg=make\ #<.o
478 [arguments] is anything that is typed after ":make".
479 {shellpipe} is the 'shellpipe' option.
480 {errorfile} is the 'makeef' option, with ## replaced to make it unique.
482 The placeholder "$*" can be used for the argument list in {makeprog} if the
483 command needs some additional characters after its arguments.  The $* is
484 replaced then by all arguments.  Example: >
485    :set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}
486 or simpler >
487    :let &mp = 'latex \\nonstopmode \\input\{$*}'
488 "$*" can be given multiple times, for example: >
489    :set makeprg=gcc\ -o\ $*\ $*
491 The 'shellpipe' option defaults to ">" for the Amiga, MS-DOS and Win32.  This
492 means that the output of the compiler is saved in a file and not shown on the
493 screen directly.  For Unix "| tee" is used.  The compiler output is shown on
494 the screen and saved in a file the same time.  Depending on the shell used
495 "|& tee" or "2>&1| tee" is the default, so stderr output will be included.
497 If 'shellpipe' is empty, the {errorfile} part will be omitted.  This is useful
498 for compilers that write to an errorfile themselves (e.g., Manx's Amiga C).
501 Using QuickFixCmdPost to fix the encoding ~
503 It may be that 'encoding' is set to an encoding that differs from the messages
504 your build program produces.  This example shows how to fix this after Vim has
505 read the error messages: >
507         function QfMakeConv()
508            let qflist = getqflist()
509            for i in qflist
510               let i.text = iconv(i.text, "cp936", "utf-8")
511            endfor
512            call setqflist(qflist)
513         endfunction
515         au QuickfixCmdPost make call QfMakeConv()
517 (Example by Faque Cheng)
519 ==============================================================================
520 5. Using :vimgrep and :grep                             *grep* *lid*
522 Vim has two ways to find matches for a pattern: Internal and external.  The
523 advantage of the internal grep is that it works on all systems and uses the
524 powerful Vim search patterns.  An external grep program can be used when the
525 Vim grep does not do what you want.
527 The internal method will be slower, because files are read into memory.  The
528 advantages are:
529 - Line separators and encoding are automatically recognized, as if a file is
530   being edited.
531 - Uses Vim search patterns.  Multi-line patterns can be used.
532 - When plugins are enabled: compressed and remote files can be searched.
533         |gzip| |netrw|
535 To be able to do this Vim loads each file as if it is being edited.  When
536 there is no match in the file the associated buffer is wiped out again.  The
537 'hidden' option is ignored here to avoid running out of memory or file
538 descriptors when searching many files.  However, when the |:hide| command
539 modifier is used the buffers are kept loaded.  This makes following searches
540 in the same files a lot faster.
543 5.1 using Vim's internal grep
545                                         *:vim* *:vimgrep* *E682* *E683*
546 :vim[grep][!] /{pattern}/[g][j] {file} ...
547                         Search for {pattern} in the files {file} ... and set
548                         the error list to the matches.
549                         Without the 'g' flag each line is added only once.
550                         With 'g' every match is added.
552                         {pattern} is a Vim search pattern.  Instead of
553                         enclosing it in / any non-ID character (see
554                         |'isident'|) can be used, so long as it does not
555                         appear in {pattern}.
556                         'ignorecase' applies.  To overrule it put |/\c| in the
557                         pattern to ignore case or |/\C| to match case.
558                         'smartcase' is not used.
560                         When a number is put before the command this is used
561                         as the maximum number of matches to find.  Use
562                         ":1vimgrep pattern file" to find only the first.
563                         Useful if you only want to check if there is a match
564                         and quit quickly when it's found.
566                         Without the 'j' flag Vim jumps to the first match.
567                         With 'j' only the quickfix list is updated.
568                         With the [!] any changes in the current buffer are
569                         abandoned.
571                         Every second or so the searched file name is displayed
572                         to give you an idea of the progress made.
573                         Examples: >
574                                 :vimgrep /an error/ *.c
575                                 :vimgrep /\<FileName\>/ *.h include/*
576                                 :vimgrep /myfunc/ **/*.c
577 <                       For the use of "**" see |starstar-wildcard|.
579 :vim[grep][!] {pattern} {file} ...
580                         Like above, but instead of enclosing the pattern in a
581                         non-ID character use a white-separated pattern.  The
582                         pattern must start with an ID character.
583                         Example: >
584                                 :vimgrep Error *.c
586                                                         *:lv* *:lvimgrep*
587 :lv[imgrep][!] /{pattern}/[g][j] {file} ...
588 :lv[imgrep][!] {pattern} {file} ...
589                         Same as ":vimgrep", except the location list for the
590                         current window is used instead of the quickfix list.
592                                                 *:vimgrepa* *:vimgrepadd*
593 :vimgrepa[dd][!] /{pattern}/[g][j] {file} ...
594 :vimgrepa[dd][!] {pattern} {file} ...
595                         Just like ":vimgrep", but instead of making a new list
596                         of errors the matches are appended to the current
597                         list.
599                                                 *:lvimgrepa* *:lvimgrepadd*
600 :lvimgrepa[dd][!] /{pattern}/[g][j] {file} ...
601 :lvimgrepa[dd][!] {pattern} {file} ...
602                         Same as ":vimgrepadd", except the location list for
603                         the current window is used instead of the quickfix
604                         list.
606 5.2 External grep
608 Vim can interface with "grep" and grep-like programs (such as the GNU
609 id-utils) in a similar way to its compiler integration (see |:make| above).
611 [Unix trivia: The name for the Unix "grep" command comes from ":g/re/p", where
612 "re" stands for Regular Expression.]
614                                                             *:gr* *:grep*
615 :gr[ep][!] [arguments]  Just like ":make", but use 'grepprg' instead of
616                         'makeprg' and 'grepformat' instead of 'errorformat'.
617                         When 'grepprg' is "internal" this works like
618                         |:vimgrep|.  Note that the pattern needs to be
619                         enclosed in separator characters then.
621                                                             *:lgr* *:lgrep*
622 :lgr[ep][!] [arguments] Same as ":grep", except the location list for the
623                         current window is used instead of the quickfix list.
625                                                         *:grepa* *:grepadd*
626 :grepa[dd][!] [arguments]
627                         Just like ":grep", but instead of making a new list of
628                         errors the matches are appended to the current list.
629                         Example: >
630                                 :grep nothing %
631                                 :bufdo grepadd! something %
632 <                       The first command makes a new error list which is
633                         empty.  The second command executes "grepadd" for each
634                         listed buffer.  Note the use of ! to avoid that
635                         ":grepadd" jumps to the first error, which is not
636                         allowed with |:bufdo|.
638                                                         *:lgrepa* *:lgrepadd*
639 :lgrepa[dd][!] [arguments]
640                         Same as ":grepadd", except the location list for the
641                         current window is used instead of the quickfix list.
643 5.3 Setting up external grep
645 If you have a standard "grep" program installed, the :grep command may work
646 well with the defaults.  The syntax is very similar to the standard command: >
648         :grep foo *.c
650 Will search all files with the .c extension for the substring "foo".  The
651 arguments to :grep are passed straight to the "grep" program, so you can use
652 whatever options your "grep" supports.
654 By default, :grep invokes grep with the -n option (show file and line
655 numbers).  You can change this with the 'grepprg' option.  You will need to set
656 'grepprg' if:
658 a)      You are using a program that isn't called "grep"
659 b)      You have to call grep with a full path
660 c)      You want to pass other options automatically (e.g. case insensitive
661         search.)
663 Once "grep" has executed, Vim parses the results using the 'grepformat'
664 option.  This option works in the same way as the 'errorformat' option - see
665 that for details.  You may need to change 'grepformat' from the default if
666 your grep outputs in a non-standard format, or you are using some other
667 program with a special format.
669 Once the results are parsed, Vim loads the first file containing a match and
670 jumps to the appropriate line, in the same way that it jumps to a compiler
671 error in |quickfix| mode.  You can then use the |:cnext|, |:clist|, etc.
672 commands to see the other matches.
675 5.4 Using :grep with id-utils
677 You can set up :grep to work with the GNU id-utils like this: >
679         :set grepprg=lid\ -Rgrep\ -s
680         :set grepformat=%f:%l:%m
682 then >
683         :grep (regexp)
685 works just as you'd expect.
686 (provided you remembered to mkid first :)
689 5.5 Browsing source code with :vimgrep or :grep
691 Using the stack of error lists that Vim keeps, you can browse your files to
692 look for functions and the functions they call.  For example, suppose that you
693 have to add an argument to the read_file() function.  You enter this command: >
695         :vimgrep /\<read_file\>/ *.c
697 You use ":cn" to go along the list of matches and add the argument.  At one
698 place you have to get the new argument from a higher level function msg(), and
699 need to change that one too.  Thus you use: >
701         :vimgrep /\<msg\>/ *.c
703 While changing the msg() functions, you find another function that needs to
704 get the argument from a higher level.  You can again use ":vimgrep" to find
705 these functions.  Once you are finished with one function, you can use >
707         :colder
709 to go back to the previous one.
711 This works like browsing a tree: ":vimgrep" goes one level deeper, creating a
712 list of branches.  ":colder" goes back to the previous level.  You can mix
713 this use of ":vimgrep" and "colder" to browse all the locations in a tree-like
714 way.  If you do this consistently, you will find all locations without the
715 need to write down a "todo" list.
717 =============================================================================
718 6. Selecting a compiler                                 *compiler-select*
720                                                 *:comp* *:compiler* *E666*
721 :comp[iler][!] {name}           Set options to work with compiler {name}.
722                                 Without the "!" options are set for the
723                                 current buffer.  With "!" global options are
724                                 set.
725                                 If you use ":compiler foo" in "file.foo" and
726                                 then ":compiler! bar" in another buffer, Vim
727                                 will keep on using "foo" in "file.foo".
728                                 {not available when compiled without the
729                                 |+eval| feature}
732 The Vim plugins in the "compiler" directory will set options to use the
733 selected compiler.  For ":compiler" local options are set, for ":compiler!"
734 global options.
735                                                         *current_compiler*
736 To support older Vim versions, the plugins always use "current_compiler" and
737 not "b:current_compiler".  What the command actually does is the following:
739 - Delete the "current_compiler" and "b:current_compiler" variables.
740 - Define the "CompilerSet" user command.  With "!" it does ":set", without "!"
741   it does ":setlocal".
742 - Execute ":runtime! compiler/{name}.vim".  The plugins are expected to set
743   options with "CompilerSet" and set the "current_compiler" variable to the
744   name of the compiler.
745 - Delete the "CompilerSet" user command.
746 - Set "b:current_compiler" to the value of "current_compiler".
747 - Without "!" the old value of "current_compiler" is restored.
750 For writing a compiler plugin, see |write-compiler-plugin|.
753 GCC                                     *quickfix-gcc*  *compiler-gcc*
755 There's one variable you can set for the GCC compiler:
757 g:compiler_gcc_ignore_unmatched_lines
758                                 Ignore lines that don't match any patterns
759                                 defined for GCC.  Useful if output from
760                                 commands run from make are generating false
761                                 positives.
764 MANX AZTEC C                            *quickfix-manx* *compiler-manx*
766 To use Vim with Manx's Aztec C compiler on the Amiga you should do the
767 following:
768 - Set the CCEDIT environment variable with the command: >
769         mset "CCEDIT=vim -q"
770 - Compile with the -qf option.  If the compiler finds any errors, Vim is
771   started and the cursor is positioned on the first error.  The error message
772   will be displayed on the last line.  You can go to other errors with the
773   commands mentioned above.  You can fix the errors and write the file(s).
774 - If you exit Vim normally the compiler will re-compile the same file.  If you
775   exit with the :cq command, the compiler will terminate.  Do this if you
776   cannot fix the error, or if another file needs to be compiled first.
778 There are some restrictions to the Quickfix mode on the Amiga.  The
779 compiler only writes the first 25 errors to the errorfile (Manx's
780 documentation does not say how to get more).  If you want to find the others,
781 you will have to fix a few errors and exit the editor.  After recompiling,
782 up to 25 remaining errors will be found.
784 If Vim was started from the compiler, the :sh and some :!  commands will not
785 work, because Vim is then running in the same process as the compiler and
786 stdin (standard input) will not be interactive.
789 PERL                                    *quickfix-perl* *compiler-perl*
791 The Perl compiler plugin doesn't actually compile, but invokes Perl's internal
792 syntax checking feature and parses the output for possible errors so you can
793 correct them in quick-fix mode.
795 Warnings are forced regardless of "no warnings" or "$^W = 0" within the file
796 being checked.  To disable this set g:perl_compiler_force_warnings to a zero
797 value.  For example: >
798         let g:perl_compiler_force_warnings = 0
801 PYUNIT COMPILER                                         *compiler-pyunit*
803 This is not actually a compiler, but a unit testing framework for the
804 Python language.  It is included into standard Python distribution
805 starting from version 2.0.  For older versions, you can get it from
806 http://pyunit.sourceforge.net.
808 When you run your tests with the help of the framework, possible errors
809 are parsed by Vim and presented for you in quick-fix mode.
811 Unfortunately, there is no standard way to run the tests.
812 The alltests.py script seems to be used quite often, that's all.
813 Useful values for the 'makeprg' options therefore are:
814  setlocal makeprg=./alltests.py " Run a testsuite
815  setlocal makeprg=python %      " Run a single testcase
817 Also see http://vim.sourceforge.net/tip_view.php?tip_id=280.
820 TEX COMPILER                                            *compiler-tex*
822 Included in the distribution compiler for TeX ($VIMRUNTIME/compiler/tex.vim)
823 uses make command if possible.  If the compiler finds a file named "Makefile"
824 or "makefile" in the current directory, it supposes that you want to process
825 your *TeX files with make, and the makefile does the right work.  In this case
826 compiler sets 'errorformat' for *TeX output and leaves 'makeprg' untouched.  If
827 neither "Makefile" nor "makefile" is found, the compiler will not use make.
828 You can force the compiler to ignore makefiles by defining
829 b:tex_ignore_makefile or g:tex_ignore_makefile variable (they are checked for
830 existence only).
832 If the compiler chose not to use make, it need to choose a right program for
833 processing your input.  If b:tex_flavor or g:tex_flavor (in this precedence)
834 variable exists, it defines TeX flavor for :make (actually, this is the name
835 of executed command), and if both variables do not exist, it defaults to
836 "latex".  For example, while editing chapter2.tex \input-ed from mypaper.tex
837 written in AMS-TeX: >
839         :let b:tex_flavor = 'amstex'
840         :compiler tex
841 <       [editing...] >
842         :make mypaper
844 Note that you must specify a name of the file to process as an argument (to
845 process the right file when editing \input-ed or \include-ed file; portable
846 solution for substituting % for no arguments is welcome).  This is not in the
847 semantics of make, where you specify a target, not source, but you may specify
848 filename without extension ".tex" and mean this as "make filename.dvi or
849 filename.pdf or filename.some_result_extension according to compiler".
851 Note: tex command line syntax is set to usable both for MikTeX (suggestion
852 by Srinath Avadhanula) and teTeX (checked by Artem Chuprina).  Suggestion
853 from |errorformat-LaTeX| is too complex to keep it working for different
854 shells and OSes and also does not allow to use other available TeX options,
855 if any.  If your TeX doesn't support "-interaction=nonstopmode", please
856 report it with different means to express \nonstopmode from the command line.
858 =============================================================================
859 7. The error format                                     *error-file-format*
861                                         *errorformat* *E372* *E373* *E374*
862                                                 *E375* *E376* *E377* *E378*
863 The 'errorformat' option specifies a list of formats that are recognized.  The
864 first format that matches with an error message is used.  You can add several
865 formats for different messages your compiler produces, or even entries for
866 multiple compilers.  See |efm-entries|.
868 Each entry in 'errorformat' is a scanf-like string that describes the format.
869 First, you need to know how scanf works.  Look in the documentation of your
870 C compiler.  Below you find the % items that Vim understands.  Others are
871 invalid.
873 Special characters in 'errorformat' are comma and backslash.  See
874 |efm-entries| for how to deal with them.  Note that a literal "%" is matched
875 by "%%", thus it is not escaped with a backslash.
877 Note: By default the difference between upper and lowercase is ignored.  If
878 you want to match case, add "\C" to the pattern |/\C|.
881 Basic items
883         %f              file name (finds a string)
884         %l              line number (finds a number)
885         %c              column number (finds a number representing character
886                         column of the error, (1 <tab> == 1 character column))
887         %v              virtual column number (finds a number representing
888                         screen column of the error (1 <tab> == 8 screen
889                         columns))
890         %t              error type (finds a single character)
891         %n              error number (finds a number)
892         %m              error message (finds a string)
893         %r              matches the "rest" of a single-line file message %O/P/Q
894         %p              pointer line (finds a sequence of '-', '.' or ' ' and
895                         uses the length for the column number)
896         %*{conv}        any scanf non-assignable conversion
897         %%              the single '%' character
898         %s              search text (finds a string)
900 The "%f" conversion may depend on the current 'isfname' setting.  "~/" is
901 expanded to the home directory and environment variables are expanded.
903 The "%f" and "%m" conversions have to detect the end of the string.  This
904 normally happens by matching following characters and items.  When nothing is
905 following the rest of the line is matched.  If "%f" is followed by a '%' or a
906 backslash, it will look for a sequence of 'isfname' characters.
908 On MS-DOS, MS-Windows and OS/2 a leading "C:" will be included in "%f", even
909 when using "%f:".  This means that a file name which is a single alphabetical
910 letter will not be detected.
912 The "%p" conversion is normally followed by a "^".  It's used for compilers
913 that output a line like: >
914             ^
915 or >
916    ---------^
917 to indicate the column of the error.  This is to be used in a multi-line error
918 message.  See |errorformat-javac| for a  useful example.
920 The "%s" conversion specifies the text to search for to locate the error line.
921 The text is used as a literal string.  The anchors "^" and "$" are added to
922 the text to locate the error line exactly matching the search text and the
923 text is prefixed with the "\V" atom to make it "very nomagic".  The "%s"
924 conversion can be used to locate lines without a line number in the error
925 output.  Like the output of the "grep" shell command.
926 When the pattern is present the line number will not be used.
928 Changing directory
930 The following uppercase conversion characters specify the type of special
931 format strings.  At most one of them may be given as a prefix at the begin
932 of a single comma-separated format pattern.
933 Some compilers produce messages that consist of directory names that have to
934 be prepended to each file name read by %f (example: GNU make).  The following
935 codes can be used to scan these directory names; they will be stored in an
936 internal directory stack.                                       *E379*
937         %D              "enter directory" format string; expects a following
938                           %f that finds the directory name
939         %X              "leave directory" format string; expects following %f
941 When defining an "enter directory" or "leave directory" format, the "%D" or
942 "%X" has to be given at the start of that substring.  Vim tracks the directory
943 changes and prepends the current directory to each erroneous file found with a
944 relative path.  See |quickfix-directory-stack| for details, tips and
945 limitations.
948 Multi-line messages                             *errorformat-multi-line*
950 It is possible to read the output of programs that produce multi-line
951 messages, i.e. error strings that consume more than one line.  Possible
952 prefixes are:
953         %E              start of a multi-line error message
954         %W              start of a multi-line warning message
955         %I              start of a multi-line informational message
956         %A              start of a multi-line message (unspecified type)
957         %>              for next line start with current pattern again |efm-%>|
958         %C              continuation of a multi-line message
959         %Z              end of a multi-line message
960 These can be used with '+' and '-', see |efm-ignore| below.
962 Using "\n" in the pattern won't work to match multi-line messages.
964 Example: Your compiler happens to write out errors in the following format
965 (leading line numbers not being part of the actual output):
967      1  Error 275 ~
968      2  line 42 ~
969      3  column 3 ~
970      4  ' ' expected after '--' ~
972 The appropriate error format string has to look like this: >
973    :set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
975 And the |:clist| error message generated for this error is:
977  1:42 col 3 error 275:  ' ' expected after '--'
979 Another example: Think of a Python interpreter that produces the following
980 error message (line numbers are not part of the actual output):
982      1  ==============================================================
983      2  FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)
984      3  --------------------------------------------------------------
985      4  Traceback (most recent call last):
986      5    File "unittests/dbfacadeTest.py", line 89, in testFoo
987      6      self.assertEquals(34, dtid)
988      7    File "/usr/lib/python2.2/unittest.py", line 286, in
989      8   failUnlessEqual
990      9      raise self.failureException, \
991     10  AssertionError: 34 != 33
992     11
993     12  --------------------------------------------------------------
994     13  Ran 27 tests in 0.063s
996 Say you want |:clist| write the relevant information of this message only,
997 namely:
998  5 unittests/dbfacadeTest.py:89:  AssertionError: 34 != 33
1000 Then the error format string could be defined as follows: >
1001   :set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
1003 Note that the %C string is given before the %A here: since the expression
1004 ' %.%#' (which stands for the regular expression ' .*') matches every line
1005 starting with a space, followed by any characters to the end of the line,
1006 it also hides line 7 which would trigger a separate error message otherwise.
1007 Error format strings are always parsed pattern by pattern until the first
1008 match occurs.
1009                                                         *efm-%>*
1010 The %> item can be used to avoid trying patterns that appear earlier in
1011 'errorformat'.  This is useful for patterns that match just about anything.
1012 For example, if the error looks like this:
1014         Error in line 123 of foo.c: ~
1015         unknown variable "i" ~
1017 This can be found with: >
1018         :set efm=xxx,%E%>Error in line %l of %f:,%Z%m
1019 Where "xxx" has a pattern that would also match the second line.
1021 Important: There is no memory of what part of the errorformat matched before;
1022 every line in the error file gets a complete new run through the error format
1023 lines.  For example, if one has: >
1024   setlocal efm=aa,bb,cc,dd,ee
1025 Where aa, bb, etc. are error format strings.  Each line of the error file will
1026 be matched to the pattern aa, then bb, then cc, etc.  Just because cc matched
1027 the previous error line does _not_ mean that dd will be tried first on the
1028 current line, even if cc and dd are multi-line errorformat strings.
1032 Separate file name                      *errorformat-separate-filename*
1034 These prefixes are useful if the file name is given once and multiple messages
1035 follow that refer to this file name.
1036         %O              single-line file message: overread the matched part
1037         %P              single-line file message: push file %f onto the stack
1038         %Q              single-line file message: pop the last file from stack
1040 Example: Given a compiler that produces the following error logfile (without
1041 leading line numbers):
1043      1  [a1.tt]
1044      2  (1,17)  error: ';' missing
1045      3  (21,2)  warning: variable 'z' not defined
1046      4  (67,3)  error: end of file found before string ended
1047      5
1048      6  [a2.tt]
1049      7
1050      8  [a3.tt]
1051      9  NEW compiler v1.1
1052     10  (2,2)   warning: variable 'x' not defined
1053     11  (67,3)  warning: 's' already defined
1055 This logfile lists several messages for each file enclosed in [...] which are
1056 properly parsed by an error format like this: >
1057   :set efm=%+P[%f],(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%-Q
1059 A call of |:clist| writes them accordingly with their correct filenames:
1061   2 a1.tt:1 col 17 error: ';' missing
1062   3 a1.tt:21 col 2 warning: variable 'z' not defined
1063   4 a1.tt:67 col 3 error: end of file found before string ended
1064   8 a3.tt:2 col 2 warning: variable 'x' not defined
1065   9 a3.tt:67 col 3 warning: 's' already defined
1067 Unlike the other prefixes that all match against whole lines, %P, %Q and %O
1068 can be used to match several patterns in the same line.  Thus it is possible
1069 to parse even nested files like in the following line:
1070   {"file1" {"file2" error1} error2 {"file3" error3 {"file4" error4 error5}}}
1071 The %O then parses over strings that do not contain any push/pop file name
1072 information.  See |errorformat-LaTeX| for an extended example.
1075 Ignoring and using whole messages                       *efm-ignore*
1077 The codes '+' or '-' can be combined with the uppercase codes above; in that
1078 case they have to precede the letter, e.g. '%+A' or '%-G':
1079         %-              do not include the matching multi-line in any output
1080         %+              include the whole matching line in the %m error string
1082 One prefix is only useful in combination with '+' or '-', namely %G.  It parses
1083 over lines containing general information like compiler version strings or
1084 other headers that can be skipped.
1085         %-G             ignore this message
1086         %+G             general message
1089 Pattern matching
1091 The scanf()-like "%*[]" notation is supported for backward-compatibility
1092 with previous versions of Vim.  However, it is also possible to specify
1093 (nearly) any Vim supported regular expression in format strings.
1094 Since meta characters of the regular expression language can be part of
1095 ordinary matching strings or file names (and therefore internally have to
1096 be escaped), meta symbols have to be written with leading '%':
1097         %\              The single '\' character.  Note that this has to be
1098                         escaped ("%\\") in ":set errorformat=" definitions.
1099         %.              The single '.' character.
1100         %#              The single '*'(!) character.
1101         %^              The single '^' character.  Note that this is not
1102                         useful, the pattern already matches start of line.
1103         %$              The single '$' character.  Note that this is not
1104                         useful, the pattern already matches end of line.
1105         %[              The single '[' character for a [] character range.
1106         %~              The single '~' character.
1107 When using character classes in expressions (see |/\i| for an overview),
1108 terms containing the "\+" quantifier can be written in the scanf() "%*"
1109 notation.  Example: "%\\d%\\+" ("\d\+", "any number") is equivalent to "%*\\d".
1110 Important note: The \(...\) grouping of sub-matches can not be used in format
1111 specifications because it is reserved for internal conversions.
1114 Multiple entries in 'errorformat'                       *efm-entries*
1116 To be able to detect output from several compilers, several format patterns
1117 may be put in 'errorformat', separated by commas (note: blanks after the comma
1118 are ignored).  The first pattern that has a complete match is used.  If no
1119 match is found, matching parts from the last one will be used, although the
1120 file name is removed and the error message is set to the whole message.  If
1121 there is a pattern that may match output from several compilers (but not in a
1122 right way), put it after one that is more restrictive.
1124 To include a comma in a pattern precede it with a backslash (you have to type
1125 two in a ":set" command).  To include a backslash itself give two backslashes
1126 (you have to type four in a ":set" command).  You also need to put a backslash
1127 before a space for ":set".
1130 Valid matches                                           *quickfix-valid*
1132 If a line does not completely match one of the entries in 'errorformat', the
1133 whole line is put in the error message and the entry is marked "not valid"
1134 These lines are skipped with the ":cn" and ":cp" commands (unless there is
1135 no valid line at all).  You can use ":cl!" to display all the error messages.
1137 If the error format does not contain a file name Vim cannot switch to the
1138 correct file.  You will have to do this by hand.
1141 Examples
1143 The format of the file from the Amiga Aztec compiler is:
1145         filename>linenumber:columnnumber:errortype:errornumber:errormessage
1147         filename        name of the file in which the error was detected
1148         linenumber      line number where the error was detected
1149         columnnumber    column number where the error was detected
1150         errortype       type of the error, normally a single 'E' or 'W'
1151         errornumber     number of the error (for lookup in the manual)
1152         errormessage    description of the error
1154 This can be matched with this 'errorformat' entry:
1155         %f>%l:%c:%t:%n:%m
1157 Some examples for C compilers that produce single-line error outputs:
1158 %f:%l:\ %t%*[^0123456789]%n:\ %m        for Manx/Aztec C error messages
1159                                         (scanf() doesn't understand [0-9])
1160 %f\ %l\ %t%*[^0-9]%n:\ %m               for SAS C
1161 \"%f\"\\,%*[^0-9]%l:\ %m                for generic C compilers
1162 %f:%l:\ %m                              for GCC
1163 %f:%l:\ %m,%Dgmake[%*\\d]:\ Entering\ directory\ `%f',
1164 %Dgmake[%*\\d]:\ Leaving\ directory\ `%f'
1165                                         for GCC with gmake (concat the lines!)
1166 %f(%l)\ :\ %*[^:]:\ %m                  old SCO C compiler (pre-OS5)
1167 %f(%l)\ :\ %t%*[^0-9]%n:\ %m            idem, with error type and number
1168 %f:%l:\ %m,In\ file\ included\ from\ %f:%l:,\^I\^Ifrom\ %f:%l%m
1169                                         for GCC, with some extras
1171 Extended examples for the handling of multi-line messages are given below,
1172 see |errorformat-Jikes| and |errorformat-LaTeX|.
1174 Note the backslash in front of a space and double quote.  It is required for
1175 the :set command.  There are two backslashes in front of a comma, one for the
1176 :set command and one to avoid recognizing the comma as a separator of error
1177 formats.
1180 Filtering messages
1182 If you have a compiler that produces error messages that do not fit in the
1183 format string, you could write a program that translates the error messages
1184 into this format.  You can use this program with the ":make" command by
1185 changing the 'makeprg' option.  For example: >
1186    :set mp=make\ \\\|&\ error_filter
1187 The backslashes before the pipe character are required to avoid it to be
1188 recognized as a command separator.  The backslash before each space is
1189 required for the set command.
1191 =============================================================================
1192 8. The directory stack                          *quickfix-directory-stack*
1194 Quickfix maintains a stack for saving all used directories parsed from the
1195 make output.  For GNU-make this is rather simple, as it always prints the
1196 absolute path of all directories it enters and leaves.  Regardless if this is
1197 done via a 'cd' command in the makefile or with the parameter "-C dir" (change
1198 to directory before reading the makefile).  It may be useful to use the switch
1199 "-w" to force GNU-make to print out the working directory before and after
1200 processing.
1202 Maintaining the correct directory is more complicated if you don't use
1203 GNU-make.  AIX-make for example doesn't print any information about its
1204 working directory.  Then you need to enhance the makefile.  In the makefile of
1205 LessTif there is a command which echoes "Making {target} in {dir}".  The
1206 special problem here is that it doesn't print informations on leaving the
1207 directory and that it doesn't print the absolute path.
1209 To solve the problem with relative paths and missing "leave directory"
1210 messages Vim uses following algorithm:
1212 1) Check if the given directory is a subdirectory of the current directory.
1213    If this is true, store it as the current directory.
1214 2) If it is not a subdir of the current directory, try if this is a
1215    subdirectory of one of the upper directories.
1216 3) If the directory still isn't found, it is assumed to be a subdirectory
1217    of Vim's current directory.
1219 Additionally it is checked for every file, if it really exists in the
1220 identified directory.  If not, it is searched in all other directories of the
1221 directory stack (NOT the directory subtree!).  If it is still not found, it is
1222 assumed that it is in Vim's current directory.
1224 There are limitation in this algorithm.  This examples assume that make just
1225 prints information about entering a directory in the form "Making all in dir".
1227 1) Assume you have following directories and files:
1228    ./dir1
1229    ./dir1/file1.c
1230    ./file1.c
1232    If make processes the directory "./dir1" before the current directory and
1233    there is an error in the file "./file1.c", you will end up with the file
1234    "./dir1/file.c" loaded by Vim.
1236    This can only be solved with a "leave directory" message.
1238 2) Assume you have following directories and files:
1239    ./dir1
1240    ./dir1/dir2
1241    ./dir2
1243    You get the following:
1245    Make output                    Directory interpreted by Vim
1246    ------------------------       ----------------------------
1247    Making all in dir1             ./dir1
1248    Making all in dir2             ./dir1/dir2
1249    Making all in dir2             ./dir1/dir2
1251    This can be solved by printing absolute directories in the "enter directory"
1252    message or by printing "leave directory" messages..
1254 To avoid this problems, ensure to print absolute directory names and "leave
1255 directory" messages.
1257 Examples for Makefiles:
1259 Unix:
1260     libs:
1261             for dn in $(LIBDIRS); do                            \
1262                 (cd $$dn; echo "Entering dir '$$(pwd)'"; make); \
1263                 echo "Leaving dir";                             \
1264             done
1267     %DEntering\ dir\ '%f',%XLeaving\ dir
1268 to your 'errorformat' to handle the above output.
1270 Note that Vim doesn't check if the directory name in a "leave directory"
1271 messages is the current directory.  This is why you could just use the message
1272 "Leaving dir".
1274 =============================================================================
1275 9. Specific error file formats                  *errorformats*
1277                                                 *errorformat-Jikes*
1278 Jikes(TM), a source-to-bytecode Java compiler published by IBM Research,
1279 produces simple multi-line error messages.
1281 An 'errorformat' string matching the produced messages is shown below.
1282 The following lines can be placed in the user's |vimrc| to overwrite Vim's
1283 recognized default formats, or see |:set+=| how to install this format
1284 additionally to the default. >
1286   :set efm=%A%f:%l:%c:%*\\d:%*\\d:,
1287         \%C%*\\s%trror:%m,
1288         \%+C%*[^:]%trror:%m,
1289         \%C%*\\s%tarning:%m,
1290         \%C%m
1292 Jikes(TM) produces a single-line error message when invoked with the option
1293 "+E", and can be matched with the following: >
1295   :setl efm=%f:%l:%v:%*\\d:%*\\d:%*\\s%m
1297                                                 *errorformat-javac*
1298 This 'errorformat' has been reported to work well for javac, which outputs a
1299 line with "^" to indicate the column of the error: >
1300   :setl efm=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
1301 or: >
1302   :setl efm=%A%f:%l:\ %m,%+Z%p^,%+C%.%#,%-G%.%#
1304 Here is an alternative from Michael F. Lamb for Unix that filters the errors
1305 first: >
1306   :setl errorformat=%Z%f:%l:\ %m,%A%p^,%-G%*[^sl]%.%#
1307   :setl makeprg=javac\ %\ 2>&1\ \\\|\ vim-javac-filter
1309 You need to put the following in "vim-javac-filter" somewhere in your path
1310 (e.g., in ~/bin) and make it executable: >
1311    #!/bin/sed -f
1312    /\^$/s/\t/\ /g;/:[0-9]\+:/{h;d};/^[ \t]*\^/G;
1314 In English, that sed script:
1315 - Changes single tabs to single spaces and
1316 - Moves the line with the filename, line number, error message to just after
1317   the pointer line. That way, the unused error text between doesn't break
1318   vim's notion of a "multi-line message" and also doesn't force us to include
1319   it as a "continuation of a multi-line message."
1321                                                 *errorformat-ant*
1322 For ant (http://jakarta.apache.org/) the above errorformat has to be modified
1323 to honour the leading [javac] in front of each javac output line: >
1324   :set efm=%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
1326 The 'errorformat' can also be configured to handle ant together with either
1327 javac or jikes.  If you're using jikes, you should tell ant to use jikes' +E
1328 command line switch which forces jikes to generate one-line error messages.
1329 This is what the second line (of a build.xml file) below does: >
1330   <property name = "build.compiler"       value = "jikes"/>
1331   <property name = "build.compiler.emacs" value = "true"/>
1333 The 'errorformat' which handles ant with both javac and jikes is: >
1334   :set efm=\ %#[javac]\ %#%f:%l:%c:%*\\d:%*\\d:\ %t%[%^:]%#:%m,
1335            \%A\ %#[javac]\ %f:%l:\ %m,%-Z\ %#[javac]\ %p^,%-C%.%#
1337                                                 *errorformat-jade*
1338 parsing jade (see http://www.jclark.com/) errors is simple: >
1339   :set efm=jade:%f:%l:%c:%t:%m
1341                                                 *errorformat-LaTeX*
1342 The following is an example how an 'errorformat' string can be specified
1343 for the (La)TeX typesetting system which displays error messages over
1344 multiple lines.  The output of ":clist" and ":cc" etc. commands displays
1345 multi-lines in a single line, leading white space is removed.
1346 It should be easy to adopt the above LaTeX errorformat to any compiler output
1347 consisting of multi-line errors.
1349 The commands can be placed in a |vimrc| file or some other Vim script file,
1350 e.g. a script containing LaTeX related stuff which is loaded only when editing
1351 LaTeX sources.
1352 Make sure to copy all lines of the example (in the given order), afterwards
1353 remove the comment lines.  For the '\' notation at the start of some lines see
1354 |line-continuation|.
1356                 First prepare 'makeprg' such that LaTeX will report multiple
1357                 errors; do not stop when the first error has occurred: >
1358  :set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}
1360                 Start of multi-line error messages: >
1361  :set efm=%E!\ LaTeX\ %trror:\ %m,
1362         \%E!\ %m,
1363 <               Start of multi-line warning messages; the first two also
1364                 include the line number.  Meaning of some regular expressions:
1365                   - "%.%#"  (".*")   matches a (possibly empty) string
1366                   - "%*\\d" ("\d\+") matches a number >
1367         \%+WLaTeX\ %.%#Warning:\ %.%#line\ %l%.%#,
1368         \%+W%.%#\ at\ lines\ %l--%*\\d,
1369         \%WLaTeX\ %.%#Warning:\ %m,
1370 <               Possible continuations of error/warning messages; the first
1371                 one also includes the line number: >
1372         \%Cl.%l\ %m,
1373         \%+C\ \ %m.,
1374         \%+C%.%#-%.%#,
1375         \%+C%.%#[]%.%#,
1376         \%+C[]%.%#,
1377         \%+C%.%#%[{}\\]%.%#,
1378         \%+C<%.%#>%.%#,
1379         \%C\ \ %m,
1380 <               Lines that match the following patterns do not contain any
1381                 important information; do not include them in messages: >
1382         \%-GSee\ the\ LaTeX%m,
1383         \%-GType\ \ H\ <return>%m,
1384         \%-G\ ...%.%#,
1385         \%-G%.%#\ (C)\ %.%#,
1386         \%-G(see\ the\ transcript%.%#),
1387 <               Generally exclude any empty or whitespace-only line from
1388                 being displayed: >
1389         \%-G\\s%#,
1390 <               The LaTeX output log does not specify the names of erroneous
1391                 source files per line; rather they are given globally,
1392                 enclosed in parentheses.
1393                 The following patterns try to match these names and store
1394                 them in an internal stack.  The patterns possibly scan over
1395                 the same input line (one after another), the trailing "%r"
1396                 conversion indicates the "rest" of the line that will be
1397                 parsed in the next go until the end of line is reached.
1399                 Overread a file name enclosed in '('...')'; do not push it
1400                 on a stack since the file apparently does not contain any
1401                 error: >
1402         \%+O(%f)%r,
1403 <               Push a file name onto the stack.  The name is given after '(': >
1404         \%+P(%f%r,
1405         \%+P\ %\\=(%f%r,
1406         \%+P%*[^()](%f%r,
1407         \%+P[%\\d%[^()]%#(%f%r,
1408 <               Pop the last stored file name when a ')' is scanned: >
1409         \%+Q)%r,
1410         \%+Q%*[^()])%r,
1411         \%+Q[%\\d%*[^()])%r
1413 Note that in some cases file names in the LaTeX output log cannot be parsed
1414 properly.  The parser might have been messed up by unbalanced parentheses
1415 then.  The above example tries to catch the most relevant cases only.
1416 You can customize the given setting to suit your own purposes, for example,
1417 all the annoying "Overfull ..." warnings could be excluded from being
1418 recognized as an error.
1419 Alternatively to filtering the LaTeX compiler output, it is also possible
1420 to directly read the *.log file that is produced by the [La]TeX compiler.
1421 This contains even more useful information about possible error causes.
1422 However, to properly parse such a complex file, an external filter should
1423 be used.  See the description further above how to make such a filter known
1424 by Vim.
1426                                                 *errorformat-Perl*
1427 In $VIMRUNTIME/tools you can find the efm_perl.pl script, which filters Perl
1428 error messages into a format that quickfix mode will understand.  See the
1429 start of the file about how to use it.  (This script is deprecated, see
1430 |compiler-perl|.)
1434  vim:tw=78:ts=8:ft=help:norl: