-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Document keymap context #14718
Comments
Yep. We could use some better documentation around context for keybindings. Here's a non-exhaustive list of contexts used by the default bindings.
Plus a bunch more in vim.json
Editor
If you have no panels in focus, no files open
Markdown preview.
This would be a useful enhancement. |
What does |
|
A primer: Contextes:
Context operators:
Variables:
I grepped from keymaps, not Rust. |
From grepping Rust code: Identifiers (
Context Key/values (
|
I spent the last few days configuring zed, and have found keybind configuration has some room for improvement :) A few notes: It took a while to get over the initial confusion of what contexts actually are. do they relate to the mere presence of an element? or does it have to have focus? if one context is active does it deactivate others or do they coexist? is there some hierarchical structure to them? how do they relate to actions, given the similar prefixes? how are keybind conflicts resolved? Here are my conclusions, please correct me if I'm wrong:
One could compare it to the following html and css selectors: <div class="Global">
<div class="Workspace">
<div class="Pane">
<div class="BufferSearchBar">
<div class="Editor">
<!-- search --> <!-- .Workspace > .Pane > .BufferSearchBar > .Editor -->
</div>
</div>
<div class="Editor">
<!-- buffer --> <!-- .Workspace > .Pane > .Editor -->
</div>
</div>
</div>
</div> It's possible to apply rules It's possible to specify the same context multiple times, where the last one wins. This can be useful when a command may not succeed to make it fallback to a previous one, see this example: [{
"context": "Editor && mode == full",
"bindings": {
"f1": "buffer_search::Deploy" // only gets called if "buffer_search::FocusSearch" fails
}
},{
"context": "Editor && mode == full",
"bindings": {
"f1": "buffer_search::FocusSearch" // focus if open, else look for next action
}
}] Which feels like an anti-pattern, would be nice to have a way of specifying fallback commands. This is how micro deals with it: What I would like to see:
A few observations:
And some additional suggestions:
|
I feel like these variables should be documented somewhere! I had to use the
|
Apparently, this document is outdated. I tried |
Yes, same for |
I am confused, I thought that this would work for file finder, project finder and buffer list but it's not {
"context": "menu",
"bindings": {
"ctrl-j": "menu::SelectNext",
"ctrl-k": "menu::SelectPrev"
}
} It works if I remove context. I also tried ProjectSearchBar, BufferSearchBar etc... no context work. I often times am confused about what to insert here and what are the possibilities. This really need a better documentation because it's most likely a deal breaker compared to the way we can configure Neovim |
I have setup some keybinds like this : However, when I open the assitant panel, it stills uses this keyind, so the !AssistantPanel does not seems to take effect. Is it because of cascading rules ? Is there a way to have keyinds disabled in the assistant panel ? |
Would be super useful if there was a command that would show/print what context you are currently in to make it easier to create your keymaps. |
Yeah, we could certainly do better here, but I recommend you look at the existing Contexts in default-linux.json or default-macos.json as a reference. Because sometimes in addition to knowing your current context (e.g. zed/assets/keymaps/default-macos.json Lines 446 to 452 in b83b42b
There has been discussion about building a debug window (like |
that would be super awesome. confusion about contexts and why some keybindings are not working / being overridden has been by far my biggest pain point in adopting Zed (although that isn't saying much - it's been wonderful with almost everything else). |
IMO it would be ideal if we could have a command like "currentContext": "ContextC",
"activeContexts": ["ContextB", "ContextC"]
"keys": {
"ctrl-g": {
"activeBindings": [
"ContextB": "bar",
"ContextC": "baz"
]
}
} if the last one is the winner, then that makes it easy to figure out why it's doing you can also see |
I agree with Andrew. There needs to be some debuggability here. I am trying to remove the cmd-r (which toggles the right dock) with |
It'd be a huge huge win to have a way to debug keybindings. Specifically, it would have two bits of functionality:
That would make it much easier to rebind keys to the hotkeys that I want. Right now, the context and the keybinding actions are really undiscoverable. @Apromixately I've seen |
One thing I'm finding surprising, it seems that I'm trying to redo how assist/inline assist get opened and submitted, so I had a I had to move the cmd-enter binding to |
Detailing another issue with key binding resolution: I'm coming from intellij, where cmd+enter is "open code actions menu". In editor, cmd-enter creates a newline, and in the assistant, cmd-enter submits the query to the assistant. Looking at default macos keybindings, cmd-enter exists in both Ok, then, I just need a custom keybinding for One short-term solution, is it possible to add debug or trace log lines when keybindings are dispatched, so that I can launch Zed with that log level, and see both the context and the command being executed? |
@leo91000 After lots of trial and error, I found that SummaryQuick summary of the rules I've discovered so far, for myself and others:
Quick summary of contexts I'm using:
Lastly, it's worth noting that the internal keybindings seem to have different precedence rules. The example I described in my previous post is one example. Looking at |
The lack of clear documentation around contexts is the last thing keeping me from adopting Zed over Neovim for most editing sessions. I use a 99% keyboard-centric workflow and I, for the life of me, can't get some of my simple keybinding cases to work. Having a debug window that displays the current context would be immensely helpful, as well as documentation around precedence. |
@lcrownover try command "debug: open key context view",I find it's very helpful to view UI context stack and keybinding matching. |
Closing this now the documentation is more up-to-date and the debug view exists. |
I also want to know the meaning of |
|
got it, thanks! |
Check for existing issues
Describe the feature
Hi,
Reading https://github.com/zed-industries/zed/blob/main/docs/src/key-bindings.md, I don't find a proper documentation of
"context"
query in keymaps.json. Could you document this ?My questions:
mode
?Markdown
?Regards,
Étienne
If applicable, add mockups / screenshots to help present your vision of the feature
No response
The text was updated successfully, but these errors were encountered: