From 46c0e47b02ce23fb152e63cf03b8f0d579894aa4 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 2 Sep 2015 23:07:02 +0900 Subject: [PATCH] Fix History[:/] - History command itself can shift index by one --- plugin/fzf.vim | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index e210f0a..bfcac57 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -239,16 +239,12 @@ endfunction function! s:history_source(type) let max = histnr(a:type) let fmt = '%'.len(string(max)).'d' - let list = filter(map(range(1, max), '[-v:val, histget(a:type, - v:val)]'), '!empty(v:val[1])') - return extend([':: Press CTRL-E to edit'], - \ map(list, 'v:val[0]." ".s:yellow(printf(fmt, len(list) - v:key)).": ".v:val[1]')) + let list = filter(map(range(1, max), 'histget(a:type, - v:val)'), '!empty(v:val)') + return extend([' :: Press CTRL-E to edit'], + \ map(list, 's:yellow(printf(fmt, len(list) - v:key)).": ".v:val')) endfunction -function! s:do() - execute s:command -endfunction - -nnoremap (-fzf-vim-do) :call do() +nnoremap (-fzf-vim-do) :execute g:__fzf_commandunlet g:__fzf_command function! s:history_sink(type, lines) if empty(a:lines) @@ -256,12 +252,12 @@ function! s:history_sink(type, lines) endif let key = a:lines[0] - let item = histget(a:type, split(a:lines[1])[1]) + let item = matchstr(a:lines[1], ': \zs.*') if key == 'ctrl-e' call histadd(a:type, item) call feedkeys(a:type."\") else - let s:command = "normal ".a:type.item."\" + let g:__fzf_command = "normal ".a:type.item."\" call feedkeys("\(-fzf-vim-do)") endif endfunction @@ -274,7 +270,7 @@ 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) + \ 'options': '+m --ansi --prompt="Hist:> " --header-lines=1 --expect=ctrl-e --tiebreak=index'}, a:bang) endfunction function! s:search_history_sink(lines) @@ -285,7 +281,7 @@ 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) + \ 'options': '+m --ansi --prompt="Hist/> " --header-lines=1 --expect=ctrl-e --tiebreak=index'}, a:bang) endfunction function! s:history(arg, bang)