Use --footer for key binding hints

- Buffers: CTRL-ALT-X replaces SHIFT-DELETE to unload buffers
- History:, History/, Commits: use --scheme=history
- Bump min fzf version to 0.63.0 for --footer
This commit is contained in:
Junegunn Choi
2026-06-12 09:06:10 +09:00
parent 356608e2ae
commit d2a59a992a
+40 -19
View File
@@ -94,7 +94,7 @@ function! s:escape_for_bash(path)
return escape(path, ' ') return escape(path, ' ')
endfunction endfunction
let s:min_version = '0.56.0' let s:min_version = '0.63.0'
let s:is_win = has('win32') || has('win64') let s:is_win = has('win32') || has('win64')
let s:is_wsl_bash = s:is_win && (exepath('bash') =~? 'Windows[/\\]system32[/\\]bash.exe$') let s:is_wsl_bash = s:is_win && (exepath('bash') =~? 'Windows[/\\]system32[/\\]bash.exe$')
let s:layout_keys = ['window', 'up', 'down', 'left', 'right'] let s:layout_keys = ['window', 'up', 'down', 'left', 'right']
@@ -352,6 +352,25 @@ for s:color_name in keys(s:ansi)
\ "endfunction" \ "endfunction"
endfor endfor
function! s:build_hint(entries, defaults)
let entries = copy(a:entries)
let keys = []
let actions = get(g:, 'fzf_action', s:default_action)
if a:defaults
call add(entries, ['Enter', 'Open'])
for [key, name, label] in [['ctrl-x', 'C-X', 'HSplit'], ['ctrl-v', 'C-V', 'VSplit'], ['ctrl-t', 'C-T', 'New tab']]
let Cmd = get(actions, key, '')
if type(Cmd) == s:TYPE.string && Cmd ==# s:default_action[key]
call add(entries, [name, label])
endif
endfor
endif
for [key, action] in entries
call add(keys, s:magenta(key, 'Special').' '.action)
endfor
return join(keys, ' ')
endfunction
function! s:buflisted() function! s:buflisted()
return filter(range(1, bufnr('$')), 'buflisted(v:val) && getbufvar(v:val, "&filetype") != "qf"') return filter(range(1, bufnr('$')), 'buflisted(v:val) && getbufvar(v:val, "&filetype") != "qf"')
endfunction endfunction
@@ -744,8 +763,7 @@ function! s:history_source(type)
endif endif
let fmt = s:yellow(' %'.len(string(max)).'d ', 'Number') let fmt = s:yellow(' %'.len(string(max)).'d ', 'Number')
let list = filter(map(range(1, max), 'histget(a:type, - v:val)'), '!empty(v:val)') let list = filter(map(range(1, max), 'histget(a:type, - v:val)'), '!empty(v:val)')
return extend([' • Press '.s:magenta('CTRL-E', 'Special').' to edit'], return map(list, 'printf(fmt, len(list) - v:key)." ".v:val')
\ map(list, 'printf(fmt, len(list) - v:key)." ".v:val'))
endfunction endfunction
nnoremap <plug>(-fzf-vim-do) :execute g:__fzf_command<cr> nnoremap <plug>(-fzf-vim-do) :execute g:__fzf_command<cr>
@@ -776,22 +794,24 @@ function! s:cmd_history_sink(lines)
call s:history_sink(':', a:lines) call s:history_sink(':', a:lines)
endfunction endfunction
function! fzf#vim#command_history(...)
return s:fzf('history-command', {
\ 'source': s:history_source(':'),
\ 'sink*': s:function('s:cmd_history_sink'),
\ 'options': '+m --ansi --prompt="Hist:> " --info inline-right --header-lines=1 --header-border=horizontal --no-separator --expect=ctrl-e --tiebreak=index'}, a:000)
endfunction
function! s:search_history_sink(lines) function! s:search_history_sink(lines)
call s:history_sink('/', a:lines) call s:history_sink('/', a:lines)
endfunction endfunction
function! s:history_common(name, source, sinklist, prompt, args)
let footer = s:magenta('C-E', 'Special').' Edit'
return s:fzf(a:name, {
\ 'source': a:source,
\ 'sink*': a:sinklist,
\ 'options': ['+m', '--ansi', '--prompt', a:prompt, '--footer', footer, '--expect=ctrl-e', '--scheme=history']}, a:args)
endfunction
function! fzf#vim#command_history(...)
call s:history_common('history-command', s:history_source(':'), s:function('s:cmd_history_sink'), 'Hist:> ', a:000)
endfunction
function! fzf#vim#search_history(...) function! fzf#vim#search_history(...)
return s:fzf('history-search', { call s:history_common('history-search', s:history_source('/'), s:function('s:search_history_sink'), 'Hist/> ', a:000)
\ 'source': s:history_source('/'),
\ 'sink*': s:function('s:search_history_sink'),
\ 'options': '+m --ansi --prompt="Hist/> " --info inline-right --header-lines=1 --header-border=horizontal --no-separator --expect=ctrl-e --tiebreak=index'}, a:000)
endfunction endfunction
function! fzf#vim#history(...) function! fzf#vim#history(...)
@@ -977,7 +997,8 @@ function! fzf#vim#buffers(...)
let sorted = sort(buffers, 's:sort_buffers') let sorted = sort(buffers, 's:sort_buffers')
let tabstop = len(max(sorted)) >= 4 ? 9 : 8 let tabstop = len(max(sorted)) >= 4 ? 9 : 8
let s:buffers_delete_file = tempname() let s:buffers_delete_file = tempname()
let options = ['+m', '-x', '--tiebreak=index', '--ansi', '-d', '\t', '--with-nth', '3..', '-n', '2,1..2', '--prompt', 'Buf> ', '--query', query, '--preview-window', '+{2}/2', '--tabstop', tabstop, '--bind', 'shift-delete:execute-silent(echo {} >> '.s:buffers_delete_file.')+exclude', '--header', '• Press '.s:magenta('SHIFT-DELETE', 'Special').' to unload buffer', '--header-border=horizontal', '--no-separator', '--info=inline-right'] let hint = s:build_hint([['C-A-X', 'Unload']], 1)
let options = ['+m', '-x', '--tiebreak=index', '--ansi', '-d', '\t', '--with-nth', '3..', '-n', '2,1..2', '--prompt', 'Buf> ', '--query', query, '--preview-window', '+{2}/2', '--tabstop', tabstop, '--bind', 'ctrl-alt-x:execute-silent(echo {} >> '.s:buffers_delete_file.')+exclude', '--footer', hint]
if bufnr('') == get(sorted, 0, 0) if bufnr('') == get(sorted, 0, 0)
call extend(options, ['--sync', '--bind', 'start:pos:2']) call extend(options, ['--sync', '--bind', 'start:pos:2'])
endif endif
@@ -1757,13 +1778,13 @@ function! s:commits(range, buffer_local, args)
if &modifiable if &modifiable
call add(expect_keys, s:paste_key()) call add(expect_keys, s:paste_key())
endif endif
let hint = s:build_hint([['C-S', 'Toggle sort'], ['C-Y', 'Yank hashes']], 1)
let options = { let options = {
\ 'source': source, \ 'source': source,
\ 'sink*': s:function('s:commits_sink'), \ 'sink*': s:function('s:commits_sink'),
\ 'options': s:reverse_list(['--ansi', '--multi', '--tiebreak=index', \ 'options': s:reverse_list(['--ansi', '--multi', '--scheme=history',
\ '--info=inline-right', '--prompt', command.'> ', '--bind=ctrl-s:toggle-sort', \ '--prompt', command.'> ', '--bind=ctrl-s:toggle-sort',
\ '--header-border=horizontal', '--no-separator', \ '--footer', hint,
\ '--header', '• Press '.s:magenta('CTRL-S', 'Special').' to toggle sort, '.s:magenta('CTRL-Y', 'Special').' to yank commit hashes',
\ '--expect=ctrl-y,'.join(expect_keys, ',')]) \ '--expect=ctrl-y,'.join(expect_keys, ',')])
\ } \ }