vim-qf icon indicating copy to clipboard operation
vim-qf copied to clipboard

Ordering the results so that the current file comes first.

Open romainl opened this issue 9 years ago • 2 comments

http://vi.stackexchange.com/questions/9436/calling-vimgrep-so-that-results-from-the-current-file-are-on-top

romainl avatar Sep 04 '16 08:09 romainl

That should be fairly easy:

function s:CurrentFirst(target)
    let curfile = expand('%')

    let errorsOnCurrent = filter(copy(target), 'bufname(v:val.bufnr) =~ ^' . curfile)
    let errorsOnOther = filter(copy(target), 'bufname(v:val.bufnr) !~ ^' . curfile)

    return errorsOnCurrent + errorsOnOther
endfunction

call setqflist(s:CurrentFirst(getqflist()))

Maybe with an option to disable sorting the current file first.

ntnn avatar Sep 04 '16 19:09 ntnn

The result looks a bit different, but it works quite well in both non-qf as well as qf-context. For now I've named the commands :Qf{C,L}sort, like the other global commands and added a buflocal command which executes either based on if it's a qf or loclist window.

ntnn avatar Sep 04 '16 22:09 ntnn