mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-06 12:44:24 +08:00
Extend Commands to include default ex commands
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user