Andrew Madsen

Follow @armadsen on Micro.blog.

Remapping ⌘-. (command-period) to BREAK in iTerm2

I switched to iTerm2 from the default macOS Terminal app a few months ago. Mostly, I really like it. It has a ton of power-user features missing in Terminal.app, as well as a nice ecosystem of enhancements. However, there are a few differences that have bugged me.

In Terminal.app, instead of pressing ^C to send a break, and thereby terminate a running program, etc., you can press the standard Mac cancel keyboard shortcut, which is ⌘-. (command-period). This is built into my muscle memory, and is used widely through the Mac interface, as it has been for decades. Out of the box, iTerm2 doesn’t recognize ⌘-. as BREAK, instead filling your terminal with escape sequences.

Of course, iTerm2 is extremely customizable, so it’s a fairly simple matter to remap ⌘-. to send break. To do so, open iTerm2’s Preferences, select the Profiles pane, then the Keys tab. Click the “+” button below the list of keyboard shortcuts to create a new short cut. Record the shortcut itself by selecting the Keyboard Shortcut field and pressing the Command and Period keys. For Action, select “Send Hex Code”. In the text field at the bottom, enter 0x03, which is ASCII for “end of text” (ETX), which is what control-C actually sends in a regular terminal. Click OK and you’re done.

Screen Shot 2020 01 25 at 4 19 17 PM

You can test it out by running something that takes a while, for example an infinitely looping shell script (see below), then pressing ⌘-. to make sure it actually breaks/stops.

#!/bin/bash
while :
do
echo "Press [CTRL+C] to stop.."
sleep 1
done

Screen Shot 2020 01 25 at 4 29 13 PM