]> git.lizzy.rs Git - micro.git/blob - runtime/help/keybindings.md
463632ab3603d4ec5558b1b9a0c0d11726542ad8
[micro.git] / runtime / help / keybindings.md
1 # Keybindings
2
3 Micro has a plethora of hotkeys that make it easy and powerful to use and all
4 hotkeys are fully customizable to your liking.
5
6 Custom keybindings are stored internally in micro if changed with the `> bind`
7 command or you can also be added in the file `~/.config/micro/bindings.json` as
8 discussed below.  For a list of the default keybindings in the json format used
9 by micro, please see the end of this file. For a more user-friendly list with
10 explanations of what the default hotkeys are and what they do, please see
11 `>help defaultkeys`
12
13 If `~/.config/micro/bindings.json` does not exist, you can simply create it.
14 Micro will know what to do with it.
15
16 You can use the alt keys + arrows to move word by word. Ctrl left and right move
17 the cursor to the start and end of the line, and ctrl up and down move the
18 cursor the start and end of the buffer.
19
20 You can hold shift with all of these movement actions to select while moving.
21
22
23 ## Rebinding keys
24
25 The bindings may be rebound using the `~/.config/micro/bindings.json` file. Each
26 key is bound to an action.
27
28 For example, to bind `Ctrl-y` to undo and `Ctrl-z` to redo, you could put the
29 following in the `bindings.json` file.
30
31 ```json
32 {
33         "CtrlY": "Undo",
34         "CtrlZ": "Redo"
35 }
36 ```
37
38 In addition to editing your `~/.config/micro/bindings.json`, you can run
39 `>bind <keycombo> <action>` For a list of bindable actions, see below.
40
41 You can also chain commands when rebinding. For example, if you want Alt-s to
42 save and quit you can bind it like so:
43
44 ```json
45 {
46     "Alt-s": "Save,Quit"
47 }
48 ```
49
50
51 ## Binding raw escape sequences
52
53 Only read this section if you are interested in binding keys that aren't on the 
54 list of supported keys for binding.
55
56 One of the drawbacks of using a terminal-based editor is that the editor must
57 get all of its information about key events through the terminal. The terminal
58 sends these events in the form of escape sequences often (but not always)
59 starting with `0x1b`. 
60
61 For example, if micro reads `\x1b[1;5D`, on most terminals this will mean the
62 user pressed CtrlLeft.
63
64 For many key chords though, the terminal won't send any escape code or will send
65 an escape code already in use. For example for `CtrlBackspace`, my terminal
66 sends `\u007f` (note this doesn't start with `0x1b`), which it also sends for
67 `Backspace` meaning micro can't bind `CtrlBackspace`.
68
69 However, some terminals do allow you to bind keys to send specific escape
70 sequences you define. Then from micro you can directly bind those escape
71 sequences to actions. For example, to bind `CtrlBackspace` you can instruct your
72 terminal to send `\x1bctrlback` and then bind it in `bindings.json`:
73
74 ```json
75 {
76     "\u001bctrlback": "DeleteWordLeft"
77 }
78 ```
79
80 Here are some instructions for sending raw escapes in different terminals
81
82 ### iTerm2
83
84 In iTerm2, you can do this in  `Preferences->Profiles->Keys` then click the `+`,
85 input your keybinding, and for the `Action` select `Send Escape Sequence`. For
86 the above example your would type `ctrlback` into the box (the `\x1b`) is
87 automatically sent by iTerm2.
88
89 ### Linux using loadkeys
90
91 You can do this in linux using the loadkeys program.
92
93 Coming soon!
94
95
96 ## Unbinding keys
97
98 It is also possible to disable any of the default key bindings by use of the 
99 `UnbindKey` action in the user's `bindings.json` file.
100
101
102 ## Bindable actions and bindable keys
103
104 The list of default keybindings contains most of the possible actions and keys
105 which you can use, but not all of them. Here is a full list of both.
106
107 Full list of possible actions:
108
109 ```
110 CursorUp
111 CursorDown
112 CursorPageUp
113 CursorPageDown
114 CursorLeft
115 CursorRight
116 CursorStart
117 CursorEnd
118 SelectToStart
119 SelectToEnd
120 SelectUp
121 SelectDown
122 SelectLeft
123 SelectRight
124 WordRight
125 WordLeft
126 SelectWordRight
127 SelectWordLeft
128 MoveLinesUp
129 MoveLinesDown
130 DeleteWordRight
131 DeleteWordLeft
132 SelectToStartOfLine
133 SelectToEndOfLine
134 InsertNewline
135 InsertSpace
136 Backspace
137 Delete
138 Center
139 InsertTab
140 Save
141 SaveAll
142 SaveAs
143 Find
144 FindNext
145 FindPrevious
146 Undo
147 Redo
148 Copy
149 Cut
150 CutLine
151 DuplicateLine
152 DeleteLine
153 IndentSelection
154 OutdentSelection
155 Paste
156 SelectAll
157 OpenFile
158 Start
159 End
160 PageUp
161 PageDown
162 HalfPageUp
163 HalfPageDown
164 StartOfLine
165 EndOfLine
166 ParagraphPrevious
167 ParagraphNext
168 ToggleHelp
169 ToggleRuler
170 JumpLine
171 ClearStatus
172 ShellMode
173 CommandMode
174 Quit
175 QuitAll
176 AddTab
177 PreviousTab
178 NextTab
179 NextSplit
180 Unsplit
181 VSplit
182 HSplit
183 PreviousSplit
184 ToggleMacro
185 PlayMacro
186 Suspend (Linux only)
187 ScrollUp
188 ScrollDown
189 SpawnMultiCursor
190 RemoveMultiCursor
191 RemoveAllMultiCursors
192 SkipMultiCursor
193 UnbindKey
194 ```
195
196 You can also bind some mouse actions (these must be bound to mouse buttons)
197
198 ```
199 MousePress
200 MouseMultiCursor
201 ```
202
203 Here is the list of all possible keys you can bind:
204
205 ```
206 Up
207 Down
208 Right
209 Left
210 UpLeft
211 UpRight
212 DownLeft
213 DownRight
214 Center
215 PageUp
216 PageDown
217 Home
218 End
219 Insert
220 Delete
221 Help
222 Exit
223 Clear
224 Cancel
225 Print
226 Pause
227 Backtab
228 F1
229 F2
230 F3
231 F4
232 F5
233 F6
234 F7
235 F8
236 F9
237 F10
238 F11
239 F12
240 F13
241 F14
242 F15
243 F16
244 F17
245 F18
246 F19
247 F20
248 F21
249 F22
250 F23
251 F24
252 F25
253 F26
254 F27
255 F28
256 F29
257 F30
258 F31
259 F32
260 F33
261 F34
262 F35
263 F36
264 F37
265 F38
266 F39
267 F40
268 F41
269 F42
270 F43
271 F44
272 F45
273 F46
274 F47
275 F48
276 F49
277 F50
278 F51
279 F52
280 F53
281 F54
282 F55
283 F56
284 F57
285 F58
286 F59
287 F60
288 F61
289 F62
290 F63
291 F64
292 CtrlSpace
293 CtrlA
294 CtrlB
295 CtrlC
296 CtrlD
297 CtrlE
298 CtrlF
299 CtrlG
300 CtrlH
301 CtrlI
302 CtrlJ
303 CtrlK
304 CtrlL
305 CtrlM
306 CtrlN
307 CtrlO
308 CtrlP
309 CtrlQ
310 CtrlR
311 CtrlS
312 CtrlT
313 CtrlU
314 CtrlV
315 CtrlW
316 CtrlX
317 CtrlY
318 CtrlZ
319 CtrlLeftSq
320 CtrlBackslash
321 CtrlRightSq
322 CtrlCarat
323 CtrlUnderscore
324 Backspace
325 Tab
326 Esc
327 Escape
328 Enter
329 ```
330
331 You can also bind some mouse buttons (they may be bound to normal actions or
332 mouse actions)
333
334 ```
335 MouseLeft
336 MouseMiddle
337 MouseRight
338 MouseWheelUp
339 MouseWheelDown
340 MouseWheelLeft
341 MouseWheelRight
342 ```
343
344 # Default keybinding configuration.
345
346 ```json
347 {
348     "Up":             "CursorUp",
349     "Down":           "CursorDown",
350     "Right":          "CursorRight",
351     "Left":           "CursorLeft",
352     "ShiftUp":        "SelectUp",
353     "ShiftDown":      "SelectDown",
354     "ShiftLeft":      "SelectLeft",
355     "ShiftRight":     "SelectRight",
356     "AltLeft":        "WordLeft",
357     "AltRight":       "WordRight",
358     "AltUp":          "MoveLinesUp",
359     "AltDown":        "MoveLinesDown",
360     "AltShiftRight":  "SelectWordRight",
361     "AltShiftLeft":   "SelectWordLeft",
362     "CtrlLeft":       "StartOfLine",
363     "CtrlRight":      "EndOfLine",
364     "CtrlShiftLeft":  "SelectToStartOfLine",
365     "ShiftHome":      "SelectToStartOfLine",
366     "CtrlShiftRight": "SelectToEndOfLine",
367     "ShiftEnd":       "SelectToEndOfLine",
368     "CtrlUp":         "CursorStart",
369     "CtrlDown":       "CursorEnd",
370     "CtrlShiftUp":    "SelectToStart",
371     "CtrlShiftDown":  "SelectToEnd",
372     "Alt-{":          "ParagraphPrevious",
373     "Alt-}":          "ParagraphNext",
374     "Enter":          "InsertNewline",
375     "CtrlH":          "Backspace",
376     "Backspace":      "Backspace",
377     "Alt-CtrlH":      "DeleteWordLeft",
378     "Alt-Backspace":  "DeleteWordLeft",
379     "Tab":            "IndentSelection,InsertTab",
380     "Backtab":        "OutdentSelection,OutdentLine",
381     "CtrlO":          "OpenFile",
382     "CtrlS":          "Save",
383     "CtrlF":          "Find",
384     "CtrlN":          "FindNext",
385     "CtrlP":          "FindPrevious",
386     "CtrlZ":          "Undo",
387     "CtrlY":          "Redo",
388     "CtrlC":          "Copy",
389     "CtrlX":          "Cut",
390     "CtrlK":          "CutLine",
391     "CtrlD":          "DuplicateLine",
392     "CtrlV":          "Paste",
393     "CtrlA":          "SelectAll",
394     "CtrlT":          "AddTab",
395     "Alt,":           "PreviousTab",
396     "Alt.":           "NextTab",
397     "Home":           "StartOfLine",
398     "End":            "EndOfLine",
399     "CtrlHome":       "CursorStart",
400     "CtrlEnd":        "CursorEnd",
401     "PageUp":         "CursorPageUp",
402     "PageDown":       "CursorPageDown",
403     "CtrlG":          "ToggleHelp",
404     "CtrlR":          "ToggleRuler",
405     "CtrlL":          "JumpLine",
406     "Delete":         "Delete",
407     "CtrlB":          "ShellMode",
408     "CtrlQ":          "Quit",
409     "CtrlE":          "CommandMode",
410     "CtrlW":          "NextSplit",
411     "CtrlU":          "ToggleMacro",
412     "CtrlJ":          "PlayMacro",
413
414     // Emacs-style keybindings
415     "Alt-f": "WordRight",
416     "Alt-b": "WordLeft",
417     "Alt-a": "StartOfLine",
418     "Alt-e": "EndOfLine",
419
420     // Integration with file managers
421     "F1":  "ToggleHelp",
422     "F2":  "Save",
423     "F3":  "Find",
424     "F4":  "Quit",
425     "F7":  "Find",
426     "F10": "Quit",
427     "Esc": "Escape",
428
429     // Mouse bindings
430     "MouseWheelUp":   "ScrollUp",
431     "MouseWheelDown": "ScrollDown",
432     "MouseLeft":      "MousePress",
433     "MouseMiddle":    "PastePrimary",
434     "Ctrl-MouseLeft": "MouseMultiCursor",
435
436     // Multiple cursors bindings
437     "Alt-n": "SpawnMultiCursor",
438     "Alt-p": "RemoveMultiCursor",
439     "Alt-c": "RemoveAllMultiCursors",
440     "Alt-x": "SkipMultiCursor",
441 }
442 ```
443
444 ## Final notes
445
446 Note: On some old terminal emulators and on Windows machines, `CtrlH` should be
447 used for backspace.
448
449 Additionally, alt keys can be bound by using `Alt-key`. For example `Alt-a` or
450 `Alt-Up`. Micro supports an optional `-` between modifiers like `Alt` and 
451 `Ctrl` so `Alt-a` could be rewritten as `Alta` (case matters for alt bindings).
452 This is why in the default keybindings you can see `AltShiftLeft` instead of
453 `Alt-ShiftLeft` (they are equivalent).