]> git.lizzy.rs Git - micro.git/blobdiff - runtime/help/keybindings.md
Merge
[micro.git] / runtime / help / keybindings.md
index 9fbe3cb314a536607b93a894b9493b4064057835..d2b1883c5614ddf986693bb9e735807fe8cd33bf 100644 (file)
@@ -4,7 +4,7 @@ Micro has a plethora of hotkeys that make it easy and powerful to use and all
 hotkeys are fully customizable to your liking.
 
 Custom keybindings are stored internally in micro if changed with the `> bind`
-command or you can also be added in the file `~/.config/micro/bindings.json` as
+command or can also be added in the file `~/.config/micro/bindings.json` as
 discussed below. For a list of the default keybindings in the json format used
 by micro, please see the end of this file. For a more user-friendly list with
 explanations of what the default hotkeys are and what they do, please see
@@ -14,8 +14,8 @@ at the end of this document).
 If `~/.config/micro/bindings.json` does not exist, you can simply create it.
 Micro will know what to do with it.
 
-You can use the alt keys + arrows to move word by word. Ctrl left and right
-move the cursor to the start and end of the line, and ctrl up and down move the
+You can use Ctrl + arrows to move word by word (Alt + arrows for Mac). Alt + left and right
+move the cursor to the start and end of the line (Ctrl + left/right for Mac), and Ctrl + up and down move the
 cursor the start and end of the buffer.
 
 You can hold shift with all of these movement actions to select while moving.
@@ -30,11 +30,17 @@ following in the `bindings.json` file.
 
 ```json
 {
-       "CtrlY": "Undo",
-       "CtrlZ": "Redo"
+       "Ctrl-y": "Undo",
+       "Ctrl-z": "Redo"
 }
 ```
 
+**Note:** The syntax `<Modifier><key>` is equivalent to `<Modifier>-<key>`. In
+addition, Ctrl-Shift bindings are not supported by terminals, and are the same
+as simply Ctrl bindings. This means that `CtrlG`, `Ctrl-G`, and `Ctrl-g` all
+mean the same thing. However, for Alt this is not the case: `AltG` and `Alt-G`
+mean `Alt-Shift-g`, while `Alt-g` does not require the Shift modifier.
+
 In addition to editing your `~/.config/micro/bindings.json`, you can run
 `>bind <keycombo> <action>` For a list of bindable actions, see below.
 
@@ -64,7 +70,7 @@ will execute `InsertTab`.
 
 ## Binding commands
 
