home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / unix / vim-6.2.tar.bz2 / vim-6.2.tar / vim62 / runtime / doc / quickfix.txt < prev    next >
Encoding:
Text File  |  2003-06-01  |  40.3 KB  |  985 lines

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