m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-19 00:53:42 -05:00

ag with quickfix support

Junegunn Choi
2015-07-09 11:38:42 +09:00
parent 59436186c2
commit 86cb9e6914

@@ -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(<q-args>, '"\').'"',
\ 'sink*': function('<sid>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