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

Remap UI keybindings #214

Open
Oppen opened this issue Dec 17, 2022 · 11 comments · May be fixed by #356
Open

Remap UI keybindings #214

Oppen opened this issue Dec 17, 2022 · 11 comments · May be fixed by #356

Comments

@Oppen
Copy link

Oppen commented Dec 17, 2022

Is your feature request related to a problem? Please describe.
It's a bit of a usability annoyance. I'm used to using Vim so just using the home row is practical. Right now I need to do hand gymnastics to use Ctrl+d and Ctrl+u for navigating the preview bar and find it rather uncomfortable.

Describe the solution you'd like
I'd like to be able to remap those keys in my configuration file so J and K (mind the case) are used instead.
Note I'm not 100% sure this isn't currently possible, but going through the README and the source code I couldn't find anything useful.

Describe alternatives you've considered
There aren't many. Essentially it's either hardcoding my preferences (not very considerate to others used to the current workflow) or making it configurable.
I'd say the current keybinding section may benefit from some UI action syntax or maybe a new section could be added for the UI interaction.

@dlvhdr
Copy link
Owner

dlvhdr commented Dec 17, 2022

Sounds good! Thanks for the issue

@robdimsdale
Copy link
Contributor

I'd like to +1 on this general idea for a different use-case. In my specific case, I'd like to use tab to switch views: it's just way more intuitive to me to use tab rather than s. For my own use-case I can change the code and rebuild, but I'd prefer to be able to set this in the global config.

I took a look, but I also don't see an easy way of changing the built-in defaults for keybindings.

@dlvhdr If you agree that configurable overrides for default/built-in keybindings is a good idea, I'd be willing to submit a PR for this. I'd want to make sure we're on the same page as far as architecture/design before submitting a PR though - especially as this would result in additions to the config file.

@dlvhdr
Copy link
Owner

dlvhdr commented Jan 16, 2023

This is definitely something I'm interested in.
My initial thoughts are around adding this to the config with default values like I've done for other options. I usually look at how lazy-git's config is structured for inspiration.
For example you can see the keybinding section here

I think this is where I set the default values

@robdimsdale
Copy link
Contributor

Gotcha - thanks. I think it's still valuable to keep the default config defined in the app but allow overriding of specific keybindings via the config file. This is consistent with the approach lazygit takes. Let me know if you disagree here.

I'd propose adding the following to the config file:

keybindings # already exists
  prs: [] # already exists
  universal: # new
    up: "up"
    upAlt1: "k"
    firstLine: "g"
    firstLineAlt1: "home"
    [ ... other keys omitted for clarity ...]
  pr:
    comment: "c"
    diff: "d"
    [ ... other keys omitted for clarity ...]
  issue:
    comment: "c"
    close: "x"
    [ ... other keys omitted for clarity ...]

I don't love the fact that this introduces a new key: keybindings.pr alongside the existing key: keybindings.prs, but I don't see a better solution unless we introduce a breaking change (e.g. moving keybindings.prs to keybindings.pr.custom_commands or similar) which I think is a bad idea for users.

Does this align with your expectations? Do you have another config in mind?

I don't yet have a super clear mental model of how to propagate the keybinding config into the app, but I think that will be clearer once I start working on the PR itself.

@dlvhdr
Copy link
Owner

dlvhdr commented Jan 18, 2023

I think another approach that avoids breaking changes (which I also want to avoid) is to introduce a syntax like this:

keybindings # already exists
  universal: # new
    - key: up
      command: up
    - key: k
      command: upAlt1
    - key: g
      command: firstLine
    - key: home
      command: firstLineAlt1
  prs:
    - key: v # example for a custom keybind
      command: cd {{.RepoPath}} && code . # && gh pr checkout {{.PrNumber}}
    - key: c
      command: comment
    - key: d
      command: diff
  issues:
    - key: c
      command: comment
    - key: x
      command: close

If we're worried about conflicts with some bash alias or tool etc, we can add another key like builtin: up or something. Or prefix the command with dash up.

@robdimsdale
Copy link
Contributor

robdimsdale commented Jan 18, 2023

In principle, I like this more than my suggestion. However, I worry that it will be a little confusing to differentiate custom commands from builtins. In the example above, prs: [{key: d, command: diff}] is both a builtin and also a valid external command. How would we prevent users from re-mapping a builtin to a custom command?

I think this is what you are alluding to with:

If we're worried about conflicts with some bash alias or tool etc, we can add another key like builtin: up or something. Or prefix the command with dash up.

But I don't quite follow the suggestion here.

@dlvhdr
Copy link
Owner

dlvhdr commented Jan 18, 2023

Yes exactly. I'm alluding to the confusion / conflict when a custom command like diff is also a builtin command.
My suggestion would be to make the config like this for example:

  prs:
    - key: v # example for a custom keybind
      command: cd {{.RepoPath}} && code . # && gh pr checkout {{.PrNumber}}
    - key: c
      command: dash comment
    - key: d
      command: dash diff

OR

  prs:
    - key: v # example for a custom keybind
      command: cd {{.RepoPath}} && code . # && gh pr checkout {{.PrNumber}}
    - key: c
      builtin: comment
      # or
      dash: comment
      # or
      dash-command: comment

Maybe you can think of a better name than builtin, as English isn't my native language.

@robdimsdale
Copy link
Contributor

Ah, right, glad we're on the same page. Thank you for the examples - that clarifies it for me.

I think command: dash comment is confusing because what if dash is a command on a user's machine. How would they (and gh-dash) disambiguate between the built-in function and the external command dash?

Maybe you can think of a better name than builtin, as English isn't my native language.

I can't come up with anything better than builtin so I think we should go with that.

@dlvhdr
Copy link
Owner

dlvhdr commented Jan 25, 2023

Sounds good!

@miniscruff
Copy link
Contributor

Is this up for grabs? I am open to giving it a try.

@dlvhdr
Copy link
Owner

dlvhdr commented Apr 12, 2024

Yeah definitely @miniscruff!

@miniscruff miniscruff linked a pull request Apr 14, 2024 that will close this issue
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 a pull request may close this issue.

4 participants