diff --git a/examples.md b/examples.md index dff33d9..63fe27e 100644 --- a/examples.md +++ b/examples.md @@ -203,4 +203,41 @@ command! FZFMru call fzf#run({ \'sink' : 'e ', \'options' : '-m', \}) -``` \ No newline at end of file +``` + +Fuzzy cmdline completion +--- + +```vimL +cnoremap eGetCompletions() + +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() . "\\eLister()\\" + 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 `` while in the ex commandline (i.e. after pressing `:`) to have fzf filter a list of vim's commandline auto-completions. Try `:colo␣` (be sure to include the space) or `:b␣`. 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. \ No newline at end of file