I have a project that has a lot of warnings. I'm wondering (until I fix all the errors) how I can make my quickfix results more relevant?

My compiler script uses %t so it can differentiate errors from warnings:

CompilerSet errorformat&
CompilerSet errorformat^=%f(%l):\ %tarning\ C%n:\ %m
CompilerSet errorformat^=%f(%l):\ %trror\ C%n:\ %m

The two ideas I've thought of are:

  • list errors first
  • list files that aren't in my buffer list last

The second option seems pretty clever, but I'm not sure how to do it?

I assume getqflist(), modify the returned list, setqflist(). How would I sort the quickfix to show files in active buffers, files in loaded buffers, then unloaded files? Within each file, they should maintain the order given by the compiler. Ideally, entries that are not errors/warnings (have no file) maintain their position.

1 Answer 1


I came up with this solution and added it to my vim-fixquick plugin:

function! s:cmp(left, right) abort
    if a:left == a:right
        return 0
    elseif a:left < a:right
        return -1
    elseif a:left > a:right
        return 1

function! fixquick#sort#compare_qf_entries(left, right) abort
    if a:left.bufnr == 0 || a:right.bufnr == 0
        " Maintain order for unlisted
        return s:cmp(a:left.qforder, a:right.qforder)
    if a:left.type == 'e' && a:right.type == 'e'
        " Sort listed buffers first.
        return -1 * s:cmp(buflisted(a:left.bufnr), buflisted(a:right.bufnr))
    " Sort errors first.
    return -1 * s:cmp(a:left.type == 'e', a:right.type == 'e')

" Call to rearrange the quickfix:
" * errors first
" * buffers you've explicitly opened ('buflisted')
" It will also maintain the order of buffers that don't have an associated
" file, so if you log your compile command and a timestamp on completion,
" those will stay at the beginning and end.
function! fixquick#sort#sort_by_buffers() abort
    let qf = getqflist()
    for i in range(0, len(qf)-1)
        let qf[i].qforder = i
    let qf = qf->sort("fixquick#sort#compare_qf_entries")
    call setqflist(qf)

To automatically apply after :make completes:

au QuickfixCmdPost make call fixquick#sort#sort_by_buffers()

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.