Nap Joseph Calub

Software Engineer and Open Source Enthusiast

iTerm2 key bindings

Published on January 22, 2024

iTerm2

I recently got a new Mac mini M1 and I wanted to share my iTerm2 key bindings:

DescriptionKeyboard shortcutActionValue
Move to the beginning of the line⌘ + ←Send Hex Code0x01
Move to the end of the line⌘ + →Send Hex Code0x05
Deleting a line⌘ + ←DeleteSend Hex Code0x15
Move forward a word⌥ + →Send Hex Code0x1B 0x66
Move backward a word⌥ + ←Send Hex Code0x1B 0x62
Deleting a word⌥ + ←DeleteSend Hex Code0x17

In order to set these key bindings, you need to go to iTerm2 > Preferences > Keys > Key Bindings > + and then add the key bindings above.

##Nerd Deep Dive

Terminal emulators like iTerm2 simulate the behavior of physical terminals (like the DEC VT100) from the early days of computing. These physical terminals were hardware devices used to interact with a computer, allowing users to input commands and view the output. The communication between the terminal and the computer was standardized through specific codes and sequences, facilitating text manipulation and cursor movement, among other functions.

###ASCII Control Characters

ASCII, or American Standard Code for Information Interchange, is a character encoding standard for electronic communication. It includes a set of control characters that are intended not to represent printable information but to control devices that use ASCII, such as terminals.

Hex CodeNameMeaningUsage Above
0x01SOHStart of Headingmove to start of line
0x05ENQEnquirymove to end of line
0x15NAKNegative Acknowledgementdelete line
0x17ETBEnd of Transmission Blockdelete word

###ANSI Escape Sequences

Escape sequences are strings of characters that start with the ESC character followed by a series of characters that instruct the terminal to perform a specific action, like moving the cursor or changing text colors.

For terminals that adhere to the xterm protocol or similar, moving forward or backward by a word is often achieved through specific escape sequences rather than hex codes.

SequenceDescription
ESC + fmove forward a word
ESC + bmove backward a word

On iTerm2, you can actually use the "Send Escape Sequence" for such:

DescriptionKeyboard shortcutActionValue
Move forward a word⌥ + →Send Escape Sequencef
Move backward a word⌥ + ←Send Escape Sequenceb

So what is the deal with 0x1B 0x66 and 0x1B 0x62 above?

The 0x1B is the hex code for the ESC character, and 0x66 and 0x62 are the hex values for f (ASCII Character 102) and b (ASCII Character 98), respectively.

This is just another way to represent the same escape sequences.

© 2021 Nap Joseph Calub. All rights reserved.

Light Mode
Dark Mode