zed icon indicating copy to clipboard operation
zed copied to clipboard

Keymap does not work

Open zongUMR opened this issue 2 years ago • 15 comments

Check for existing issues

  • [X] Completed

Describe the bug / provide steps to reproduce it

I defined customized keymap but it doesn't work.

Environment

Zed: v0.73.3 (stable)
OS: macOS 13.1.0
Memory: 16 GiB
Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

Screenshot 2023-02-20 at 11 06 12

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

If you only need the most recent lines, you can run the zed: open log command palette action to see the last 1000.

Althougth the below log has an invalid keystore ctrl-c-d error, but I already changed it to ctrl-c ctrl-d, but doesn't work either. log.txt

zongUMR avatar Feb 20 '23 03:02 zongUMR

ctrl-c is bound to menu::Cancel in the default keymap, so your bindings dont have a chance to reach the second key.

This issue is a ux and understandability problem with our keybinding system. Some ways forward:

  1. We must give users a way to understand what action is being dispatched by a given keypress maybe through a toggleable setitng or log
  2. We should surface to the user when there are pending keys in the matcher. This would make it more obvious when a key has already been consumed
  3. We must give the user a way to override these default bindings. Today later bindings match first, but this doesn't properly handle when bindings have multiple steps as shown above.

Kethku avatar Feb 20 '23 10:02 Kethku

Yes exactly, I think the 3rd point is the most important for an ending user.

zongUMR avatar Feb 23 '23 01:02 zongUMR

@Kethku Will Zed allow users to override the default bindings in the next release? So I can use ctrl-c ctrl-d to trigger goToDefiniton action, it is an important and useful shortcut for me like in other editors

zongUMR avatar Feb 23 '23 02:02 zongUMR

Unfortunately no. I will make sure to discuss this with the team to come up with a fix soon

Kethku avatar Feb 23 '23 02:02 Kethku

I guess this is the same thing I reported some time ago in https://github.com/zed-industries/zed/issues/5649 I'll close that one as it didn't manage to get any comment

aexvir avatar Feb 23 '23 18:02 aexvir

Unfortunately no. I will make sure to discuss this with the team to come up with a fix soon

Is it possible to bind g-d to goToDefinition? I tried it but did not work either.

zongUMR avatar Feb 25 '23 05:02 zongUMR

Unfortunately no. I will make sure to discuss this with the team to come up with a fix soon

Is it possible to bind g-d to goToDefinition? I tried it but did not work either.

I'm looking for this too

andrew-ares avatar Feb 25 '23 06:02 andrew-ares

Unfortunately no. I will make sure to discuss this with the team to come up with a fix soon

Is it possible to bind g-d to goToDefinition? I tried it but did not work either.

What do you mean by this? Do you mean pressing the g and d keys together and queueing a goToDefinition action?

Kethku avatar Feb 25 '23 22:02 Kethku

Press g and immediately with a d to trigger the goToDefinition action, it's a very common action in VIM

zongUMR avatar Feb 27 '23 01:02 zongUMR

Oh I see. This can be done today using some vim specific keymap contexts.

Most of the operators in vim mode will set the vim_operator context variable for active editors to the operator key. So for this case, you can use vim_operator == g to create bindings locked behind the g key in normal mode.

Binding g d to goToDefinition looks like this:

{
    "context": "Editor && vim_operator == g",
    "bindings": {
        "d": "editor::GoToDefinition"
    }
}

Add that to your personal keymap and you should be good to go.

Kethku avatar Feb 27 '23 18:02 Kethku

TBH I might add this as a default binding. I'll go do that right now.

Kethku avatar Feb 27 '23 18:02 Kethku

Oh I see. This can be done today using some vim specific keymap contexts.

Most of the operators in vim mode will set the vim_operator context variable for active editors to the operator key. So for this case, you can use vim_operator == g to create bindings locked behind the g key in normal mode.

Binding g d to goToDefinition looks like this:

{
    "context": "Editor && vim_operator == g",
    "bindings": {
        "d": "editor::GoToDefinition"
    }
}

Add that to your personal keymap and you should be good to go.

It works, thanks Kethku

zongUMR avatar Feb 28 '23 01:02 zongUMR

I am also having an issue where I am not sure what happens when I press keys.

I tried to add some shortcuts I am familiar with from VS Code, but none of them are working:

{
  "context": "Editor",
  "bindings": {
    "cmd-shift-k": "editor::DeleteLine",
    "alt-up": "editor::MoveLineUp",
    "alt-down": "editor::MoveLineDown",
    "alt-shift-up": "editor::DuplicateLine",
    "alt-shift-down": "editor::DuplicateLine"
  }
}

obahareth avatar Jan 29 '24 16:01 obahareth

I am trying to re-bind ctrl-1 to shift-1 because my pinky hurts 🤕

{
    "context": "Editor && vim_mode == normal && !VimWaiting && !menu",
    "bindings": {
      // put key-bindings here if you want them to work only in normal mode
      "space l": "pane::SplitRight",
      "space h": "pane::SplitLeft",
      "space p": "file_finder::Toggle",
      "space k": "editor::MoveRight",
      "shift-1": ["pane::ActivateItem", 0],
      "shift-2": ["pane::ActivateItem", 2],
      "shift-3": ["pane::ActivateItem", 3]
    }
  },

However, it does not seem to be working 😞

munozr1 avatar Feb 21 '24 13:02 munozr1

However, it does not seem to be working 😞

Yeah, I think the problem is that we don't send shift-1 but ! (on my keyboard) to the editor. Can you open a separate ticket for that?

mrnugget avatar Feb 26 '24 12:02 mrnugget

Is there any movement on this? I want to map editor:MoveLineUp to ctrl-k, but that's already taken by editor::CutToEndOfLine.

I've spent so long trying to figure this out. It seems like this is an ordering issue, the default's shouldn't take precedence when evaluating a key binding, the user's should have priority.

Are there plans to address in an upcoming release? 🙏

lougreenwood avatar Jul 18 '24 11:07 lougreenwood

I just tested the original keymap submitted in this issue and all of the bindings work for me, so I think the original issue here is solved. For any other issues brought up in this thread, please open up a new issue!

JosephTLyons avatar Jul 27 '24 20:07 JosephTLyons