Canonicalize the two fzf key aliases before comparing

fzf reads 'return' as 'enter' and 'alt-return' as 'alt-enter', so
show_key='alt-return' passed the check against the default paste key and
--expect closed fzf while the footer advertised Show. ctrl-m is not an alias,
it goes through the generic ctrl- branch to its own event.
This commit is contained in:
Junegunn Choi
2026-08-27 00:01:26 +09:00
parent c63f25a2ba
commit 05b2324b75
+6 -2
View File
@@ -361,7 +361,7 @@ function! s:build_hint(entries, defaults, ...)
let keys = []
let actions = get(g:, 'fzf_action', s:default_action)
if a:defaults
if index(taken, 'enter') < 0 && index(taken, 'return') < 0
if index(taken, 'enter') < 0
call add(entries, ['Enter', 'Open'])
endif
for [key, name, label] in [['ctrl-x', 'C-X', 'HSplit'], ['ctrl-v', 'C-V', 'VSplit'], ['ctrl-t', 'C-T', 'Tab']]
@@ -442,6 +442,9 @@ function! s:show_key()
return s:conf('show_key', 'ctrl-o')
endfunction
" fzf spells these two events more than one way
let s:key_aliases = {'return': 'enter', 'alt-return': 'alt-enter'}
" A key can be a comma-separated list, which fzf binds to every key in it.
" fzf escapes 'alt-,' before splitting on the comma, so do the same. It also
" lowercases a key name before matching it, except for 'alt-X' and a bare
@@ -452,8 +455,9 @@ function! s:split_keys(keys)
let keys = map(split(substitute(a:keys, '\c\(alt-\),', '\1'.sep, 'g'), ','),
\ 'substitute(v:val, sep, ",", "g")')
" 'alt-X' keeps X as typed but not its prefix, so fold only the prefix there
return map(keys, 'strchars(v:val) == 1 ? v:val
call map(keys, 'strchars(v:val) == 1 ? v:val
\ : v:val =~? "^alt-.$" ? "alt-".v:val[4:] : tolower(v:val)')
return map(keys, 'get(s:key_aliases, v:val, v:val)')
endfunction
" 'ctrl-alt-x' -> 'C-A-X' and 'double-click' -> 'Dbl-Click', to match the