mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-20 17:43:42 -05:00
Commandline autocomplete filter
39
examples.md
39
examples.md
@@ -203,4 +203,41 @@ command! FZFMru call fzf#run({
|
|||||||
\'sink' : 'e ',
|
\'sink' : 'e ',
|
||||||
\'options' : '-m',
|
\'options' : '-m',
|
||||||
\})
|
\})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Fuzzy cmdline completion
|
||||||
|
---
|
||||||
|
|
||||||
|
```vimL
|
||||||
|
cnoremap <silent> <c-l> <c-\>eGetCompletions()<cr>
|
||||||
|
|
||||||
|
function! Lister()
|
||||||
|
call extend(g:FZF_Cmd_Completion_Pre_List,split(getcmdline(),' '))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! GetCompletions()
|
||||||
|
let g:FZF_Cmd_Completion_Pre_List = []
|
||||||
|
let l:cmdline_list = split(getcmdline(), ' ', 1)
|
||||||
|
let l:Prefix = l:cmdline_list[0:-2]
|
||||||
|
execute "silent normal! :" . getcmdline() . "\<c-a>\<c-\>eLister()\<cr>\<c-c>"
|
||||||
|
let l:FZF_Cmd_Completion_List = g:FZF_Cmd_Completion_Pre_List[len(l:Prefix):-1]
|
||||||
|
unlet g:FZF_Cmd_Completion_Pre_List
|
||||||
|
if len(l:Prefix) > 0 && (
|
||||||
|
\ (l:Prefix[0] == 'e') ||
|
||||||
|
\ (l:Prefix[0] == 'tabe') ||
|
||||||
|
\ (l:Prefix[0] == 'vs') ||
|
||||||
|
\ (l:Prefix[0] == 'sp')
|
||||||
|
\)
|
||||||
|
return join(l:Prefix + fzf#run({
|
||||||
|
\'options': '-m --select-1 --query='.l:cmdline_list[-1]
|
||||||
|
\}))
|
||||||
|
else
|
||||||
|
return join(l:Prefix + fzf#run({
|
||||||
|
\'source':l:FZF_Cmd_Completion_List,
|
||||||
|
\'options': '--select-1 --query='.l:cmdline_list[-1]
|
||||||
|
\}))
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
```
|
||||||
|
|
||||||
|
hit `<c-l>` while in the ex commandline (i.e. after pressing `:`) to have fzf filter a list of vim's commandline auto-completions. Try `:colo␣<c-l>` (be sure to include the space) or `:b␣<c-l>`. There are special cases for handling file-searches, so that you can go deeper into the directory than just one layer. More special cases could be added. Some limitations: the auto-complete for `:help` and `:tag` are limited to 300 entries, so you may need to narrow it a bit.
|
||||||
Reference in New Issue
Block a user