mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-08 05:24:47 +08:00
Add line completion (global and local)
This commit is contained in:
15
README.md
15
README.md
@@ -66,12 +66,14 @@ let g:fzf_layout = { 'down': '40%' }
|
|||||||
Mappings
|
Mappings
|
||||||
--------
|
--------
|
||||||
|
|
||||||
| Mapping | Description |
|
| Mapping | Description |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `<plug>(fzf-complete-word)` | `cat /usr/share/dict/words` |
|
| `<plug>(fzf-complete-word)` | `cat /usr/share/dict/words` |
|
||||||
| `<plug>(fzf-complete-path)` | Path completion using `find` (file + dir) |
|
| `<plug>(fzf-complete-path)` | Path completion using `find` (file + dir) |
|
||||||
| `<plug>(fzf-complete-file)` | File completion using `find` |
|
| `<plug>(fzf-complete-file)` | File completion using `find` |
|
||||||
| `<plug>(fzf-complete-file-ag)` | File completion using `ag` |
|
| `<plug>(fzf-complete-file-ag)` | File completion using `ag` |
|
||||||
|
| `<plug>(fzf-complete-line)` | Line completion (all open buffers) |
|
||||||
|
| `<plug>(fzf-complete-buffer-line)` | Line completion (current buffer only) |
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
@@ -79,6 +81,7 @@ Mappings
|
|||||||
imap <c-x><c-k> <plug>(fzf-complete-word)
|
imap <c-x><c-k> <plug>(fzf-complete-word)
|
||||||
imap <c-x><c-f> <plug>(fzf-complete-path)
|
imap <c-x><c-f> <plug>(fzf-complete-path)
|
||||||
imap <c-x><c-j> <plug>(fzf-complete-file-ag)
|
imap <c-x><c-j> <plug>(fzf-complete-file-ag)
|
||||||
|
imap <c-x><c-l> <plug>(fzf-complete-line)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Completion helper
|
### Completion helper
|
||||||
|
|||||||
@@ -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*
|
FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc*
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
||||||
@@ -98,14 +98,16 @@ COMMANDS *fzf-vim-commands*
|
|||||||
MAPPINGS *fzf-vim-mappings*
|
MAPPINGS *fzf-vim-mappings*
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
||||||
-----------------------------+------------------------------------------
|
---------------------------------+------------------------------------------
|
||||||
Mapping | Description ~
|
Mapping | Description ~
|
||||||
-----------------------------+------------------------------------------
|
---------------------------------+------------------------------------------
|
||||||
<plug>(fzf-complete-word) | `cat /usr/share/dict/words`
|
<plug>(fzf-complete-word) | `cat /usr/share/dict/words`
|
||||||
<plug>(fzf-complete-path) | Path completion using `find` (file + dir)
|
<plug>(fzf-complete-path) | Path completion using `find` (file + dir)
|
||||||
<plug>(fzf-complete-file) | File completion using `find`
|
<plug>(fzf-complete-file) | File completion using `find`
|
||||||
<plug>(fzf-complete-file-ag) | File completion using `ag`
|
<plug>(fzf-complete-file-ag) | File completion using `ag`
|
||||||
-----------------------------+------------------------------------------
|
<plug>(fzf-complete-line) | Line completion (all open buffers)
|
||||||
|
<plug>(fzf-complete-buffer-line) | Line completion (current buffer only)
|
||||||
|
---------------------------------+------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
< Usage >_____________________________________________________________________~
|
< Usage >_____________________________________________________________________~
|
||||||
@@ -114,6 +116,7 @@ MAPPINGS *fzf-vim-mappings*
|
|||||||
imap <c-x><c-k> <plug>(fzf-complete-word)
|
imap <c-x><c-k> <plug>(fzf-complete-word)
|
||||||
imap <c-x><c-f> <plug>(fzf-complete-path)
|
imap <c-x><c-f> <plug>(fzf-complete-path)
|
||||||
imap <c-x><c-j> <plug>(fzf-complete-file-ag)
|
imap <c-x><c-j> <plug>(fzf-complete-file-ag)
|
||||||
|
imap <c-x><c-l> <plug>(fzf-complete-line)
|
||||||
<
|
<
|
||||||
|
|
||||||
< Completion helper >_________________________________________________________~
|
< Completion helper >_________________________________________________________~
|
||||||
|
|||||||
@@ -106,6 +106,18 @@ function! s:warn(message)
|
|||||||
echohl None
|
echohl None
|
||||||
endfunction
|
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
|
" Files
|
||||||
" ------------------------------------------------------------------
|
" ------------------------------------------------------------------
|
||||||
@@ -589,6 +601,24 @@ inoremap <expr> <plug>(fzf-complete-file)
|
|||||||
\ <sid>complete_file(0, "find . -path '*/\.*' -prune -o -type f -print -o -type l -print \| sed '1d;s:^..::'")
|
\ <sid>complete_file(0, "find . -path '*/\.*' -prune -o -type f -print -o -type l -print \| sed '1d;s:^..::'")
|
||||||
inoremap <expr> <plug>(fzf-complete-file-ag) <sid>complete_file(0, "ag -l -g ''")
|
inoremap <expr> <plug>(fzf-complete-file-ag) <sid>complete_file(0, "ag -l -g ''")
|
||||||
|
|
||||||
|
" ----------------------------------------------------------------------------
|
||||||
|
" <plug>(fzf-complete-line)
|
||||||
|
" <plug>(fzf-complete-buffer-line)
|
||||||
|
" ----------------------------------------------------------------------------
|
||||||
|
function! s:reduce_line(lines)
|
||||||
|
return join(split(a:lines[0], '\t\zs')[2:], '')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
inoremap <expr> <plug>(fzf-complete-line) fzf#complete(extend({
|
||||||
|
\ 'prefix': '^.*$',
|
||||||
|
\ 'source': <sid>lines(),
|
||||||
|
\ 'options': '--tiebreak=index --ansi --nth 3..',
|
||||||
|
\ 'reducer': function('<sid>reduce_line')}, <sid>win()))
|
||||||
|
|
||||||
|
inoremap <expr> <plug>(fzf-complete-buffer-line) fzf#complete(extend({
|
||||||
|
\ 'prefix': '^.*$',
|
||||||
|
\ 'source': <sid>uniq(getline(1, '$'))}, <sid>win()))
|
||||||
|
|
||||||
" ------------------------------------------------------------------
|
" ------------------------------------------------------------------
|
||||||
let &cpo = s:cpo_save
|
let &cpo = s:cpo_save
|
||||||
unlet s:cpo_save
|
unlet s:cpo_save
|
||||||
|
|||||||
Reference in New Issue
Block a user