-You can also bind a key to execute a command in command mode (see 
+You can also bind a key to execute a command in command mode (see
 `help commands`). Simply prepend the binding with `command:`. For example:
 
 ```json
@@ -73,33 +79,39 @@ You can also bind a key to execute a command in command mode (see
 }
 ```
 
+**Note for macOS**: By default, macOS terminals do not forward alt events and
+instead insert unicode characters. To fix this, do the following:
+
+* iTerm2: select `Esc+` for `Left Option Key` in `Preferences->Profiles->Keys`.
+* Terminal.app: Enable `Use Option key as Meta key` in `Preferences->Profiles->Keyboard`.
+
 Now when you press `Alt-p` the `pwd` command will be executed which will show
 your working directory in the infobar.
 
-You can also bind an "editable" command with `command-edit:`. This means that 
+You can also bind an "editable" command with `command-edit:`. This means that
 micro won't immediately execute the command when you press the binding, but
-instead just place the string in the infobar in command mode. For example, 
-you could rebind `CtrlG` to `> help`:
+instead just place the string in the infobar in command mode. For example,
+you could rebind `Ctrl-g` to `> help`:
 
 ```json
 {
-    "CtrlG": "command-edit:help "
+    "Ctrl-g": "command-edit:help "
 }
 ```
 
-Now when you press `CtrlG`, `help` will appear in the command bar and your
+Now when you press `Ctrl-g`, `help` will appear in the command bar and your
 cursor will be placed after it (note the space in the json that controls the
 cursor placement).
 
 ## Binding raw escape sequences
 
-Only read this section if you are interested in binding keys that aren't on the 
+Only read this section if you are interested in binding keys that aren't on the
 list of supported keys for binding.
 
 One of the drawbacks of using a terminal-based editor is that the editor must
 get all of its information about key events through the terminal. The terminal
 sends these events in the form of escape sequences often (but not always)
-starting with `0x1b`. 
+starting with `0x1b`.
 
 For example, if micro reads `\x1b[1;5D`, on most terminals this will mean the
 user pressed CtrlLeft.
@@ -137,7 +149,7 @@ Coming soon!
 
 ## Unbinding keys
 
-It is also possible to disable any of the default key bindings by use of the 
+It is also possible to disable any of the default key bindings by use of the
 `None` action in the user's `bindings.json` file.
 
 ## Bindable actions and bindable keys
@@ -162,6 +174,8 @@ SelectUp
 SelectDown
 SelectLeft
 SelectRight
+SelectToStartOfText
+SelectToStartOfTextToggle
 WordRight
 WordLeft
 SelectWordRight
@@ -183,11 +197,13 @@ Save
 SaveAll
 SaveAs
 Find
+FindLiteral
 FindNext
 FindPrevious
 Undo
 Redo
 Copy
+CopyLine
 Cut
 CutLine
 DuplicateLine
@@ -209,6 +225,8 @@ HalfPageUp
 HalfPageDown
 StartOfLine
 EndOfLine
+StartOfText
+StartOfTextToggle
 ParagraphPrevious
 ParagraphNext
 ToggleHelp
@@ -245,6 +263,9 @@ JumpToMatchingBrace
 Autocomplete
 ```
 
+The `StartOfTextToggle` and `SelectToStartOfTextToggle` actions toggle between
+jumping to the start of the text (first) and start of the line.
+
 You can also bind some mouse actions (these must be bound to mouse buttons)
 
 ```
@@ -342,32 +363,32 @@ F62
 F63
 F64
 CtrlSpace
-CtrlA
-CtrlB
-CtrlC
-CtrlD
-CtrlE
-CtrlF
-CtrlG
-CtrlH
-CtrlI
-CtrlJ
-CtrlK
-CtrlL
-CtrlM
-CtrlN
-CtrlO
-CtrlP
-CtrlQ
-CtrlR
-CtrlS
-CtrlT
-CtrlU
-CtrlV
-CtrlW
-CtrlX
-CtrlY
-CtrlZ
+Ctrl-a
+Ctrl-b
+Ctrl-c
+Ctrl-d
+Ctrl-e
+Ctrl-f
+Ctrl-g
+Ctrl-h
+Ctrl-i
+Ctrl-j
+Ctrl-k
+Ctrl-l
+Ctrl-m
+Ctrl-n
+Ctrl-o
+Ctrl-p
+Ctrl-q
+Ctrl-r
+Ctrl-s
+Ctrl-t
+Ctrl-u
+Ctrl-v
+Ctrl-w
+Ctrl-x
+Ctrl-y
+Ctrl-z
 CtrlLeftSq
 CtrlBackslash
 CtrlRightSq
@@ -394,6 +415,11 @@ MouseWheelLeft
 MouseWheelRight
 ```
 
+## Key sequences
+
+Key sequences can be bound by specifying valid keys one after another in brackets, such
+as `<Ctrl-x><Ctrl-c>`.
+
 # Default keybinding configuration.
 
 A select few keybindings are different on MacOS compared to other
@@ -410,21 +436,21 @@ conventions for text editing defaults.
     "ShiftDown":      "SelectDown",
     "ShiftLeft":      "SelectLeft",
     "ShiftRight":     "SelectRight",
-    "AltLeft":        "WordLeft",
-    "AltRight":       "WordRight",
+    "AltLeft":        "WordLeft", (Mac)
+    "AltRight":       "WordRight", (Mac)
     "AltUp":          "MoveLinesUp",
     "AltDown":        "MoveLinesDown",
     "CtrlShiftRight": "SelectWordRight",
     "CtrlShiftLeft":  "SelectWordLeft",
-    "AltLeft":        "StartOfLine",
+    "AltLeft":        "StartOfTextToggle",
     "AltRight":       "EndOfLine",
     "AltShiftRight":  "SelectWordRight", (Mac)
     "AltShiftLeft":   "SelectWordLeft", (Mac)
     "CtrlLeft":       "StartOfText", (Mac)
     "CtrlRight":      "EndOfLine", (Mac)
-    "AltShiftLeft":   "SelectToStartOfLine",
-    "CtrlShiftLeft":  "SelectToStartOfText", (Mac)
-    "ShiftHome":      "SelectToStartOfLine",
+    "AltShiftLeft":   "SelectToStartOfTextToggle",
+    "CtrlShiftLeft":  "SelectToStartOfTextToggle", (Mac)
+    "ShiftHome":      "SelectToStartOfTextToggle",
     "AltShiftRight":  "SelectToEndOfLine",
     "CtrlShiftRight": "SelectToEndOfLine", (Mac)
     "ShiftEnd":       "SelectToEndOfLine",
@@ -435,29 +461,29 @@ conventions for text editing defaults.
     "Alt-{":          "ParagraphPrevious",
     "Alt-}":          "ParagraphNext",
     "Enter":          "InsertNewline",
-    "CtrlH":          "Backspace",
+    "Ctrl-h":          "Backspace",
     "Backspace":      "Backspace",
     "Alt-CtrlH":      "DeleteWordLeft",
     "Alt-Backspace":  "DeleteWordLeft",
     "Tab":            "Autocomplete|IndentSelection|InsertTab",
     "Backtab":        "OutdentSelection|OutdentLine",
-    "CtrlO":          "OpenFile",
-    "CtrlS":          "Save",
-    "CtrlF":          "Find",
-    "CtrlN":          "FindNext",
-    "CtrlP":          "FindPrevious",
-    "CtrlZ":          "Undo",
-    "CtrlY":          "Redo",
-    "CtrlC":          "Copy",
-    "CtrlX":          "Cut",
-    "CtrlK":          "CutLine",
-    "CtrlD":          "DuplicateLine",
-    "CtrlV":          "Paste",
-    "CtrlA":          "SelectAll",
-    "CtrlT":          "AddTab",
-    "Alt,":           "PreviousTab",
-    "Alt.":           "NextTab",
-    "Home":           "StartOfLine",
+    "Ctrl-o":          "OpenFile",
+    "Ctrl-s":          "Save",
+    "Ctrl-f":          "Find",
+    "Ctrl-n":          "FindNext",
+    "Ctrl-p":          "FindPrevious",
+    "Ctrl-z":          "Undo",
+    "Ctrl-y":          "Redo",
+    "Ctrl-c":          "CopyLine|Copy",
+    "Ctrl-x":          "Cut",
+    "Ctrl-k":          "CutLine",
+    "Ctrl-d":          "DuplicateLine",
+    "Ctrl-v":          "Paste",
+    "Ctrl-a":          "SelectAll",
+    "Ctrl-t":          "AddTab",
+    "Alt-,":           "PreviousTab",
+    "Alt-.":           "NextTab",
+    "Home":           "StartOfText",
     "End":            "EndOfLine",
     "CtrlHome":       "CursorStart",
     "CtrlEnd":        "CursorEnd",
@@ -465,17 +491,17 @@ conventions for text editing defaults.
     "PageDown":       "CursorPageDown",
     "CtrlPageUp":     "PreviousTab",
     "CtrlPageDown":   "NextTab",
-    "CtrlG":          "ToggleHelp",
+    "Ctrl-g":          "ToggleHelp",
     "Alt-g":          "ToggleKeyMenu",
-    "CtrlR":          "ToggleRuler",
-    "CtrlL":          "command-edit:goto ",
+    "Ctrl-r":          "ToggleRuler",
+    "Ctrl-l":          "command-edit:goto ",
     "Delete":         "Delete",
-    "CtrlB":          "ShellMode",
-    "CtrlQ":          "Quit",
-    "CtrlE":          "CommandMode",
-    "CtrlW":          "NextSplit",
-    "CtrlU":          "ToggleMacro",
-    "CtrlJ":          "PlayMacro",
+    "Ctrl-b":          "ShellMode",
+    "Ctrl-q":          "Quit",
+    "Ctrl-e":          "CommandMode",
+    "Ctrl-w":          "NextSplit",
+    "Ctrl-u":          "ToggleMacro",
+    "Ctrl-j":          "PlayMacro",
     "Insert":         "ToggleOverwriteMode",
 
     // Emacs-style keybindings
@@ -509,13 +535,114 @@ conventions for text editing defaults.
 }
 ```
 
+## Pane type bindings
+
+Keybindings can be specified for different pane types as well. For example, to
+make a binding that only affects the command bar, use the `command` subgroup:
+
+```
+{
+    "command": {
+        "Ctrl-w": "WordLeft"
+    }
+}
+```
+
+The possible pane types are `buffer` (normal buffer), `command` (command bar),
+and `terminal` (terminal pane). The defaults for the command and terminal panes
+are given below:
+
+```
+{
+    "terminal": {
+        "<Ctrl-q><Ctrl-q>": "Exit",
+        "<Ctrl-e><Ctrl-e>": "CommandMode",
+        "<Ctrl-w><Ctrl-w>": "NextSplit"
+    },
+
+    "command": {
+        "Up":             "HistoryUp",
+        "Down":           "HistoryDown",
+        "Right":          "CursorRight",
+        "Left":           "CursorLeft",
+        "ShiftUp":        "SelectUp",
+        "ShiftDown":      "SelectDown",
+        "ShiftLeft":      "SelectLeft",
+        "ShiftRight":     "SelectRight",
+        "AltLeft":        "StartOfTextToggle",
+        "AltRight":       "EndOfLine",
+        "AltUp":          "CursorStart",
+        "AltDown":        "CursorEnd",
+        "AltShiftRight":  "SelectWordRight",
+        "AltShiftLeft":   "SelectWordLeft",
+        "CtrlLeft":       "WordLeft",
+        "CtrlRight":      "WordRight",
+        "CtrlShiftLeft":  "SelectToStartOfTextToggle",
+        "ShiftHome":      "SelectToStartOfTextToggle",
+        "CtrlShiftRight": "SelectToEndOfLine",
+        "ShiftEnd":       "SelectToEndOfLine",
+        "CtrlUp":         "CursorStart",
+        "CtrlDown":       "CursorEnd",
+        "CtrlShiftUp":    "SelectToStart",
+        "CtrlShiftDown":  "SelectToEnd",
+        "Enter":          "ExecuteCommand",
+        "CtrlH":          "Backspace",
+        "Backspace":      "Backspace",
+        "OldBackspace":   "Backspace",
+        "Alt-CtrlH":      "DeleteWordLeft",
+        "Alt-Backspace":  "DeleteWordLeft",
+        "Tab":            "CommandComplete",
+        "Backtab":        "CycleAutocompleteBack",
+        "Ctrl-z":         "Undo",
+        "Ctrl-y":         "Redo",
+        "Ctrl-c":         "CopyLine|Copy",
+        "Ctrl-x":         "Cut",
+        "Ctrl-k":         "CutLine",
+        "Ctrl-v":         "Paste",
+        "Home":           "StartOfTextToggle",
+        "End":            "EndOfLine",
+        "CtrlHome":       "CursorStart",
+        "CtrlEnd":        "CursorEnd",
+        "Delete":         "Delete",
+        "Ctrl-q":         "AbortCommand",
+        "Ctrl-e":         "EndOfLine",
+        "Ctrl-a":         "StartOfLine",
+        "Ctrl-w":         "DeleteWordLeft",
+        "Insert":         "ToggleOverwriteMode",
+        "Ctrl-b":         "WordLeft",
+        "Ctrl-f":         "WordRight",
+        "Ctrl-d":         "DeleteWordLeft",
+        "Ctrl-m":         "ExecuteCommand",
+        "Ctrl-n":         "HistoryDown",
+        "Ctrl-p":         "HistoryUp",
+        "Ctrl-u":         "SelectToStart",
+
+        // Emacs-style keybindings
+        "Alt-f": "WordRight",
+        "Alt-b": "WordLeft",
+        "Alt-a": "StartOfText",
+        "Alt-e": "EndOfLine",
+
+        // Integration with file managers
+        "F10": "AbortCommand",
+        "Esc": "AbortCommand",
+
+        // Mouse bindings
+        "MouseWheelUp":   "HistoryUp",
+        "MouseWheelDown": "HistoryDown",
+        "MouseLeft":      "MousePress",
+        "MouseMiddle":    "PastePrimary"
+    }
+}
+```
+
 ## Final notes
 
-Note: On some old terminal emulators and on Windows machines, `CtrlH` should be
+Note: On some old terminal emulators and on Windows machines, `Ctrl-h` should be
 used for backspace.
 
 Additionally, alt keys can be bound by using `Alt-key`. For example `Alt-a` or
-`Alt-Up`. Micro supports an optional `-` between modifiers like `Alt` and 
+`Alt-Up`. Micro supports an optional `-` between modifiers like `Alt` and
 `Ctrl` so `Alt-a` could be rewritten as `Alta` (case matters for alt bindings).
 This is why in the default keybindings you can see `AltShiftLeft` instead of
 `Alt-ShiftLeft` (they are equivalent).