Last active
May 16, 2023 18:18
-
-
Save simonrad/6847104 to your computer and use it in GitHub Desktop.
My iTerm2 custom key bindings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| iTerm2 Key Bindings | |
| =================== | |
| Fast way | |
| -------- | |
| 1. Run this command: | |
| echo '{"Touch Bar Items":[],"Key Mappings":{"0xf700-0x260000":{"Action":10,"Text":"[1;6A"},"0x37-0x40000":{"Action":11,"Text":"0x1f"},"0x32-0x40000":{"Action":11,"Text":"0x00"},"0xf709-0x20000":{"Action":10,"Text":"[17;2~"},"0xf70c-0x20000":{"Action":10,"Text":"[20;2~"},"0xf729-0x20000":{"Action":10,"Text":"[1;2H"},"0xf72b-0x40000":{"Action":10,"Text":"[1;5F"},"0xf705-0x20000":{"Action":10,"Text":"[1;2Q"},"0xf703-0x260000":{"Action":10,"Text":"[1;6C"},"0xf700-0x220000":{"Action":10,"Text":"[1;2A"},"0xf701-0x280000":{"Action":11,"Text":"0x1b 0x1b 0x5b 0x42"},"0x6c-0x100000":{"Text":"[C","Action":10},"0x38-0x40000":{"Action":11,"Text":"0x7f"},"0x33-0x40000":{"Action":11,"Text":"0x1b"},"0xf703-0x220000":{"Action":10,"Text":"[1;2C"},"0xf701-0x240000":{"Action":10,"Text":"[1;5B"},"0x4c-0x160000":{"Text":"","Action":34},"0xf70d-0x20000":{"Action":10,"Text":"[21;2~"},"0xf702-0x260000":{"Action":10,"Text":"[1;6D"},"0xf729-0x40000":{"Action":10,"Text":"[1;5H"},"0x69-0x140000":{"Text":"[A","Action":10},"0xf706-0x20000":{"Action":10,"Text":"[1;2R"},"0x34-0x40000":{"Action":11,"Text":"0x1c"},"0xf700-0x280000":{"Action":11,"Text":"0x1b 0x1b 0x5b 0x41"},"0x6a-0x100000":{"Text":"[D","Action":10},"0x4a-0x160000":{"Text":"","Action":33},"0x6a-0x80000":{"Text":"b","Action":10},"0x2d-0x40000":{"Action":11,"Text":"0x1f"},"0xf70e-0x20000":{"Action":10,"Text":"[23;2~"},"0xf702-0x220000":{"Action":10,"Text":"[1;2D"},"0xf703-0x280000":{"Action":11,"Text":"0x1b 0x1b 0x5b 0x43"},"0xf700-0x240000":{"Action":10,"Text":"[1;5A"},"0xf707-0x20000":{"Action":10,"Text":"[1;2S"},"0xf70a-0x20000":{"Action":10,"Text":"[18;2~"},"0x35-0x40000":{"Action":11,"Text":"0x1d"},"0xf70f-0x20000":{"Action":10,"Text":"[24;2~"},"0x6c-0x140000":{"Text":"","Action":0},"0xf703-0x240000":{"Action":10,"Text":"[1;5C"},"0x6b-0x140000":{"Text":"[B","Action":10},"0xf701-0x260000":{"Action":10,"Text":"[1;6B"},"0xf702-0x280000":{"Action":11,"Text":"0x1b 0x1b 0x5b 0x44"},"0xf72b-0x20000":{"Action":10,"Text":"[1;2F"},"0x36-0x40000":{"Action":11,"Text":"0x1e"},"0x6a-0x140000":{"Text":"","Action":2},"0xf708-0x20000":{"Action":10,"Text":"[15;2~"},"0x6c-0x80000":{"Text":"f","Action":10},"0xf701-0x220000":{"Action":10,"Text":"[1;2B"},"0xf70b-0x20000":{"Action":10,"Text":"[19;2~"},"0xf702-0x240000":{"Action":10,"Text":"[1;5D"},"0xf704-0x20000":{"Action":10,"Text":"[1;2P"}}}' > /tmp/iterm_key_presets.itermkeymap | |
| 2. To set these bindings in iTerm2, go to Preferences->Profiles->Keys and then Presets->Import. Import the file '/tmp/iterm_key_presets.itermkeymap'. | |
| Slow way | |
| -------- | |
| Explanation: | |
| esc-f and esc-b : Move by word. Will work in Python and other shells as well. | |
| esc-[A : Equivalent to up arrow key. | |
| esc-[B : Equivalent to down arrow key. | |
| esc-[C : Equivalent to right arrow key. | |
| esc-[D : Equivalent to left arrow key. | |
| You can run `od -c` at the terminal to see the escape sequence / keycode of anything you type. | |
| In the below table, "^[" means "esc-". | |
| To set these bindings in iTerm2, go to Preferences->Profiles->Keys and add these to the table. You can choose "Send Escape Sequence" as the action, and then type (for example) "[A" in the "ESC +" field. | |
| Key Combo Action | |
| ------------------ ------------------- | |
| ctrl-shift-cmd-j Move Tab Left | |
| ctrl-shift-cmd-l Move Tab Right | |
| ctrl-cmd-j Previous Tab | |
| ctrl-cmd-l Next Tab | |
| ctrl-cmd-i Send ^[ [A | |
| ctrl-cmd-k Send ^[ [B | |
| cmd-j Send ^[ [D | |
| cmd-l Send ^[ [C | |
| option-j Send ^[ b | |
| option-l Send ^[ f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment