mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-08 05:24:47 +08:00
Extend Commands to include default ex commands
This commit is contained in:
@@ -44,7 +44,7 @@ Commands
|
|||||||
| `Locate PATTERN` | `locate` command output |
|
| `Locate PATTERN` | `locate` command output |
|
||||||
| `History` | `v:oldfiles` and open buffers |
|
| `History` | `v:oldfiles` and open buffers |
|
||||||
| `Snippets` | Snippets ([UltiSnips][us]) |
|
| `Snippets` | Snippets ([UltiSnips][us]) |
|
||||||
| `Commands` | User-defined commands |
|
| `Commands` | Commands |
|
||||||
| `Helptags` | Help tags |
|
| `Helptags` | Help tags |
|
||||||
|
|
||||||
- Most commands support `CTRL-T` / `CTRL-X` / `CTRL-V` key
|
- Most commands support `CTRL-T` / `CTRL-X` / `CTRL-V` key
|
||||||
|
|||||||
@@ -422,17 +422,48 @@ function! s:format_cmd(line)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:command_sink(cmd)
|
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] == '!' ? '' : ' '))
|
call feedkeys(':'.cmd.(a:cmd[0] == '!' ? '' : ' '))
|
||||||
endfunction
|
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)
|
function! s:commands(bang)
|
||||||
redir => cout
|
redir => cout
|
||||||
silent command
|
silent command
|
||||||
redir END
|
redir END
|
||||||
let list = split(cout, "\n")
|
let list = split(cout, "\n")
|
||||||
call s:fzf({
|
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'),
|
\ 'sink': function('s:command_sink'),
|
||||||
\ 'options': '--ansi --tiebreak=index --header-lines 1 -x --prompt "Commands> " -n2 -d'.s:nbs}, a:bang)
|
\ 'options': '--ansi --tiebreak=index --header-lines 1 -x --prompt "Commands> " -n2 -d'.s:nbs}, a:bang)
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user