Five tips for iTerm

I like to avoid unnecessary tooling, adding complexity only when current tools have reached their limits. While macOS’s built-in terminal.app has improved, it’s limitations are easy to find.

The best terminal replacement is iTerm2. The developers claim iTerm “brings the terminal into the modern age with features you never knew you always wanted.” In fact iTerm is so feature-rich that what you always wanted might remain undiscovered, hidden in the vast preferences menu.

Some of iTerm’s less obvious features have made a significant impact on my workflow. For those new to iTerm or those still plumbing its depths, here are five tips for maximizing iTerm’s power and flexibility.

1. Non-native Full Screen Mode

Most of my development work is done on a 13" MacBook Air. While I love the Air’s size and portability, its screen real estate is limited. It feels crowded to have a terminal window open alongside a text editor. Fortunately iTerm offers the option to disable “native full screen mode.” This makes it easy to switch back-and-forth between an editor and shell. How? Rather than opening a native full-screen app with the accompanying slow animation, iTerm instantly places a terminal over the desktop. The result looks like this:

Here’s how to enable it in the Preferences menu:

Under the “General” tab uncheck “Native full screen windows.”
In the “Profiles” tab select “Window” and then change the style to “Fullscreen.” This tells iTerm to open new windows in fullscreen mode.
Optionally, set the transparency and blur effects. I find enabling a little transparency helps me remember what’s on the desktop, while blur effect prevents desktop text from obfuscating the terminal’s output.
Finally, in the “Keys” tab enable the system-wide show/hide hotkey. I use ⌘i (the mnemonic being i = iTerm). This conflicts with the italics shortcut in some apps, but that’s a tradeoff I can live with.

Now a fullscreen terminal appears and disappears as fast as you can hit a hotkey.

2. Clickable Links

A simple one: hold the key and click on any URL. iTerm will open the link in a new browser tab. This is great for opening localhost windows after a dev server starts. It can also be used to open directories and files, although this behavior seems less consistent.

3. OSX Shortcuts

By default iTerm uses standard bash shortcuts to navigate text (e.g. ⌃c jumps to the beginning of a line). However, macOS’s uses Cocoa Text bindings everywhere else, including text editors (e.g. ⌘← jumps to the beginning of a line). It was always difficult to override macOS muscle memory at the command line. Fortunately, iTerm allows you to remap bash shortcuts to be more Mac-like. Begin in Preferences→Profiles→Keys. It should look like this:

First click “+” to add a new shortcut.
Press the shortcut’s key combination: ⌘← (jump to beginning of line)
Set the appropriate action: Send Escape Sequence
Enter the Escape Sequence: [H
This does override some shortcuts defined in iTerm’s global “Keys” menu. For instance ⌘← will no longer jump one tab to the left. However, I simply use ⌘1, ⌘2, etc to select tabs in the order they appear.
Keyboard Shortcut: ⌘→ (jump to end of line)
Action: Send Escape Sequence
Esc+ [F
Keyboard Shortcut: ⌥← (jump back one word)
Action: Send Escape Sequence
Esc+ b
Keyboard Shortcut: ⌥→ (jump forward one word)
Action: Send Escape Sequence
Esc+ f
Keyboard Shortcut: ⌘←Delete (Delete line to the left of cursor)
Action: Send Hex Code
0x15
Keyboard Shortcut:⌥←Delete (Delete word to the left of cursor)
Action: Send Hex Code
0x1B 0x08

4. Paste History

This one can save a lot of time. To access everything you’ve pasted into iTerm, use ⌘⇧H and select the command you wish to paste again.

5. Profiles and Window Arrangements

I didn’t initially appreciate the power of “Profiles” in iTerm. But creating a handful of profiles makes it possible to launch a custom workspace with one click. This means never having to go through the tedious process of starting a dev server, test runner, database console, etc. when jumping back into a project. Here’s how to setup a workspace for Rails:

First, select the “Default” profile and then “Duplicate Profile” from the “Other Actions” menu. This will duplicate all settings from the default profile (for instance the macOS keybindings described above).
Select the new profile, give it a name, and specify the text to be run at start. Then select “Reuse previous session’s directory” as the working directory.
Repeat the duplication and configuration process. These are the settings used to start Guard. Again, “Reuse previous session’s directory.”
Settings for a database console.
Settings for a Rails console.

Setting up the workspace involves using these profiles in conjunction with another powerful iTerm feature: split panes. A tab can be divided horizontally or vertically and each pane can run a different session. This means we can assign a profile to each pane and recall this workspace configuration later.

To create a new workspace, first cd into your project’s directory. To create a horizontal split, use ⌘⌥⇧H, or ⌘⌥⇧V for a vertical split. When creating a new pane, iTerm will ask what profile you want to use. After you have a few panes created, you can rearrange them by dragging with the mouse. Once your panes are in a preferred configuration, just hit ⌘⇧S to save the window arrangement. To launch your arrangement, use ⌘⇧R at anytime.

For those using laptops or smaller monitors, ⌘⇧⏎ will maximize/minimize the active pane. This is useful for examining log files in greater depth.

To discover more features check out the iTerm site. And follow its creator, George Nachman, on Twitter.