iTerm2 Cheatsheet

Shell Integration

Shell integration enables advanced iTerm2 features like marks and command history tracking.

Enable Shell Integration

iTerm2 automatically installs shell integration. To manually enable:

curl -L https://iterm2.com/shell_integration/install_shell_integration.sh | bash

Key Commands

Command Purpose
it2api Interact with iTerm2 from command line
it2cmd Mark command boundaries
iterm2_prompt_mark Manually set marks in shell prompt
iterm2_get_pwd Get current working directory in iTerm2

Using Marks

Marks allow quick navigation between command outputs:

  • Set mark: โŒ˜โ‡งM
  • Jump to mark: โŒ˜โ‡งJ
  • Next mark: โŒ˜โŒฅ.
  • Previous mark: โŒ˜โŒฅ/
Profile Configuration

Profiles define terminal appearance, behavior, and key mappings.

Default Profile Locations

~/Library/Application Support/iTerm2/DynamicProfiles/
~/Library/Application Support/iTerm2/scripts/

Dynamic Profile JSON Structure

{
  "Profiles": [
    {
      "Name": "My Profile",
      "Guid": "profile-guid-12345",
      "Command": "/bin/zsh",
      "Working Directory": "/Users/username",
      "Use Custom Font": true,
      "Font Name": "JetBrains Mono",
      "Font Size": 12,
      "Character Encoding": 4,
      "Color Preset Name": "Catppuccin Mocha",
      "Background Color": {
        "Red Component": 0.1,
        "Green Component": 0.1,
        "Blue Component": 0.12
      }
    }
  ]
}

Key Profile Settings

Setting Purpose
Name Profile display name
Guid Unique identifier
Cursor Type Block, underline, or vertical bar
Use Bold Font Enable bold text rendering
Blinking Cursor Cursor animation toggle
Scrollback Lines Terminal history buffer size
Triggers & Actions

Triggers automatically execute actions when terminal output matches patterns.

Access Triggers

Profile Settings โ†’ Advanced โ†’ Triggers

Common Trigger Patterns

Pattern Use Case
error|ERROR|Error Highlight error messages
warning|WARNING Highlight warnings
^(.*)(passed|failed) Capture test results
^prompt> Custom prompt detection

Available Actions

Action Description
Highlight Text Color code matching output
Capture Output Save matched text to pasteboard
Run Command Execute shell command
Show Alert Display notification
Open URL Launch URL in browser
Send Text Send text to terminal
Bounce Dock Icon Get user attention

Example Trigger Setup

Pattern: npm ERR! Action: Highlight Text (Red background) Instant: Checked

tmux Integration

iTerm2 integrates with tmux for enhanced terminal multiplexing.

Starting tmux with iTerm2

# Start new session with native iTerm2 integration
tmux -CC new-session -s main

# Attach to existing session
tmux -CC attach-session -t main

# New window in tmux session
tmux new-window -t main -n editor

Benefits of tmux Integration

  • Native tab/pane support in iTerm2 UI
  • Native search and copy/paste
  • Profile settings applied per tmux pane
  • Proper unicode and mouse support
  • Automatic session persistence

tmux Dashboard

Access via: iTerm2 Menu โ†’ tmux โ†’ Dashboard

Shows all active tmux sessions with:

  • Session names and window count
  • Pane arrangement visualization
  • Quick switch between sessions

Key Mappings

Action Default
Send command โŒ˜โŒฅC prefix
Detach session โŒ˜โŒฅD
List sessions โŒ˜โŒฅL
Image Display

iTerm2 supports displaying images and downloading files in the terminal.

Image Display Commands

# Display image using imgcat
imgcat ~/screenshot.png

# Inline image display
printf '\e]1337;File=name=filename;size=123456;base64=1:\n'

# Download file from URL
it2dl https://example.com/image.jpg

Supported Image Formats

Format Support Notes
PNG Full Recommended format
JPEG Full Good compression
GIF Full Animated support
TIFF Full Lossless option
PDF Partial First page only

Image Display Features

  • Inline image preview in terminal
  • Click to open in default app
  • Cmd+click to copy to clipboard
  • Right-click for context menu
  • Automatic size adjustment

it2dl - Download Utility

# Basic download
it2dl https://example.com/file.pdf

# Specify destination
it2dl https://example.com/image.jpg ~/Downloads/

