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?

4 Answers 4


You can use the conceal feature for this.

Add the following to the file ~/.vim/after/syntax/qf.vim (first creating the file if necessary):

syntax match ConcealedDetails /\v^[^|]*\|[^|]*\| / conceal
setlocal conceallevel=2
setlocal 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.

Further details:

  • This works but syntax highlighting in the qf buffer breaks. (i.e. filename part is no longer shown in different color). Any way to fix it?
    – balki
    Aug 18, 2023 at 21:08
  • nvm. not an issue if concealing entire path and line numbers. Added answer below to hide a prefix of the path. vi.stackexchange.com/a/42868
    – balki
    Aug 18, 2023 at 22:12

While the other answers here have all the necessary pointers ever needed, I think there is lacking a comprehensive solution IMHO.

Below is a ready-to-paste in your .vimrc (or equivalent)

au BufReadPost quickfix :call ConcealPath() 

function ConcealPath()
       syntax match ConcealedPath /\v^\/[^|]*\// conceal cchar=&
       setlocal conceallevel=2
       setlocal concealcursor=nvic
       setlocal nowrap 

function UnconcealPath()
       setlocal conceallevel=0
       setlocal wrap

More than being a comprehensive answer, it is a more general solution.

You are now equipped to hide similar "long paths" without any file-edits, any where in vim (not just in a quickfix window), using

:call ConcealPath()

and revert/unhide using

:call UnconcealPath()

NOTE-1: The use of set wrap and set nowrap is only for aesthetics that I liked in my usage

NOTE-2: You can also conveniently map your favourite keys to reduce typing in case you need frequently using the function calls

NOTE-3: All this works only when you notice +conceal is present in your :version (or vim --version from terminal). So -conceal will knock you off this deal. Neovim (nvim) on the other hand, will not suffer from this issue due to its philosophy of all-possible features always-on.

  • 1
    Thanks for the summary! A small nitpick that you don't need the :s inside autocmd and functions, only when using Ex commands interactively... So personally I'd recommend removing those.
    – filbranden
    May 20, 2021 at 23:54
  • 1
    @filbranden Done! May 21, 2021 at 0:44
  • I updated my answer to include complete instructions. Not sure why I didn't do so in the first place, as it's actually more concise this way, so thanks for nudging me into doing so! I like your idea of adding functions so you can toggle the behaviour. +1
    – Rich
    May 21, 2021 at 9:40

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

au BufReadPost quickfix  setlocal modifiable
            \ | silent exe 'g/^/s/\v^[^|]*\|[^|]*\| //'
            \ | setlocal nomodifiable
  • 2
    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, 2021 at 13:47

Hiding a known common prefix of the long path

syn match qfFileName "^[^|]*" nextgroup=qfSeparator contains=ConcealedDetails
syntax match ConcealedDetails /^.*my_projects_path/ conceal cchar=↭ contained

setlocal conceallevel=2                                                        
setlocal concealcursor=nvic                                                    

qfFileName is defined in $VIMRUNTIME/syntax/qf.vim. We are redefining to add that it could contain our ConecealedDetails matchgroup. Without this, the whole line will not be highlighted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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