How to format Vim quickfix entries?

It is not possible to configure the way quickfix locations are displayed. It is only possible to specify how to interpret them via the errorformat option. However, one can use the conceal feature to hide filenames in the quickfix or a location list window.

The following commands enable concealing and define a syntax rule matching any text at the beginning of a line before the first | character.

:set conceallevel=2 concealcursor=nc
:syntax match qfFileName /^[^|]*/ transparent conceal

One can trigger these commands for every quickfix or location list window using an auto-command. Yet, it is not a good idea in general, since in most cases displaying filenames is a useful feature.

For the case presented in the question, it is better to make these customizations only for the newly collected location list. It requires opening the location list window first, though.

:lopen
:set conceallevel=2 concealcursor=nc
:syntax match qfFileName /^[^|]*/ transparent conceal

I ended up implementing this on plasticboy/vim-markdown on this PR (with GIF animation) using set modifiable + substitution instead of conceal with something along:

function! b:Markdown_Toc()
    silent lvimgrep '^#' %
    vertical lopen
    let &winwidth=(&columns/2)
    set modifiable
    %s/\v^([^|]*\|){2,2} #//
    for i in range(1, line('$'))
        let l:line = getline(i)
        let l:header = matchstr(l:line, '^#*')
        let l:length = len(l:header)
        let l:line = substitute(l:line, '\v^#*[ ]*', '', '')
        let l:line = substitute(l:line, '\v[ ]*#*$', '', '')
        let l:line = repeat(' ', (2 * l:length)) . l:line
        call setline(i, l:line)
    endfor
    set nomodified
    set nomodifiable
endfunction

But you might prefer:

Plugin 'plasticboy/vim-markdown'

It's up to you. =)

Screenshot:

enter image description here

Tags:

Vim