Sort QuickFix tool by filename.
David Blume

David Blume commited on 2021-09-24 12:32:25
Showing 1 changed files, with 17 additions and 1 deletions.

... ...
@@ -1,4 +1,4 @@
1
-" Version 2021-04-27.1 - Prefer local cscope.out database
1
+" Version 2021-09-24.1 - Sort Quickfix list by filename
2 2
 set nocompatible    " Use Vim defaults, forget compatibility with vi.
3 3
 set bs=2            " allow backspacing over everything in insert mode
4 4
 set wildmenu        " Allows command-line completion with tab
... ...
@@ -315,6 +315,22 @@ if has("cscope")
315 315
     set csverb
316 316
 endif
317 317
 
318
+" From https://stackoverflow.com/questions/15393301/how-to-automatically-sort-quickfix-entries-by-line-text-in-vim
319
+" :grep term %
320
+" :grep -r term path/
321
+" :cw
322
+" :ccl (or C-w,q)
323
+autocmd! QuickfixCmdPost * call SortQuickfix('QfStrCmp')
324
+
325
+function! SortQuickfix(fn)
326
+    call setqflist(sort(getqflist(), a:fn), 'r')
327
+endfunction
328
+
329
+function! QfStrCmp(e1, e2)
330
+    let [t1, t2] = [bufname(a:e1.bufnr), bufname(a:e2.bufnr)]
331
+    return t1 <# t2 ? -1 : t1 ==# t2 ? 0 : 1
332
+endfunction
333
+
318 334
 " I use Roboto Mono from https://github.com/powerline/fonts
319 335
 " On iTerm2, Preferences -> Profiles -> Text -> Font
320 336
 " Cygwin64 won't let you choose it. Launch Cygwin64 as follows:
321 337