Fix VSCode base keymap discrepancies

Give the VSCode base keymap its own overlay assets instead of being an
alias for the default (now Zed) keymap, and fix the bindings where Zed's
defaults diverge from actual VS Code: Format Document (shift-alt-f),
Format Selection, insert cursors at line ends (shift-alt-i), toggle word
wrap (alt-z), Zen Mode (cmd-k z / ctrl-k z), parameter hints, AST
selection expansion (macOS), find regex toggle (macOS), block comment
(Linux), open definition to the side, and F5/F10 debugger bindings.
This commit is contained in:
Kirill Bulatov 2026-07-09 18:13:54 +03:00
parent 04f471f946
commit 731fb7e3d8
4 changed files with 125 additions and 2 deletions

View file

@ -0,0 +1,41 @@
[
// VS Code for Linux (and Windows). See: https://code.visualstudio.com/docs/reference/default-keybindings
//
// Zed's default keymap is close to VS Code's, so this overlay only contains
// the bindings where the two diverge.
{
"context": "Editor",
"use_key_equivalents": true,
"bindings": {
"shift-alt-f": "editor::Format", // Format Document (Windows-style; Linux `ctrl-shift-i` is a Zed default already)
"ctrl-k ctrl-f": "editor::FormatSelections", // Format Selection
"shift-alt-i": "editor::SplitSelectionIntoLines", // Insert cursor at end of each line selected
"alt-z": "editor::ToggleSoftWrap", // Toggle Word Wrap
"ctrl-shift-space": "editor::ShowSignatureHelp", // Trigger Parameter Hints
"ctrl-shift-a": "editor::ToggleBlockComments", // Toggle Block Comment
"ctrl-k f12": "editor::GoToDefinitionSplit", // Open Definition to the Side
},
},
{
"context": "Editor && mode == full",
"use_key_equivalents": true,
"bindings": {
// In VS Code `ctrl-k z` is Zen Mode; the word wrap toggle moves to `alt-z`.
"ctrl-k z": "workspace::ToggleCenteredLayout",
},
},
{
"context": "Workspace",
"use_key_equivalents": true,
"bindings": {
"f5": "debugger::Start", // Start Debugging
},
},
{
"context": "Workspace && debugger_running",
"use_key_equivalents": true,
"bindings": {
"f10": "debugger::StepOver",
},
},
]

View file

@ -0,0 +1,50 @@
[
// VS Code for macOS. See: https://code.visualstudio.com/docs/reference/default-keybindings
//
// Zed's default keymap is close to VS Code's, so this overlay only contains
// the bindings where the two diverge.
{
"context": "Editor",
"use_key_equivalents": true,
"bindings": {
"shift-alt-f": "editor::Format", // Format Document
"cmd-k cmd-f": "editor::FormatSelections", // Format Selection
"shift-alt-i": "editor::SplitSelectionIntoLines", // Insert cursor at end of each line selected
"alt-z": "editor::ToggleSoftWrap", // Toggle Word Wrap
"cmd-shift-space": "editor::ShowSignatureHelp", // Trigger Parameter Hints
"ctrl-shift-cmd-right": "editor::SelectLargerSyntaxNode", // Expand AST Selection
"ctrl-shift-cmd-left": "editor::SelectSmallerSyntaxNode", // Shrink AST Selection
"cmd-k cmd-c": ["editor::ToggleComments", { "advance_downwards": false }], // Add Line Comment (closest analog)
"cmd-k f12": "editor::GoToDefinitionSplit", // Open Definition to the Side
},
},
{
"context": "Editor && mode == full",
"use_key_equivalents": true,
"bindings": {
// In VS Code `cmd-k z` is Zen Mode; the word wrap toggle moves to `alt-z`.
"cmd-k z": "workspace::ToggleCenteredLayout",
},
},
{
"context": "BufferSearchBar || ProjectSearchBar",
"use_key_equivalents": true,
"bindings": {
"alt-cmd-r": "search::ToggleRegex", // Toggle Find Regex
},
},
{
"context": "Workspace",
"use_key_equivalents": true,
"bindings": {
"f5": "debugger::Start", // Start Debugging
},
},
{
"context": "Workspace && debugger_running",
"use_key_equivalents": true,
"bindings": {
"f10": "debugger::StepOver",
},
},
]

View file

@ -104,7 +104,7 @@ impl BaseKeymap {
BaseKeymap::TextMate => Some("keymaps/macos/textmate.json"),
BaseKeymap::Emacs => Some("keymaps/macos/emacs.json"),
BaseKeymap::Cursor => Some("keymaps/macos/cursor.json"),
BaseKeymap::VSCode => None,
BaseKeymap::VSCode => Some("keymaps/macos/vscode.json"),
BaseKeymap::Zed => None,
BaseKeymap::None => None,
}
@ -117,7 +117,7 @@ impl BaseKeymap {
BaseKeymap::Emacs => Some("keymaps/linux/emacs.json"),
BaseKeymap::Cursor => Some("keymaps/linux/cursor.json"),
BaseKeymap::TextMate => None,
BaseKeymap::VSCode => None,
BaseKeymap::VSCode => Some("keymaps/linux/vscode.json"),
BaseKeymap::Zed => None,
BaseKeymap::None => None,
}

View file

@ -5098,6 +5098,8 @@ mod tests {
use workspace::ActivatePreviousPane;
// From the JetBrains keymap
use workspace::ActivatePreviousItem;
// From the VSCode keymap
use debugger_ui::Start;
app_state
.fs
@ -5190,6 +5192,36 @@ mod tests {
],
line!(),
);
// Test the VSCode keymap overlay
app_state
.fs
.save(
paths::settings_file(),
&r#"{"base_keymap": "VSCode"}"#.into(),
Default::default(),
)
.await
.unwrap();
executor.run_until_parked();
window
.update(cx, |_, _, cx| {
workspace.update(cx, |workspace, cx| {
workspace.register_action(|_, _: &Start, _window, _cx| {});
cx.notify();
});
})
.unwrap();
executor.run_until_parked();
assert_key_bindings_for(
window.into(),
cx,
vec![("backspace", &ActionB), ("f5", &Start)],
line!(),
);
}
#[gpui::test]