Add Commands command
This commit is contained in:
parent
701791bd37
commit
cffb0e0191
2 changed files with 29 additions and 0 deletions
|
@ -42,6 +42,7 @@ List of commands
|
|||
| `Locate PATTERN` | `locate` command output |
|
||||
| `History` | `v:oldfiles` and open buffers |
|
||||
| `Snippets` | Snippets ([UltiSnips][us]) |
|
||||
| `Commands` | User-defined commands |
|
||||
|
||||
- All commands except `Colors` support `CTRL-T` / `CTRL-X` / `CTRL-V` key
|
||||
bindings to open in a new tab, a new split, or in a new vertical split.
|
||||
|
|
|
@ -364,6 +364,34 @@ endfunction
|
|||
|
||||
command! -bang Snippets call s:snippets(<bang>0)
|
||||
|
||||
" ------------------------------------------------------------------
|
||||
" Commands
|
||||
" ------------------------------------------------------------------
|
||||
let s:nbs = nr2char(0x2007)
|
||||
|
||||
function! s:format_cmd(line)
|
||||
return substitute(a:line, '\C \([A-Z]\S*\) ',
|
||||
\ '\=s:nbs.s:yellow(submatch(1), 1).s:nbs', '')
|
||||
endfunction
|
||||
|
||||
function! s:command_sink(cmd)
|
||||
let cmd = matchstr(a:cmd, '\C[A-Z]\S*\ze'.s:nbs)
|
||||
call feedkeys(':'.cmd.(a:cmd[0] == '!' ? '' : ' '))
|
||||
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)')),
|
||||
\ 'sink': function('s:command_sink'),
|
||||
\ 'options': '--ansi --header-lines 1 -x --prompt "Commands> " -n2 -d'.s:nbs}, a:bang)
|
||||
endfunction
|
||||
|
||||
command! -bang Commands call s:commands(<bang>0)
|
||||
|
||||
" ----------------------------------------------------------------------------
|
||||
" Completion helper
|
||||
" ----------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Reference in a new issue