mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-19 00:53:42 -05:00
ag with quickfix support
@@ -116,28 +116,45 @@ command! FZFLines call fzf#run({
|
|||||||
|
|
||||||
### Narrow ag results within vim
|
### 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
|
```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)
|
function! s:ag_handler(lines)
|
||||||
if len(a:lines) < 2 | return | endif
|
if len(a:lines) < 2 | return | endif
|
||||||
|
|
||||||
let [key, line] = a:lines[0:1]
|
let cmd = get({'ctrl-x': 'split',
|
||||||
let [file, line, col] = split(line, ':')[0:2]
|
\ 'ctrl-v': 'vertical split',
|
||||||
let cmd = get({'ctrl-x': 'split', 'ctrl-v': 'vertical split', 'ctrl-t': 'tabe'}, key, 'e')
|
\ 'ctrl-t': 'tabe'}, a:lines[0], 'e')
|
||||||
execute cmd escape(file, ' %#\')
|
let list = map(a:lines[1:], 's:ag_to_qf(v:val)')
|
||||||
execute line
|
|
||||||
execute 'normal!' col.'|zz'
|
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
|
endfunction
|
||||||
|
|
||||||
command! -nargs=1 Ag call fzf#run({
|
command! -nargs=1 Ag call fzf#run({
|
||||||
\ 'source': 'ag --nogroup --column --color "'.escape(<q-args>, '"\').'"',
|
\ 'source': 'ag --nogroup --column --color "'.escape(<q-args>, '"\').'"',
|
||||||
\ 'sink*': function('<sid>ag_handler'),
|
\ '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%'
|
\ 'down': '50%'
|
||||||
\ })
|
\ })
|
||||||
```
|
```
|
||||||
|
|
||||||
`CTRL-X`, `CTRL-V`, `CTRL-T` to open in a new split, vertical split, tab respectively.
|
|
||||||
|
|
||||||
### Fuzzy cmdline completion
|
### Fuzzy cmdline completion
|
||||||
|
|
||||||
```vimL
|
```vimL
|
||||||
|
|||||||
Reference in New Issue
Block a user