Working Effectively with iTerm2



Series: Awesome Tips about Mac

Install iTerm2

install shell-integration
  • Install from menu: iTerm2 > Install Shell Integration

Change Default Settings to Make iTerm2 Even Better

To make iTerm2 even better, we can change its default settings by pressing Cmd+, or open menu iTerm2 -> Preferences.

Reuse previous session’s directory
  • Profiles > Default > General > Working Directory > Reuse previous session’s directory
Store command history/directory info
  • Check Save copy/paste and command history at General > Magic Section.
    • So we can use the history, recent directory even after restart iTerm
Restore last windows after restart
  • Ensure Preferences > Advanced > Restore window contents at startup is set to Yes in iTerm (default to true)
  • Ensure “Close windows when quitting an app” is off in Mac’s System Preferences >General
Disable “Quit iTerm2?” confirm dialog

By default, iTerm2 will ask us whether we really want to quit or close sessions. We always click OK. Even we accidentally quit iTerms, we can just reopen it, it will restore previous tabs.

So let’s disable all confirm dialogs for closing at Preferences -> General -> Closing section and uncheck all.

Other Settings
  • Enable “Check for updates automatically” at General -> Services. (iTerms’s pretty useful, so why not keep it to the latest.)

Keyboard Shortcuts for iTerm2

KeysAction
Cmd+\Show Annotations
Cmd+ClickClickable Links
Cmd+Shift+HPaste History
Cmd+kClear buffer
Cmd+Shift+OOpen Quickly(Search tabs)
Cmd+;Autocomplete
Cmd+Shift+;Show Command History
Cmd+Shift+HShow Paste History
Cmd+Option+/Recent Directories popup

Bash emacs mode shortcuts

KeysAction
CTRL-AMove cursor to the beginning of the line
CTRL-EMove to the end of the line
CTRL-KKill forward to the end of a line
CTRL-UKill the line from the beginning to this point
^abc­^­defRun previous command, replacing abc with def
Option+left(right)Move backward(forward) one word

Tips for iTerm2

  • Copy to pasteboard on selection
  • Cmd+k to clear current buffer vs Cmd+r or the clear bash command.
    • Use Cmd+k: clear current buffer, if you don’t want cmd+f to search old history
Command History - Cmd+Shift+;
  • Type to search, up/down to select
Paste History - Cmd+Shift+H
  • Works for multiple-lines command
Split Screening
  • Cmd+d for horizontal split
  • Cmd+Shift+d for vertical split
highlight errors and warnings
  • Preferences > Profiles > Advanced > Triggers > Edit
(?i:.*error.*)                     // Yellow on Black
(?i:.*(warning|warn).*)            // Orange on Black
(?i:.*FATAL.*)                     // White on Red
Make Option+left(right) work
  • Preferences > Profiles > Keys
Keyboard Shortcut: Option+LeftAction: Send Escape SequenceEsc+ b
Keyboard Shortcut: Option+RightAction: Send Escape SequenceEsc+ f
imgcat
  • Show the image in the command line.
badge

A badge is a large text label that appears in the top right of a terminal session to provide dynamic status, such as the current host name or git branch

  • Preferences>Profiles>General>Badge (session.username)@(session.hostname)

Toolbet

Track long running command
  • Edit > Marks and Annotations > Alert on next mark

Labels

adsense (5) Algorithm (69) Algorithm Series (35) Android (7) ANT (6) bat (8) Big Data (7) Blogger (14) Bugs (6) Cache (5) Chrome (19) Code Example (29) Code Quality (7) Coding Skills (5) Database (7) Debug (16) Design (5) Dev Tips (63) Eclipse (32) Git (5) Google (33) Guava (7) How to (9) Http Client (8) IDE (7) Interview (88) J2EE (13) J2SE (49) Java (186) JavaScript (27) JSON (7) Learning code (9) Lesson Learned (6) Linux (26) Lucene-Solr (112) Mac (10) Maven (8) Network (9) Nutch2 (18) Performance (9) PowerShell (11) Problem Solving (11) Programmer Skills (6) regex (5) Scala (6) Security (9) Soft Skills (38) Spring (22) System Design (11) Testing (7) Text Mining (14) Tips (17) Tools (24) Troubleshooting (29) UIMA (9) Web Development (19) Windows (21) xml (5)