Install iTerm2
- Install it with brew, check here for more HomeBrew tips and tricks
brew tap caskroom/cask
brew cask install iterm2
# or install iterm2-beta
# brew tap homebrew/cask-versions
# brew cask install iterm2-beta
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
Keys | Action |
---|---|
Cmd+\ | Show Annotations |
Cmd+Click | Clickable Links |
Cmd+Shift+H | Paste History |
Cmd+k | Clear buffer |
Cmd+Shift+O | Open Quickly(Search tabs) |
Cmd+; | Autocomplete |
Cmd+Shift+; | Show Command History |
Cmd+Shift+H | Show Paste History |
Cmd+Option+/ | Recent Directories popup |
Bash emacs mode shortcuts
Keys | Action |
---|---|
CTRL-A | Move cursor to the beginning of the line |
CTRL-E | Move to the end of the line |
CTRL-K | Kill forward to the end of a line |
CTRL-U | Kill the line from the beginning to this point |
^abc^def | Run previous command, replacing abc with def |
Option+left(right) | Move backward(forward) one word |
Tips for iTerm2
- Copy to pasteboard on selection
Cmd+k
toclear current buffer
vsCmd+r
or theclear
bash command.- Use
Cmd+k: clear current buffer
, if you don’t wantcmd+f
to search old history
- Use
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+Left | Action: Send Escape Sequence | Esc+ b |
Keyboard Shortcut: Option+Right | Action: Send Escape Sequence | Esc+ 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