Say in vim, after :grep text *, then :copen, then cursor in a quickfix window, which has contents like below

some-very-very-very-long-path/file1.txt|1 col 46| some text
some-very-very-very-long-path/file2.txt|84 col 34| another text
some-very-very-very-long-path/file3.txt|243 col 29| yetanother text


How to conceal the filename and line column number at the beginning of each line?


You can use the conceal feature for this.

:syntax match ConcealedDetails /\v^[^|]*\|[^|]*\| / conceal
:set conceallevel=2
:set concealcursor=nvic

The first line sets up a syntax item to conceal anything that matches the regular expression.

The second line informs Vim that you want to hide any concealed items that don't have a replacement cchar set.

The third line makes it so that the text is always concealed, whatever mode you are in.

The regular expression I used presumes that your file names/paths won't ever contain a | character. If they do, you'll need to adjust your regular expression to account for this.

Presumably you won't want to type this in every time you want to use it, so you could set up a function that contains the commands and run it manually or from a mapping or user command, or you could set up the commands to run every time you open the quickfix window either with an autocommand or by using the after directory.

Further details:

  • :help conceal
  • :help 'conceallevel'
  • :help 'concealcursor'

according to quickfix.txt and the answer by Rich, following works:

au BufReadPost quickfix  setlocal modifiable
            \ | silent exe 'g/^/s/\v^[^|]*\|[^|]*\| //'
            \ | setlocal nomodifiable
  • 1
    Welcome to Vi and Vim! I'm not sure this uses conceal so much as actually removing the relevant characters? – D. Ben Knoble Mar 20 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.