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

Overhaul custom key bindings to be a first-class feature #172

Merged
merged 21 commits into from
Jun 11, 2021

Conversation

PatrickF1
Copy link
Owner

@PatrickF1 PatrickF1 commented Jun 10, 2021

Setting custom key bindings is horrible experience. It's time to give it a make over!

Background and motivation

fzf.fish ships with default key bindings that are mnemonic and have minimal conflicts with existing fish key bindings. However, for users who want to change them, the process of customizing them is frustrating and confusing at best. This frustration has culminated in a steady stream of issues, discussions, PRs, and Wiki sections around key bindings (#17, #89, #99, #108, #103, #153, #162, Wiki section). Here are the shortcomings of making custom bindings DIY:

  • Besides not installing the default bindings if fzf_fish_custom_keybindings is set, the plugin provides zero assistance to the user when it comes to installing the custom bindings. Users have to study config/fzf.fish, bind documentation, and maybe even learn some fish syntax to learn how to set their own key bindings. This is a quite daunting task. Furthermore, users have to reference functions clearly denoted private (__fzf_search_*)., which feels and use hacky. Ideally,
    the plugin does not require typical users to dive into its code and will abstract private functions away completely.
  • fzf_fish_custom_keybindings is all or nothing; users have to opt out of ALL default key bindings and re-bind them themselves even if they only want to change one. This is tedious, verbose, and unwieldy. A good plugin should allow tweaking the key binding while maintaining the rest of the defaults.
  • Because the fzf_fish_custom_keybindings has to be set before config/fzf.fish is executed, it has to be created as a universal variable. Unfortunately, universal variables are a very confusing point for new fish users.
  • And because it needs to be universal, it's bad practice to add it to one's config.fish. This makes it more difficult for one's fzf.fish configuration to be checked into git.

As the plugin author, I have also felt the pain of working around this DIY custom binding mechanism:

  • Because custom bindings are so painful to use, user forego custom bindings and get stuck with the defaults, which puts a lot of pressure on me (subconsciously and through the many issues opened) to make the default bindings suitable for everyone. Unfortunately, the goal of having a default set of key bindings that is suitable for even 80% of users while being easy to learn (or mnemonic) is nigh impossible, requiring a thorough understanding of the multitudes of CLIs and terminals people use, the ways they use them, and they key binding. I've concluded this task is ultimately futile because key bindings are very idiosyncratic. Therefore, custom key bindings should be a first class feature that is well supported, completely documented, flexible, painless to use, and directly encouraged.
  • Any change, even an addition (such as a new feature), to the default key bindings is an outsized, monumental event because it's not transparent and hard to communicate to users. In fisher, there isn't a mechanism for precisely warning users of backwards incompatible changes. Furthermore, the only place where the default key bindings are officially listed is on the readme. The best I can do is to cut a new major release and post on Reddit and Gitter to announce any and all key binding changes. But still, most users will probably be left in the dark when their key bindings silently break on the next update. If more users customized their key bindings and (which they don't because again, it's not well supported) and there was an interface to quickly view the default key bindings, this would be a much smaller problem.
  • Because users have to hardcode in the function names for their custom key bindings, fzf.fish's internal functions are not really private and I cannot rename them as they morph. This is important to me as the names of some features, and therefore the ideal function name, have shifted since their inception.
  • Finally, fzf_fish_custom_keybindings has an annoying typo: key binding is two words, not one.

The new solution

A new function called fzf_configure_bindings solves or mitigates all of the aforementioned problems. It:

  • serves as a wrapper around the key bindings and fzf.fish's private functions so that they are properly abstracted away under a lightweight interface.
  • allows customizing the key binding for each feature through namesake options (e.g. --directory controls the search directory key binding). Bindings can be overridden or, if the user doesn't want to use the feature, even disabled.
  • uses mnemonic key sequences by default for features that the user chooses to not customize. This means that to change the key bind for a single feature, only one option needs to be specified.
  • comes with great, easy-to-read help documentation that prints if used incorrectly.
  • includes the default key bindings in its help message so users can easily and quickly find them.
  • is robust and thoroughly tested.
  • will include command completion (to be implemented later).

@PatrickF1 PatrickF1 force-pushed the key-bind-function branch 3 times, most recently from 2bf5c33 to a4a2121 Compare June 10, 2021 21:29
@PatrickF1 PatrickF1 force-pushed the key-bind-function branch 2 times, most recently from bae1392 to f5b0af7 Compare June 10, 2021 23:41
@PatrickF1 PatrickF1 force-pushed the key-bind-function branch 3 times, most recently from bc35d42 to 9ea27d4 Compare June 11, 2021 05:35
@PatrickF1 PatrickF1 changed the title Overhaul key binding mechanism Overhaul custom key bindings to be a first-class feature Jun 11, 2021
@PatrickF1 PatrickF1 merged commit 0fa7c34 into main Jun 11, 2021
@PatrickF1 PatrickF1 deleted the key-bind-function branch June 11, 2021 16:46
PatrickF1 added a commit that referenced this pull request Jun 12, 2021
forgot to remove it in #172 when I overhauled the custom key binding mechanism
PatrickF1 added a commit that referenced this pull request Jun 12, 2021
I forgot to remove it in #172 when I overhauled the custom key binding mechanism. Also shortened the section on customize key binding.
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

Successfully merging this pull request may close these issues.

1 participant