A simplified variant of vim-addon-qf-layout.
- Format location like
grep -H
- Align start of contents from all files
- Sperate location and contents with
|
function! QuickFixFormat()
let qflist = map(getqflist(),
\ "extend(v:val, {'filename' : bufname(v:val.bufnr)})")
let prefix_len = max(map(copy(qflist),
\ "strchars(v:val.filename . ':' . v:val.lnum)"))
let fmt = '%-' . prefix_len . 's' . '%s'
setlocal modifiable
call setline('1', map(qflist,
\ "printf(fmt, v:val.filename . ':' . v:val.lnum, ' | ' . v:val.text)"))
setlocal nomodifiable nomodified
endfunction
augroup QuickFixFormat
autocmd!
autocmd BufReadPost quickfix
\ if !getwininfo(win_getid())[0]['loclist']
\ | call QuickFixFormat
\ | endif
augroup END
As an update Vim 8.2.0869
introduces the quickfixtextfunc
option which can be set to a function
intended to format the contents of the quickfix window. However this function
is called for each entry rather than the entire list. As such it is useless for
aligning text other than on predetermined fixed boundaries.