diff --git a/README.md b/README.md index 4bd6e03..9256cb2 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Commands | `Colors` | Color schemes | | `Ag [PATTERN]` | [ag][ag] search result (`CTRL-A` to select all, `CTRL-D` to deselect all) | | `Lines` | Lines in loaded buffers | +| `BLines` | Lines in the current buffer | | `Marks` | Marks | | `Tags` | Tags in the project (`ctags -R`) | | `BTags` | Tags in the current buffer | diff --git a/doc/fzf-vim.txt b/doc/fzf-vim.txt index 609f99c..99aeb26 100644 --- a/doc/fzf-vim.txt +++ b/doc/fzf-vim.txt @@ -62,6 +62,7 @@ COMMANDS *fzf-vim-commands* `Colors` | Color schemes `Ag [PATTERN]` | {ag}{5} search result (CTRL-A to select all, CTRL-D to deselect all) `Lines` | Lines in loaded buffers + `BLines` | Lines in the current buffer `Marks` | Marks `Tags` | Tags in the project ( `ctags -R` ) `BTags` | Tags in the current buffer diff --git a/plugin/fzf.vim b/plugin/fzf.vim index b6ae4a2..2609d59 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -150,20 +150,49 @@ function! s:line_handler(lines) normal! ^zz endfunction -function! s:buffer_lines() - let res = [] +function! s:lines() + let cur = [] + let rest = [] + let buf = bufnr('') for b in s:buflisted() - call extend(res, - \ map(getbufline(b, 0, "$"), + call extend(b == buf ? cur : rest, + \ map(getbufline(b, 1, "$"), \ 'printf("[%s]\t%s:\t%s", s:blue(b, 1), s:yellow(v:key + 1, 1), v:val)')) endfor - return res + return extend(cur, rest) endfunction command! -bang Lines call s:fzf({ -\ 'source': buffer_lines(), +\ 'source': lines(), \ 'sink*': function('line_handler'), -\ 'options': '+m --prompt "Lines> " --ansi --extended --nth=3..'.s:expect() +\ 'options': '+m --tiebreak=index --prompt "Lines> " --ansi --extended --nth=3..'.s:expect() +\}, 0) + +" ------------------------------------------------------------------ +" BLines +" ------------------------------------------------------------------ +function! s:buffer_line_handler(lines) + if len(a:lines) < 2 + return + endif + let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '') + if !empty(cmd) + execute 'silent' cmd + endif + + execute split(a:lines[1], '\t')[0][0:-2] + normal! ^zz +endfunction + +function! s:buffer_lines() + return map(getline(1, "$"), + \ 'printf("%s:\t%s", s:yellow(v:key + 1, 1), v:val)') +endfunction + +command! -bang BLines call s:fzf({ +\ 'source': buffer_lines(), +\ 'sink*': function('buffer_line_handler'), +\ 'options': '+m --tiebreak=index --prompt "BLines> " --ansi --extended --nth=2..'.s:expect() \}, 0) " ------------------------------------------------------------------