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:
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:
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:
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.