Merge pull request #7 from junegunn/extended-history
Command history and search history (#6)
This commit is contained in:
commit
fb355a9737
3 changed files with 73 additions and 6 deletions
|
@ -43,6 +43,8 @@ Commands
|
||||||
| `Windows` | Windows |
|
| `Windows` | Windows |
|
||||||
| `Locate PATTERN` | `locate` command output |
|
| `Locate PATTERN` | `locate` command output |
|
||||||
| `History` | `v:oldfiles` and open buffers |
|
| `History` | `v:oldfiles` and open buffers |
|
||||||
|
| `History:` | Command history |
|
||||||
|
| `History/` | Search history |
|
||||||
| `Snippets` | Snippets ([UltiSnips][us]) |
|
| `Snippets` | Snippets ([UltiSnips][us]) |
|
||||||
| `Commands` | Commands |
|
| `Commands` | Commands |
|
||||||
| `Helptags` | Help tags |
|
| `Helptags` | Help tags |
|
||||||
|
|
|
@ -69,6 +69,8 @@ COMMANDS *fzf-vim-commands*
|
||||||
`Windows` | Windows
|
`Windows` | Windows
|
||||||
`Locate PATTERN` | `locate` command output
|
`Locate PATTERN` | `locate` command output
|
||||||
`History` | `v:oldfiles` and open buffers
|
`History` | `v:oldfiles` and open buffers
|
||||||
|
`History:` | Command history
|
||||||
|
`History/` | Search history
|
||||||
`Snippets` | Snippets ({UltiSnips}{6})
|
`Snippets` | Snippets ({UltiSnips}{6})
|
||||||
`Commands` | Commands
|
`Commands` | Commands
|
||||||
`Helptags` | Help tags
|
`Helptags` | Help tags
|
||||||
|
|
|
@ -227,7 +227,7 @@ command! -bang -nargs=1 Locate call s:fzf({
|
||||||
\}, <bang>0)
|
\}, <bang>0)
|
||||||
|
|
||||||
" ------------------------------------------------------------------
|
" ------------------------------------------------------------------
|
||||||
" History
|
" History[:/]
|
||||||
" ------------------------------------------------------------------
|
" ------------------------------------------------------------------
|
||||||
function! s:all_files()
|
function! s:all_files()
|
||||||
return extend(
|
return extend(
|
||||||
|
@ -236,11 +236,74 @@ function! s:all_files()
|
||||||
\ filter(map(s:buflisted(), 'bufname(v:val)'), '!empty(v:val)'))
|
\ filter(map(s:buflisted(), 'bufname(v:val)'), '!empty(v:val)'))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
command! -bang History call s:fzf({
|
function! s:history_source(type)
|
||||||
\ 'source': reverse(s:all_files()),
|
let max = histnr(a:type)
|
||||||
\ 'sink*': function('<sid>common_sink'),
|
let fmt = '%'.len(string(max)).'d'
|
||||||
\ 'options': '--prompt "Hist> " -m' . s:expect(),
|
let list = filter(map(range(1, max), '[-v:val, histget(a:type, - v:val)]'), '!empty(v:val[1])')
|
||||||
\}, <bang>0)
|
return extend([':: Press CTRL-E to edit'],
|
||||||
|
\ map(list, 'v:val[0]." ".s:yellow(printf(fmt, len(list) - v:key)).": ".v:val[1]'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:do()
|
||||||
|
execute s:command
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
nnoremap <plug>(-fzf-vim-do) :call <sid>do()<cr>
|
||||||
|
|
||||||
|
function! s:history_sink(type, lines)
|
||||||
|
if empty(a:lines)
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
let key = a:lines[0]
|
||||||
|
let item = histget(a:type, split(a:lines[1])[1])
|
||||||
|
if key == 'ctrl-e'
|
||||||
|
call histadd(a:type, item)
|
||||||
|
call feedkeys(a:type."\<up>")
|
||||||
|
else
|
||||||
|
let s:command = "normal ".a:type.item."\<cr>"
|
||||||
|
call feedkeys("\<plug>(-fzf-vim-do)")
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:cmd_history_sink(lines)
|
||||||
|
call s:history_sink(':', a:lines)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:cmd_history(bang)
|
||||||
|
call s:fzf({
|
||||||
|
\ 'source': s:history_source(':'),
|
||||||
|
\ 'sink*': function('s:cmd_history_sink'),
|
||||||
|
\ 'options': '+m --ansi --with-nth=2.. --prompt="Hist:> " --header-lines=1 --expect=ctrl-e --tiebreak=index'}, a:bang)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:search_history_sink(lines)
|
||||||
|
call s:history_sink('/', a:lines)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:search_history(bang)
|
||||||
|
call s:fzf({
|
||||||
|
\ 'source': s:history_source('/'),
|
||||||
|
\ 'sink*': function('s:search_history_sink'),
|
||||||
|
\ 'options': '+m --ansi --with-nth 2.. --prompt="Hist/> " --header-lines=1 --expect=ctrl-e --tiebreak=index'}, a:bang)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:history(arg, bang)
|
||||||
|
let bang = a:bang || a:arg[len(a:arg)-1] == '!'
|
||||||
|
if a:arg[0] == ':'
|
||||||
|
call s:cmd_history(bang)
|
||||||
|
elseif a:arg[0] == '/'
|
||||||
|
call s:search_history(bang)
|
||||||
|
else
|
||||||
|
call s:fzf({
|
||||||
|
\ 'source': reverse(s:all_files()),
|
||||||
|
\ 'sink*': function('s:common_sink'),
|
||||||
|
\ 'options': '--prompt "Hist> " -m' . s:expect(),
|
||||||
|
\}, bang)
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
command! -bang -nargs=* History call s:history(<q-args>, <bang>0)
|
||||||
|
|
||||||
" ------------------------------------------------------------------
|
" ------------------------------------------------------------------
|
||||||
" Buffers
|
" Buffers
|
||||||
|
|
Loading…
Add table
Reference in a new issue