@@ -15,6 +15,7 @@ This subject is introduced in section |30.1| of the user manual.
15157. The error format | error-file-format |
16168. The directory stack | quickfix-directory-stack |
17179. Specific error file formats | errorformats |
18+ 10. Customizing the quickfix window | quickfix-window-function |
1819
1920The quickfix commands are not available when the | +quickfix | feature was
2021disabled at compile time.
@@ -1921,6 +1922,59 @@ error messages into a format that quickfix mode will understand. See the
19211922start of the file about how to use it. (This script is deprecated, see
19221923| compiler-perl | .)
19231924
1924-
1925+ =============================================================================
1926+ 10. Customizing the quickfix window *quickfix-window-function*
1927+
1928+ The default format for the lines displayed in the quickfix window and location
1929+ list window is:
1930+
1931+ <filename> | <lnum> col <col> | <text>
1932+
1933+ The values displayed in each line correspond to the "bufnr", "lnum", "col" and
1934+ "text" fields returned by the | getqflist() | function.
1935+
1936+ For some quickfix/location lists, the displayed text need to be customized.
1937+ For example, if only the filename is present for a quickfix entry, then the
1938+ two "|" field separator characters after the filename are not needed. Another
1939+ use case is to customize the path displayed for a filename. By default, the
1940+ complete path (which may be too long) is displayed for files which are not
1941+ under the current directory tree. The file path may need to be simplified to a
1942+ common parent directory.
1943+
1944+ The displayed text can be customized by setting the 'quickfixtextfunc' option
1945+ to a Vim function. This function will be called with a dict argument for
1946+ every entry in a quickfix or a location list. The dict argument will have the
1947+ following fields:
1948+
1949+ quickfix set to 1 when called for a quickfix list and 0 when called for
1950+ a location list.
1951+ id quickfix or location list identifier
1952+ idx index of the entry in the quickfix or location list
1953+
1954+ The function should return a single line of text to display in the quickfix
1955+ window for the entry identified by idx. The function can obtain information
1956+ about the current entry using the | getqflist() | function and specifying the
1957+ quickfix list identifier "id" and the entry index "idx".
1958+
1959+ If a quickfix or location list specific customization is needed, then the
1960+ 'quickfixtextfunc' attribute of the list can be set using the | setqflist() | or
1961+ | setloclist() | function. This overrides the global 'quickfixtextfunc' option.
1962+
1963+ The example below displays the list of old files (| v:oldfiles | ) in a quickfix
1964+ window. As there is no line, column number and error text information
1965+ associated with each entry, the 'quickfixtextfunc' function returns only the
1966+ filename.
1967+ Example: >
1968+ " create a quickfix list from v:oldfiles
1969+ call setqflist([], ' ', {'lines' : v:oldfiles, 'efm' : '%f',
1970+ \ 'quickfixtextfunc' : 'QfOldFiles'})
1971+ func QfOldFiles(info)
1972+ " get information about the specific quickfix entry
1973+ let e = getqflist({'id' : a:info.id, 'idx' : a:info.idx,
1974+ \ 'items' : 1}).items[0]
1975+ " return the simplified file name
1976+ return fnamemodify(bufname(e.bufnr), ':p:.')
1977+ endfunc
1978+ <
19251979
19261980 vim:tw=78:ts=8:noet:ft=help:norl:
0 commit comments