From 86cb9e69143d1a675b1db30567341a3cd8c16f7a Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 9 Jul 2015 11:38:42 +0900 Subject: [PATCH] ag with quickfix support --- Examples-(vim).md | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/Examples-(vim).md b/Examples-(vim).md index 7c90b05..71ac0dc 100644 --- a/Examples-(vim).md +++ b/Examples-(vim).md @@ -116,28 +116,45 @@ command! FZFLines call fzf#run({ ### Narrow ag results within vim +- `CTRL-X`, `CTRL-V`, `CTRL-T` to open in a new split, vertical split, tab respectively. +- `CTRL-A` to select all matches and list them in quickfix window + ```vim +function! s:ag_to_qf(line) + let parts = split(a:line, ':') + return {'filename': parts[0], 'lnum': parts[1], 'col': parts[2], + \ 'text': join(parts[3:], ':')} +endfunction + function! s:ag_handler(lines) if len(a:lines) < 2 | return | endif - let [key, line] = a:lines[0:1] - let [file, line, col] = split(line, ':')[0:2] - let cmd = get({'ctrl-x': 'split', 'ctrl-v': 'vertical split', 'ctrl-t': 'tabe'}, key, 'e') - execute cmd escape(file, ' %#\') - execute line - execute 'normal!' col.'|zz' + let cmd = get({'ctrl-x': 'split', + \ 'ctrl-v': 'vertical split', + \ 'ctrl-t': 'tabe'}, a:lines[0], 'e') + let list = map(a:lines[1:], 's:ag_to_qf(v:val)') + + let first = list[0] + execute cmd escape(first.filename, ' %#\') + execute first.lnum + execute 'normal!' first.col.'|zz' + + if len(list) > 1 + call setqflist(list) + copen + wincmd p + endif endfunction command! -nargs=1 Ag call fzf#run({ \ 'source': 'ag --nogroup --column --color "'.escape(, '"\').'"', \ 'sink*': function('ag_handler'), -\ 'options': '--ansi --expect=ctrl-t,ctrl-v,ctrl-x --no-multi --color hl:68,hl+:110', +\ 'options': '--ansi --expect=ctrl-t,ctrl-v,ctrl-x '. +\ '--multi --bind ctrl-a:select-all --color hl:68,hl+:110', \ 'down': '50%' \ }) ``` -`CTRL-X`, `CTRL-V`, `CTRL-T` to open in a new split, vertical split, tab respectively. - ### Fuzzy cmdline completion ```vimL