# Download with custom name
it2dl --name custom.jpg https://example.com/original.jpg
Advanced Features

Password Manager Integration

iTerm2 can auto-fill passwords from macOS Keychain:

  1. Profile Settings โ†’ Advanced โ†’ Password Manager
  2. Enable “Password Manager” option
  3. Use keyboard shortcut to fill passwords
  4. Supports SSH key passphrases

Instant Replay

Access with: โŒ˜โŒ˜ (press Command twice)

  • Rewind terminal history without scrollback limit
  • Typical limit: last 100MB of data
  • Navigate with arrow keys
  • Disable with: Preferences โ†’ Advanced โ†’ Instant Replay disabled

Smart Selection

Right-click to select intelligently:

  • Email addresses
  • URLs
  • IP addresses
  • File paths
  • Custom regex patterns

Define custom patterns in Preferences โ†’ Profiles โ†’ Advanced โ†’ Smart Selection Rules.

Semantic History

Cmd+click to open files referenced in terminal:

  • Application configuration via Cmd+click
  • Custom opener selection available
  • Supports relative and absolute paths
  • Protocol handler integration (ssh://, ftp://)

Status Bar

Display terminal information persistently:

  • Add components: View โ†’ Toggle Status Bar
  • Available indicators: hostname, git status, time, battery
  • Customizable per profile
  • Light/dark mode aware
Custom Key Mappings

Customize keyboard shortcuts for increased productivity.

Access Key Mappings

Profile Settings โ†’ Keys โ†’ Key Mappings

Common Key Mapping Examples

Key Combo Action Hex Code
โŒ˜โŒซ Delete line 0x15
โŒ˜โ† Move to line start 0x01
โŒ˜โ†’ Move to line end 0x05
โŒฅโ† Move word back 0x1b 0x62
โŒฅโ†’ Move word forward 0x1b 0x66

Hex Code Reference

0x01 = Ctrl+A (Home)
0x05 = Ctrl+E (End)
0x08 = Ctrl+H (Backspace)
0x15 = Ctrl+U (Clear line)
0x17 = Ctrl+W (Delete word)
0x1b = Escape prefix

Custom Mapping Example

Map โŒฅโŒซ to delete word backward:

  1. Key: โŒฅโŒซ
  2. Action: Send Hex Code
  3. Code: 0x17 (Ctrl+W)

Vim Mode Key Mappings

For vim-style navigation:

Vim Key Map To Hex/Text
jk Escape Literal String
โŒ˜h Left Left Arrow
โŒ˜j Down Down Arrow
โŒ˜k Up Up Arrow
โŒ˜l Right Right Arrow
Tips & Tricks

Badges and Titles

Set dynamic window titles in shell config:

# In ~/.zshrc
function set_title() {
  print -Pn "\e]2;$1\a"
}

# Usage
set_title "Development Server"

Arrangements

Save window layouts for quick restoration:

  1. Arrange windows and panes as desired
  2. Window โ†’ Save Window Arrangement
  3. Restore: Window โ†’ Restore Arrangement

Buried Sessions

Hide background sessions without closing:

  • Right-click session
  • “Bury Session”
  • Access via Window menu when needed
  • Useful for long-running processes

Status Bar Customization

Add useful indicators to status bar:

  • Hostname display
  • Git branch/status
  • Current time
  • Battery percentage
  • User-defined components via escape sequences

Command Palette

Quick access to iTerm2 functions:

  • Press: โŒ˜โ‡งA
  • Search for commands
  • Recent commands prioritized
  • Fully customizable

Search Enhancement

Advanced find features:

  • Find in pane history: โŒ˜F
  • Regex pattern support
  • Case-sensitive toggle
  • Highlight all matches
  • Jump to find results with Enter

Session Logging

Enable session recording for auditing:

# Enable logging
script ~/session-$(date +%s).log

# All terminal activity recorded to file
# Exit to close logging
exit

Color Schemes

Apply Catppuccin theme:

  1. Download theme files from catppuccin/iterm2
  2. Preferences โ†’ Profiles โ†’ Colors
  3. Color Presets โ†’ Import
  4. Select Catppuccin Mocha
  5. Apply to profiles

Cursor Customization

Profile Settings โ†’ Appearance โ†’ Cursor:

  • Block (default)
  • Underline
  • Vertical Bar
  • Blinking toggle
  • Color customization per profile