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