Extend Commands to include default ex commands

This commit is contained in:
Junegunn Choi
2015-08-29 22:51:34 +09:00
parent c857037b4b
commit eec4a667d8
2 changed files with 34 additions and 3 deletions

View File

@@ -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

View File

@@ -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