Set up iTerm2

iTerm2 is a Terminal alternative for macOS.

Installation

Install iTerm2 via Homebrew:

$ brew install --cask iterm2

Install oh-my-zsh via

$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Set up movement & delete shortcuts

iTerm does not feature shortcuts for moving word-by-word or to the end or beginning of a line.

  1. Go to Settings ‣ Profiles ‣ Keys ‣ Key Mapping.

  2. Add these new key mapping, for each selection Send Escape Sequence as Action:

    Key Mapping

    Action

    Value

    Does what?

    Alt+Left

    Send Escape Sequence

    b

    Jump one word to the left

    Alt+Right

    Send Escape Sequence

    f

    Jump one word to the right

    Alt+Del<-

    Send Hex Code

    0x17

    Delete left standing word

    Alt+Del->

    Send Escape Sequence

    d

    Delete right standing word

    Cmd+Left

    Send Hex Code

    0x01

    Move to beginning of the row

    Cmd+Right

    Send Hex Code

    0x05

    Move to end of the row

    Cmd+Del<- *

    Send Hex Code

    0x18 0x7f

    Delete current row

    Cmd+Del->

    Send Hex Code

    0x0b

    Delete everything after cursor

    * need to add this to your ~/.zshrc or ~/.zprofile to make it work:

    # iTerm2 support for 'Delete current row' keymap
    bindkey "^X\\x7f" backward-kill-line
    

A quicker solution, but which does not feature all above key mappings is to change the presets to Natural Text Editing.

Set custom color theme

There a lot of color themes to choose from.

  1. Open the XML files for the respective theme and save it as *.itermcolors file.

  2. In iTerm go to Settings ‣ Profiles ‣ Colors.

  3. Select Color Preset… -> Import… and select the *.itermcolors file.

  4. Again chose Color Presets…, and select the imported theme. They are immediately applied to the current shell.

Set custom oh-my-zsh theme

There are a variety of themes available for iTerm (all compatible with oh-my-zsh).

In this guide, the powerlevel10k theme is used for demonstration.

  1. Install the theme via homebrew:

    $ brew install powerlevel10k
    
  2. Add it to your ~/.zshrc file to be launched for each new shell window:

    $ echo "source $(brew --prefix)/share/powerlevel10k/powerlevel10k.zsh-theme" >>~/.zshrc
    
  3. Open a new shell window to start the setup wizard.

  4. Confirm installing the new font, afterwards restart iTerm2.

  5. The setup resumes. Follow the instructions and make your choices

Add custom plugins

Oh-my-zsh features a lot of optional plugins for various purposes. A list is available in the Plugins wiki page. The only plugin already pre-enabled is the git plugin.

To add a plugin, open the ~.zshrc file and add the plugin name to the plugins variable, for example:

plugins=(git pyenv)

Other tweaks

  • Change cursor to blinking, vertical bar:

    Settings ‣ Profiles ‣ Text ‣ Cursor:

    • select Vertical bar

    • check Blinking cursor

  • Add command syntax highlighting:

    1. Install zsh-syntax-highlighting:

      $ brew install zsh-syntax-highlighting
      
    2. Enable it by adding a source line to your ~/.zshrc file:

      $ echo "source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc