diff --git a/README.md b/README.md index 9256cb2..f17622e 100644 --- a/README.md +++ b/README.md @@ -66,12 +66,14 @@ let g:fzf_layout = { 'down': '40%' } Mappings -------- -| Mapping | Description | -| --- | --- | -| `(fzf-complete-word)` | `cat /usr/share/dict/words` | -| `(fzf-complete-path)` | Path completion using `find` (file + dir) | -| `(fzf-complete-file)` | File completion using `find` | -| `(fzf-complete-file-ag)` | File completion using `ag` | +| Mapping | Description | +| --- | --- | +| `(fzf-complete-word)` | `cat /usr/share/dict/words` | +| `(fzf-complete-path)` | Path completion using `find` (file + dir) | +| `(fzf-complete-file)` | File completion using `find` | +| `(fzf-complete-file-ag)` | File completion using `ag` | +| `(fzf-complete-line)` | Line completion (all open buffers) | +| `(fzf-complete-buffer-line)` | Line completion (current buffer only) | ### Usage @@ -79,6 +81,7 @@ Mappings imap (fzf-complete-word) imap (fzf-complete-path) imap (fzf-complete-file-ag) +imap (fzf-complete-line) ``` ### Completion helper diff --git a/doc/fzf-vim.txt b/doc/fzf-vim.txt index 99aeb26..9613649 100644 --- a/doc/fzf-vim.txt +++ b/doc/fzf-vim.txt @@ -1,4 +1,4 @@ -fzf-vim.txt fzf-vim Last change: August 22 2015 +fzf-vim.txt fzf-vim Last change: August 23 2015 FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc* ============================================================================== @@ -98,14 +98,16 @@ COMMANDS *fzf-vim-commands* MAPPINGS *fzf-vim-mappings* ============================================================================== - -----------------------------+------------------------------------------ - Mapping | Description ~ - -----------------------------+------------------------------------------ - (fzf-complete-word) | `cat /usr/share/dict/words` - (fzf-complete-path) | Path completion using `find` (file + dir) - (fzf-complete-file) | File completion using `find` - (fzf-complete-file-ag) | File completion using `ag` - -----------------------------+------------------------------------------ + ---------------------------------+------------------------------------------ + Mapping | Description ~ + ---------------------------------+------------------------------------------ + (fzf-complete-word) | `cat /usr/share/dict/words` + (fzf-complete-path) | Path completion using `find` (file + dir) + (fzf-complete-file) | File completion using `find` + (fzf-complete-file-ag) | File completion using `ag` + (fzf-complete-line) | Line completion (all open buffers) + (fzf-complete-buffer-line) | Line completion (current buffer only) + ---------------------------------+------------------------------------------ < Usage >_____________________________________________________________________~ @@ -114,6 +116,7 @@ MAPPINGS *fzf-vim-mappings* imap (fzf-complete-word) imap (fzf-complete-path) imap (fzf-complete-file-ag) + imap (fzf-complete-line) < < Completion helper >_________________________________________________________~ diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 2609d59..0813110 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -106,6 +106,18 @@ function! s:warn(message) echohl None endfunction +function! s:uniq(list) + let visited = {} + let ret = [] + for l in a:list + if !empty(l) && !has_key(visited, l) + call add(ret, l) + let visited[l] = 1 + endif + endfor + return ret +endfunction + " ------------------------------------------------------------------ " Files " ------------------------------------------------------------------ @@ -589,6 +601,24 @@ inoremap (fzf-complete-file) \ complete_file(0, "find . -path '*/\.*' -prune -o -type f -print -o -type l -print \| sed '1d;s:^..::'") inoremap (fzf-complete-file-ag) complete_file(0, "ag -l -g ''") +" ---------------------------------------------------------------------------- +" (fzf-complete-line) +" (fzf-complete-buffer-line) +" ---------------------------------------------------------------------------- +function! s:reduce_line(lines) + return join(split(a:lines[0], '\t\zs')[2:], '') +endfunction + +inoremap (fzf-complete-line) fzf#complete(extend({ +\ 'prefix': '^.*$', +\ 'source': lines(), +\ 'options': '--tiebreak=index --ansi --nth 3..', +\ 'reducer': function('reduce_line')}, win())) + +inoremap (fzf-complete-buffer-line) fzf#complete(extend({ +\ 'prefix': '^.*$', +\ 'source': uniq(getline(1, '$'))}, win())) + " ------------------------------------------------------------------ let &cpo = s:cpo_save unlet s:cpo_save