1// documentation: https://zed.dev/docs/key-bindings
2//
3// To see the default key bindings run `zed: open default keymap`
4// from the command palette.
5[
6 {
7 "context": "!GitPanel",
8 "bindings": {
9 "ctrl-g": "menu::Cancel"
10 }
11 },
12 {
13 // Workaround to avoid falling back to default bindings.
14 // Unbind so Zed ignores these keys and lets emacs handle them.
15 // NOTE: must be declared before the `Editor` override.
16 "context": "Editor",
17 "bindings": {
18 "ctrl-g": null // currently activates `go_to_line::Toggle` when there is nothing to cancel
19 }
20 },
21 {
22 "context": "Editor",
23 "bindings": {
24 "ctrl-g": "editor::Cancel",
25 "alt-g g": "go_to_line::Toggle", // goto-line
26 "alt-g alt-g": "go_to_line::Toggle", // goto-line
27 "ctrl-space": "editor::SetMark", // set-mark
28 "ctrl-@": "editor::SetMark", // set-mark
29 "ctrl-x ctrl-x": "editor::SwapSelectionEnds", // exchange-point-and-mark
30 "ctrl-f": "editor::MoveRight", // forward-char
31 "ctrl-b": "editor::MoveLeft", // backward-char
32 "ctrl-n": "editor::MoveDown", // next-line
33 "ctrl-p": "editor::MoveUp", // previous-line
34 "home": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": false }], // move-beginning-of-line
35 "end": ["editor::MoveToEndOfLine", { "stop_at_soft_wraps": false }], // move-end-of-line
36 "ctrl-a": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": false }], // move-beginning-of-line
37 "ctrl-e": ["editor::MoveToEndOfLine", { "stop_at_soft_wraps": false }], // move-end-of-line
38 "shift-home": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": false }], // move-beginning-of-line
39 "shift-end": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": false }], // move-end-of-line
40 "alt-m": ["editor::MoveToBeginningOfLine", { "stop_at_soft_wraps": false, "stop_at_indent": true }], // back-to-indentation
41 "alt-left": "editor::MoveToPreviousWordStart", // left-word
42 "alt-right": "editor::MoveToNextWordEnd", // right-word
43 "alt-f": "editor::MoveToNextWordEnd", // forward-word
44 "alt-b": "editor::MoveToPreviousWordStart", // backward-word
45 "alt-u": "editor::ConvertToUpperCase", // upcase-word
46 "alt-l": "editor::ConvertToLowerCase", // downcase-word
47 "alt-c": "editor::ConvertToUpperCamelCase", // capitalize-word
48 "ctrl-t": "editor::Transpose", // transpose-chars
49 "alt-;": ["editor::ToggleComments", { "advance_downwards": false }],
50 "ctrl-x ctrl-;": "editor::ToggleComments",
51 "alt-.": "editor::GoToDefinition", // xref-find-definitions
52 "alt-?": "editor::FindAllReferences", // xref-find-references
53 "alt-,": "pane::GoBack", // xref-pop-marker-stack
54 "ctrl-x h": "editor::SelectAll", // mark-whole-buffer
55 "ctrl-d": "editor::Delete", // delete-char
56 "alt-d": ["editor::DeleteToNextWordEnd", { "ignore_newlines": false, "ignore_brackets": false }], // kill-word
57 "alt-backspace": "editor::DeleteToPreviousWordStart", // backward-kill-word
58 "alt-delete": "editor::DeleteToPreviousWordStart", // backward-kill-word
59 "ctrl-k": "editor::KillRingCut", // kill-line
60 "ctrl-w": "editor::Cut", // kill-region
61 "alt-w": "editor::Copy", // kill-ring-save
62 "ctrl-y": "editor::KillRingYank", // yank
63 "ctrl-_": "editor::Undo", // undo
64 "ctrl-/": "editor::Undo", // undo
65 "ctrl-x u": "editor::Undo", // undo
66 "alt-{": "editor::MoveToStartOfParagraph", // backward-paragraph
67 "alt-}": "editor::MoveToEndOfParagraph", // forward-paragraph
68 "ctrl-up": "editor::MoveToStartOfParagraph", // backward-paragraph
69 "ctrl-down": "editor::MoveToEndOfParagraph", // forward-paragraph
70 "ctrl-v": "editor::MovePageDown", // scroll-up
71 "alt-v": "editor::MovePageUp", // scroll-down
72 "ctrl-x [": "editor::MoveToBeginning", // beginning-of-buffer
73 "ctrl-x ]": "editor::MoveToEnd", // end-of-buffer
74 "alt-<": "editor::MoveToBeginning", // beginning-of-buffer
75 "alt->": "editor::MoveToEnd", // end-of-buffer
76 "ctrl-home": "editor::MoveToBeginning", // beginning-of-buffer
77 "ctrl-end": "editor::MoveToEnd", // end-of-buffer
78 "ctrl-l": "editor::ScrollCursorCenterTopBottom", // recenter-top-bottom
79 "ctrl-s": "buffer_search::Deploy", // isearch-forward
80 "ctrl-r": "buffer_search::Deploy", // isearch-backward
81 "alt-^": "editor::JoinLines", // join-line
82 "alt-q": "editor::Rewrap" // fill-paragraph
83 }
84 },
85 {
86 "context": "Editor && selection_mode", // region selection
87 "bindings": {
88 "right": "editor::SelectRight",
89 "left": "editor::SelectLeft",
90 "down": "editor::SelectDown",
91 "up": "editor::SelectUp",
92 "alt-left": "editor::SelectToPreviousWordStart",
93 "alt-right": "editor::SelectToNextWordEnd",
94 "pagedown": "editor::SelectPageDown",
95 "ctrl-v": "editor::SelectPageDown",
96 "pageup": "editor::SelectPageUp",
97 "alt-v": "editor::SelectPageUp",
98 "ctrl-f": "editor::SelectRight",
99 "ctrl-b": "editor::SelectLeft",
100 "ctrl-n": "editor::SelectDown",
101 "ctrl-p": "editor::SelectUp",
102 "home": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": false }],
103 "end": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": false }],
104 "ctrl-a": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": false }],
105 "ctrl-e": ["editor::SelectToEndOfLine", { "stop_at_soft_wraps": false }],
106 "alt-m": ["editor::SelectToBeginningOfLine", { "stop_at_soft_wraps": false, "stop_at_indent": true }],
107 "alt-f": "editor::SelectToNextWordEnd",
108 "alt-b": "editor::SelectToPreviousWordStart",
109 "alt-{": "editor::SelectToStartOfParagraph",
110 "alt-}": "editor::SelectToEndOfParagraph",
111 "ctrl-up": "editor::SelectToStartOfParagraph",
112 "ctrl-down": "editor::SelectToEndOfParagraph",
113 "ctrl-x [": "editor::SelectToBeginning",
114 "ctrl-x ]": "editor::SelectToEnd",
115 "alt-<": "editor::SelectToBeginning",
116 "alt->": "editor::SelectToEnd",
117 "ctrl-home": "editor::SelectToBeginning",
118 "ctrl-end": "editor::SelectToEnd",
119 "ctrl-g": "editor::Cancel"
120 }
121 },
122 {
123 "context": "Editor && (showing_code_actions || showing_completions)",
124 "bindings": {
125 "ctrl-p": "editor::ContextMenuPrevious",
126 "ctrl-n": "editor::ContextMenuNext"
127 }
128 },
129 {
130 "context": "Editor && showing_signature_help && !showing_completions",
131 "bindings": {
132 "ctrl-p": "editor::SignatureHelpPrevious",
133 "ctrl-n": "editor::SignatureHelpNext"
134 }
135 },
136 // Example setting for using emacs-style tab
137 // (i.e. indent the current line / selection or perform symbol completion depending on context)
138 // {
139 // "context": "Editor && !showing_code_actions && !showing_completions",
140 // "bindings": {
141 // "tab": "editor::AutoIndent" // indent-for-tab-command
142 // }
143 // },
144 {
145 "context": "Workspace",
146 "bindings": {
147 "alt-x": "command_palette::Toggle", // execute-extended-command
148 "ctrl-x b": "tab_switcher::Toggle", // switch-to-buffer
149 "ctrl-x ctrl-b": "tab_switcher::Toggle", // list-buffers
150 // "ctrl-x ctrl-c": "workspace::CloseWindow" // in case you only want to exit the current Zed instance
151 "ctrl-x ctrl-c": "zed::Quit", // save-buffers-kill-terminal
152 "ctrl-x 5 0": "workspace::CloseWindow", // delete-frame
153 "ctrl-x 5 2": "workspace::NewWindow", // make-frame-command
154 "ctrl-x o": "workspace::ActivateNextPane", // other-window
155 "ctrl-x k": "pane::CloseActiveItem", // kill-buffer
156 "ctrl-x 0": "pane::CloseActiveItem", // delete-window
157 // "ctrl-x 1": "pane::JoinAll", // in case you prefer to delete the splits but keep the buffers open
158 "ctrl-x 1": "pane::CloseOtherItems", // delete-other-windows
159 "ctrl-x 2": "pane::SplitDown", // split-window-below
160 "ctrl-x 3": "pane::SplitRight", // split-window-right
161 "ctrl-x ctrl-f": "file_finder::Toggle", // find-file
162 "ctrl-x ctrl-s": "workspace::Save", // save-buffer
163 "ctrl-x ctrl-w": "workspace::SaveAs", // write-file
164 "ctrl-x s": "workspace::SaveAll" // save-some-buffers
165 }
166 },
167 {
168 // Workaround to enable using native emacs from the Zed terminal.
169 // Unbind so Zed ignores these keys and lets emacs handle them.
170 // NOTE:
171 // "terminal::SendKeystroke" only works for a single key stroke (e.g. ctrl-x),
172 // so override with null for compound sequences (e.g. ctrl-x ctrl-c).
173 "context": "Terminal",
174 "bindings": {
175 // If you want to perfect your emacs-in-zed setup, also consider the following.
176 // You may need to enable "option_as_meta" from the Zed settings for "alt-x" to work.
177 // "alt-x": ["terminal::SendKeystroke", "alt-x"],
178 // "ctrl-x": ["terminal::SendKeystroke", "ctrl-x"],
179 // "ctrl-n": ["terminal::SendKeystroke", "ctrl-n"],
180 // ...
181 "ctrl-x ctrl-c": null, // save-buffers-kill-terminal
182 "ctrl-x ctrl-f": null, // find-file
183 "ctrl-x ctrl-s": null, // save-buffer
184 "ctrl-x ctrl-w": null, // write-file
185 "ctrl-x s": null // save-some-buffers
186 }
187 },
188 {
189 "context": "BufferSearchBar > Editor",
190 "bindings": {
191 "ctrl-s": "search::SelectNextMatch",
192 "ctrl-r": "search::SelectPreviousMatch",
193 "ctrl-g": "buffer_search::Dismiss"
194 }
195 },
196 {
197 "context": "Pane",
198 "bindings": {
199 "ctrl-alt-left": "pane::GoBack",
200 "ctrl-alt-right": "pane::GoForward"
201 }
202 }
203]