m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-20 01:23:43 -05:00

Improve FZFLines example

Junegunn Choi
2014-07-04 02:44:48 -07:00
parent 25b3902a34
commit 4d45c1b628

@@ -167,29 +167,27 @@ 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). 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).
search lines in all open vim buffers Search lines in all open vim buffers
--- ---
```vimL ```vimL
command! FZFLines call fzf#run({ command! FZFLines call fzf#run({
\'source': BuffersLines(), \ 'source': BuffersLines(),
\'sink' : function('LineHandler'), \ 'sink': function('LineHandler'),
\}) \ 'options': '--extended --nth=3..,'
\})
function! LineHandler(l) function! LineHandler(l)
let keys = split(a:l,' ') let keys = split(a:l, ':\t')
exec 'buf ' . keys[0] exec 'buf ' . keys[0]
let line = join(keys[4:-1]) exec keys[1]
exec search(escape(line, '\\/.*$^~[]')) normal! ^zz
endfunction endfunction
function! BuffersLines() function! BuffersLines()
let all = range(1, bufnr('$'))
let res = [] let res = []
for b in all for b in filter(range(1, bufnr('$')), 'buflisted(v:val)')
if buflisted(b) call extend(res, map(getbufline(b,0,"$"), 'b . ":\t" . (v:key + 1) . ":\t" . v:val '))
let res = res + map(getbufline(b,0,"$"), 'b . " -- " . (v:key + 1) . " -- " . v:val ')
endif
endfor endfor
return res return res
endfunction endfunction