From eec4a667d8f04e85035238bf3ca5c17a31b77cb2 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 29 Aug 2015 22:51:34 +0900 Subject: [PATCH] Extend Commands to include default ex commands --- README.md | 2 +- plugin/fzf.vim | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a34e11b..ef362ce 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Commands | `Locate PATTERN` | `locate` command output | | `History` | `v:oldfiles` and open buffers | | `Snippets` | Snippets ([UltiSnips][us]) | -| `Commands` | User-defined commands | +| `Commands` | Commands | | `Helptags` | Help tags | - Most commands support `CTRL-T` / `CTRL-X` / `CTRL-V` key diff --git a/plugin/fzf.vim b/plugin/fzf.vim index e18fbae..79ceab8 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -422,17 +422,48 @@ function! s:format_cmd(line) endfunction function! s:command_sink(cmd) - let cmd = matchstr(a:cmd, '\C[A-Z]\S*\ze'.s:nbs) + let cmd = matchstr(a:cmd, s:nbs.'\zs\S*\ze'.s:nbs) call feedkeys(':'.cmd.(a:cmd[0] == '!' ? '' : ' ')) endfunction +function! s:format_excmd(ex) + let match = matchlist(a:ex, '^|:\(\S\+\)|\s*\S*\(.*\)') + return printf(" \x1b[34m%-38s\x1b[m%s", s:nbs.match[1].s:nbs, s:strip(match[2])) +endfunction + +function! s:excmds() + let help = globpath($VIMRUNTIME, 'doc/index.txt') + if empty(help) + return [] + endif + + let commands = [] + let command = '' + for line in readfile(help) + if line =~ '^|:[^|]' + if !empty(command) + call add(commands, s:format_excmd(command)) + endif + let command = line + elseif line =~ '^\s\+\S' && !empty(command) + let command .= substitute(line, '^\s*', ' ', '') + elseif !empty(commands) && line =~ '^\s*$' + break + endif + endfor + if !empty(command) + call add(commands, s:format_excmd(command)) + endif + return commands +endfunction + function! s:commands(bang) redir => cout silent command redir END let list = split(cout, "\n") call s:fzf({ - \ 'source': extend(list[0:0], map(list[1:], 's:format_cmd(v:val)')), + \ 'source': extend(extend(list[0:0], s:excmds()), map(list[1:], 's:format_cmd(v:val)')), \ 'sink': function('s:command_sink'), \ 'options': '--ansi --tiebreak=index --header-lines 1 -x --prompt "Commands> " -n2 -d'.s:nbs}, a:bang) endfunction