fzf
fzf copied to clipboard
Sometimes: Return swaps with CTRL-J
- [x] I have read through the manual page (
man fzf
) - [x] I have the latest version of fzf
- [x] I have searched through the existing issues
Info
- OS
- [x] Linux
- [ ] Mac OS X
- [ ] Windows
- [ ] Etc.
- Shell
- [ ] bash
- [x] zsh
- [ ] fish
Problem / Steps to reproduce
In some instances, seemingly randomly, maybe 1/100, my Return key for accepting a selection swaps with CTRL-J (so that Return moves the selection down and CTRL-J accepts the selection), while CTRL-K keeps working normally, I have been experiencing this issue for some years, so I do not think it's recent.
Would deeply appreciate any pointers as to what could cause this, as it happens infrequently, but more than once a day, it's been hard to pin down.
Is there any debug mode / verbose debug prints I can set for fzf that could shed some light onto this?
Thanks for any pointers and thanks for the amazing Software!
I just found a way to reliably reproduce this:
I have a zsh-binding (CTRL-G) that opens fzf
with all of the git branches of the current directory and allows me to select one, which then gets added to the prompt where my cursor sits.
# {{{ fzf - list git branches
list_git_branches_via_fzf() {
local branch=$(git branch | awk -F ' +' '! /\(no branch\)/ {print $2}' | fzf) || exit 1
LBUFFER+="$branch"
zle .reset-prompt
}
zle -N list_git_branches_via_fzf{,}
bindkey '^G' list_git_branches_via_fzf
# }}}
If I very quickly start a new terminal-emulator instance (I tried different terminal-emulators, happens with all of them) and immediately press that zsh-bind (I have to be very quick), this exact behavior will occur.
This way it is reproducible on my end. However if I wait, say, a full second after opening the terminal emulator, it does not seem to occur to all.
It seems to also very consistently happen if I start fzf
immediately after an application that puts the terminal in noncanonical mode exits.
e.g. if I quit vim
and immediately queue up CTRL-G (my zsh-bind that then starts fzf
), the terminal seems to exit the noncanonical mode of vim
, presumably then re-enter canonical mode (for the normal zsh
prompt?) and then seemingly some terminal attributes get mixed up while opening up fzf
and the problem as described here occurs.
I should add that I'm a needlessly fast typer, yet I really struggle to slow down when typing.
It would be great to find out the cause of this.
Maybe the handling of the terminal attributes can be more robust, if my theory works out, I'd be really interested what terminal attribute could even cause the problem described in this issue (that CTRL-J and Return effectively swap behavior).
Thanks for any response.
I really have no idea what's going on your side. Some pointers you might want to take a look:
- https://stackoverflow.com/questions/71755990/ctrl-j-is-always-changed-to-ctrl-m-in-session-started-by-aws-session-manager
- https://github.com/vim/vim/issues/2031
Anyway, if the issue is constantly bothering you, I suggest that you bind CTRL-J
to accept
in your $FZF_DEFAULT_OPTS
. You'll lose the ability to move the cursor down with CTRL-J
, but you can still use CTRL-N
(paired with CTRL-P
) instead.
export FZF_DEFAULT_OPTS='--bind ctrl-j:accept'
Thanks for your response and your feedback!
I'm very committed to CTRL-J
navigation, I plan to debug this further by intercepting tty communication (maybe https://github.com/geoffmeyers/interceptty) and trying to figure out exactly why this happens on my end.
I'd really like to get at the root of this, as fzf
is invaluable to me, I'll update this issue once I know more.
Thanks for your amazing work!