m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-19 00:53:42 -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 ### Narrow ag results within vim
Add this to your .vimrc ```vim
function! s:ag_handler(lines)
if empty(a:lines) | return | endif
```vimL let [key, line] = a:lines[0:1]
command! -nargs=1 AgFZF call fzf#run({ let [file, line, col] = split(line, ':')[0:2]
\'source': Arghandler(<f-args>), let cmd = get({'ctrl-x': 'split', 'ctrl-v': 'vertical split', 'ctrl-t': 'tabe'}, key, 'e')
\'sink' : function('AgHandler'), execute cmd escape(file, ' %#\')
\'options' : '-m' 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%'
\ }) \ })
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@' "
endfunction
``` ```
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 ### Fuzzy cmdline completion