[Commands] CTRL-X to directly execute the command

Close #162
This commit is contained in:
Junegunn Choi
2016-06-21 01:06:56 +09:00
parent 94e499b131
commit 6b62cb418a
2 changed files with 19 additions and 6 deletions

View File

@@ -709,9 +709,16 @@ function! s:format_cmd(line)
\ '\=s:nbs.s:yellow(submatch(1), "Function").s:nbs', '')
endfunction
function! s:command_sink(cmd)
let cmd = matchstr(a:cmd, s:nbs.'\zs\S*\ze'.s:nbs)
call feedkeys(':'.cmd.(a:cmd[0] == '!' ? '' : ' '))
function! s:command_sink(lines)
if len(a:lines) < 2
return
endif
let cmd = matchstr(a:lines[1], s:nbs.'\zs\S*\ze'.s:nbs)
if empty(a:lines[0])
call feedkeys(':'.cmd.(a:lines[1][0] == '!' ? '' : ' '))
else
execute cmd
endif
endfunction
function! s:format_excmd(ex)
@@ -752,8 +759,9 @@ function! fzf#vim#commands(...)
let list = split(cout, "\n")
return s:fzf({
\ 'source': extend(extend(list[0:0], map(list[1:], 's:format_cmd(v:val)')), s:excmds()),
\ 'sink': s:function('s:command_sink'),
\ 'options': '--ansi --tiebreak=index --header-lines 1 -x --prompt "Commands> " -n2,3,2..3 -d'.s:nbs}, a:000)
\ 'sink*': s:function('s:command_sink'),
\ 'options': '--ansi --expect '.get(g:, 'fzf_commands_expect', 'ctrl-x').
\ ' --tiebreak=index --header-lines 1 -x --prompt "Commands> " -n2,3,2..3 -d'.s:nbs}, a:000)
endfunction
" ------------------------------------------------------------------