vim-qf
vim-qf copied to clipboard
Ordering the results so that the current file comes first.
http://vi.stackexchange.com/questions/9436/calling-vimgrep-so-that-results-from-the-current-file-are-on-top
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.
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.