diff --git a/Examples-(vim).md b/Examples-(vim).md index 964f981..98728d4 100644 --- a/Examples-(vim).md +++ b/Examples-(vim).md @@ -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(), - \'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 ', +\ 'sink*': function('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