LoginSignup
0
4

More than 5 years have passed since last update.

Vim の grep を pt (The Platinum Searcher) で実行して QuickFix をファイルパスでソートする

Posted at

vimrc に以下を記述する。

augroup vimrc
  autocmd!
augroup END

" grep プログラムに pt を指定
let &grepprg = 'pt /nogroup /nocolor /column /S'
" /column で桁を表示しているので %c も使うパターンを追加
set grepformat^=%f:%l:%c:%m
" grep 後に quickfix-window を表示
autocmd vimrc QuickFixCmdPost *grep* cwindow

" http://stackoverflow.com/questions/15393301/automatically-sort-quickfix-entries-by-line-text-in-vim
" pt で grep を実行した後に結果をパス順にしたかったので sort
autocmd! vimrc QuickFixCmdPost * call s:SortQuickfix('s:QfStrCmp')
function! s:SortQuickfix(fn)
  call setqflist(sort(getqflist(), a:fn))
endfunction
function! s:QfStrCmp(e1, e2)
  let [t1, t2] = [bufname(a:e1.bufnr), bufname(a:e2.bufnr)]
  return t1 <? t2 ? -1 : t1 ==? t2 ? 0 : 1
endfunction
0
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
4