m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-18 16:45:38 -05:00

Updated Examples (vim) (markdown)

Junegunn Choi
2015-05-14 14:57:16 +09:00
parent 35faa5ff8d
commit 85566a4452

@@ -105,27 +105,27 @@ command! FZFLines call fzf#run({
### Narrow ag results within vim
Add this to your .vimrc
```vim
function! s:ag_handler(lines)
if empty(a:lines) | return | endif
```vimL
command! -nargs=1 AgFZF call fzf#run({
\'source': Arghandler(<f-args>),
\'sink' : function('AgHandler'),
\'options' : '-m'
\})
function! AgHandler(l)
let keys = split(a:l,':')
execute 'tabe +' . keys[-2] . ' ' . escape(keys[-1], ' ')
endfunction
function! Arghandler(l)
return "ag -i " . a:l . " | sed 's@\\(.[^:]*\\):\\(.[^:]*\\):\\(.*\\)@\\3:\\2:\\1@' "
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.'|'
endfunction
command! -nargs=1 Ag call fzf#run({
\ 'source': 'ag --nogroup --column --color <q-args>',
\ 'sink*': function('<sid>ag_handler'),
\ 'options': '--ansi --expect=ctrl-t,ctrl-v,ctrl-x --no-multi',
\ 'down': '50%'
\ })
```
Then use `:AgFZF` followed by an ag-recogizable regex to pipe ag results into fzf for narrowing. Selected results are opened in new tabs so that you can open multiple positions within the same file (perhaps there's a better way of doing this).
`CTRL-X`, `CTRL-V`, `CTRL-T` to open in a new split, vertical split, tab respectively.
### Fuzzy cmdline completion