Fzf: Pressing <Esc>C when using set -o vi calls fzf and deletes the line being edited

Created on 13 Mar 2018  路  4Comments  路  Source: junegunn/fzf

  • Category

    • [ ] fzf binary

    • [ ] fzf-tmux script

    • [x] Key bindings

    • [ ] Completion

    • [ ] Vim

    • [ ] Neovim

    • [ ] Etc.

  • OS

    • [x] Linux

    • [ ] Mac OS X

    • [ ] Windows

    • [ ] Windows Subsystem for Linux

    • [ ] Etc.

  • Shell

    • [x] bash

    • [ ] zsh

    • [ ] fish

I use the vi editing mode for bash. Specifically the line set -o vi is in my .bashrc file and set show-mode-in-prompt on in my .inputrc.

The sequence EscC while in insert mode results in a call to fzf, which is not what should be done, since that sequence of keys is what one press if wants to exit insert mode and change something (_e.g._ EscCB, ...). Actually the problem exists only if the two keys Esc and C are pressed in rapid succession, no matter what mode is active before the combo.

EDIT
I noticed that what happens when I press EscC is a call to __fzf_cd__, which is binded, in the key-bindings.bash file, to the escape sequence \ec, for which the comment reads # ALT-C - cd into the selected directory; indeed, when I press EscC the same thing happens as I had pressed Alt+C. After all, I verify, by preceding them with Ctrl+V on the command line, that both EscC and Alt+V are represented with the characters ^[c, which should be the same as \ec.

Most helpful comment

Yeah, ALT-C is indeed ESCC, that's how terminals interpret alt key chords. I can see that it can be a problem on vi-mode, but I'm not sure if I can change the binding and break backward compatibiliy. If that's too annoying, you might want to disable the binding:

set -o vi
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
[[ $- =~ i ]] && bind '"\ec": nop'

or bind the functionality to another key chord like so

set -o vi
[ -f ~/.fzf.bash ] && source ~/.fzf.bash

# Re-bind it to CTRL-Q
bind "$(bind -s | grep '^"\\ec"' | sed 's/ec/C-q/')"
[[ $- =~ i ]] && bind '"\ec": nop'

All 4 comments

Yeah, ALT-C is indeed ESCC, that's how terminals interpret alt key chords. I can see that it can be a problem on vi-mode, but I'm not sure if I can change the binding and break backward compatibiliy. If that's too annoying, you might want to disable the binding:

set -o vi
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
[[ $- =~ i ]] && bind '"\ec": nop'

or bind the functionality to another key chord like so

set -o vi
[ -f ~/.fzf.bash ] && source ~/.fzf.bash

# Re-bind it to CTRL-Q
bind "$(bind -s | grep '^"\\ec"' | sed 's/ec/C-q/')"
[[ $- =~ i ]] && bind '"\ec": nop'

Wow. Maybe I've always missed this: when I press Alt-C, where C can be any key, my keyboard is really sending the same electrical signal as I had quickly pressed EscC, so there's no way to distinguish which one was pressed, right?

Because I had to invest some time to find this out, in zsh this seems to work for me:

[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
[[ $- =~ i ]] && bindkey -r '\ec'

EDIT: But I do like the feature, so rebound it to alt-q as suggested above in zsh with (fzf version 0.17.3)

bindkey '\eq' fzf-cd-widget

I never press esc q in quick succession, so for now it isn't a problem for me.

I opened an issue with a similar problem: https://github.com/junegunn/fzf/issues/1291

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chrisamow picture chrisamow  路  3Comments

jberglinds picture jberglinds  路  3Comments

ahmedelgabri picture ahmedelgabri  路  3Comments

ahmedelgabri picture ahmedelgabri  路  3Comments

erusev picture erusev  路  3Comments