junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
63.17k stars 2.37k forks source link

Configure fzf not to use "alternate screen" behavior when canceling the history search #2083

Open unphased opened 4 years ago

unphased commented 4 years ago

Info

Problem / Steps to reproduce

I'd like to be able to configure fzf when I use it with the ctrl+R binding (in zsh) to leave the buffer present on screen if I cancel the search. Half of the time I use history recall with fzf to re-run something (in this case I want the buffer to clear), but the other half of the time I want to see what I ran before and cancel it and run it modified. It would be nice to have it leave the buffer as-is so I can refer to the output as I construct the new command.

I have tested with echo 'abc\ndef' | fzf --no-clear that this works as expected, but adding --no-clear to the (pretty complex) FZF_DEFAULT_OPTS= in fzf-history-widget in ~/.fzf/shell/key-bindings.zsh had no effect. It seems like either it conflicts or is negated by some of the other configuration here?

I was hoping I could at least make it leave the buffer up no matter what, but I couldn't even get that working.

junegunn commented 4 years ago

You can move your cursor around with ANSI escape sequences like so:

# Enter => delete it
# CTRL-C => leave it
fzf --no-clear --height 20 > /dev/null && echo -e "\x1b[J\x1b[A" || echo -e "\x1b[19B"

But I'm not sure if it's possible to achieve this behavior just by setting FZF_CTRL_R_OPTS.