Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toggle-bind action bind (allow reuse of the same keybind for unbind|rebind) #2865

Closed
3 tasks done
ibhagwan opened this issue Jul 8, 2022 · 2 comments
Closed
3 tasks done

Comments

@ibhagwan
Copy link

ibhagwan commented Jul 8, 2022

  • I have read through the manual page (man fzf)
  • I have the latest version of fzf
  • I have searched through the existing issues

Info

First, ty @junegunn for this magical piece of software!

Related #2564, #2843.

Following the very useful example Switching between Ripgrep mode and fzf mode, a use can press ctrl-f to unbind the change event, enable search and fuzzy match followed by a ctrl-r to rebind the change event and disable search.

The above IMHO can be more efficient if there was a toggle-bind action, in the above example, there's no real point of pressing ctrl-r or ctrl-f more than once, you only press it when you wish to toggle from disabled search to fuzzy search and vice versa, with a toggle-bind action we could have one keybind (say ctrl-r) to switch back and forth between the different modes.

This could be futher improved with:

  • The ability to have different queries saved for each mode (disabled/enabled search query) so that when we toggle the action we don't lose the context of what was originally searched for
  • A change-header action with support for the current query so that when the user switches mode the header can display the query from the previous mode

An exmaple for the above would be:

  • Start fzf in disabled mode with rg and search for foo.*
  • Toggle to fuzzy search mode and display in the header results for regex: foo.* (so now we know what we're doing fuzzy searching on)
  • When toggling back from fuzzy to disabled the query changes back to foo.* as the fuzzy query doesn't make much sense in this context
  • Now we modify the query to bar.* and toggle back to fuzzy, the header will now display results for regex: bar.*` and also restore the previous query that was typed in fuzzy mode*

I have a working exmaple of the above in my neovim plugin fzf-lua by using a single bind ctrl-g, I created this before the rebind action was introduced by restarting the fzf process with different options that were saved externally, you can watch this exact same behavior in action below to see how useful it is:

Notice how the both the prompt and the header change depending on the mode we're in

Peek 2022-07-07 19-03

@junegunn
Copy link
Owner

Following the very useful example Switching between Ripgrep mode and fzf mode

toggle-bind action we could have one keybind (say ctrl-r) to switch back and forth between the different modes.

I thought about the option, but I decided that it was not going to be particularly useful in that context because

  1. We can't switch between two prompts with a single binding (e.g.1. ripgrep> vs. 2. fzf> )
  2. We can't switch between two reload commands (e.g. directories vs. files)

This could be futher improved with:
...

So we would need more options than just toggle-bind, and it starts to feel a lot like a feature creep. So I'm not sure about the direction.

Your example already seems to work great, what would it benefit from these additional functionalities?

@ibhagwan
Copy link
Author

So we would need more options than just toggle-bind, and it starts to feel a lot like a feature creep. So I'm not sure about the direction.

You’re correct, this would be quite a big change.

Your example already seems to work great, what would it benefit from these additional functionalities?

Currently, the only downside of my approach is the fact I have to restart the ripgrep process each time I toggle from fuzzy to regex, admittedly it’s not a big deal on most repos but on really large codebases you can argue for the performance benefit of not having to rerun rg, in my example, say you searched for foo.* when you press ctrl-g the fzf process is restarted with $FZF_DEFAULT_COMMAND = 'rg … 'foo.*' for the fuzzy search mode, with a toggle-bind we can just reuse the current result set (same as with unbind).

Quite honestly Fzf is perfect as is so this would be a luxury feature, I guess we can close this issue.

Ty again for your amazing software!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants