kuda.ai | code. guitar. life.

Settings For a Better iTerm2 Experience

created in September 2022, last update in November 2022

iTerm2 is a fantastic terminal app for your mac. Many developers use it. In fact, I think most think it's the better alternative to the Mac's standard terminal.

iterm2-theme-minimal

There are a few settings which will make your iTerm2 experience even better.

My Most Used Keyboard Shortcuts

I strongly prefer using the keyboard over the mouse or touchpad, and there is a lot that you can achieve in iTerm2 with the keyboard. Here is a list of the keyboard shortcuts that I use the most:

  • cmd + enter -> activate / deactivate full screen
  • cmd + + -> zoom in
  • cmd + - -> zoom out
  • cmd + 0 -> reset zoom
  • cmd + shift + enter -> maximize current window (especially useful when you use split windows)
  • cmd + t -> open a new tab
  • cmd + w -> close focused window
  • cmd + d -> split window vertically
  • cmd + shift + d -> split window horizontally
  • cmd + {1..9} -> Move to tab with number {1..9}
  • cmd + i -> change name of the tab

Cycle The Pane Focus With Your Keyboard

A feature that you are maybe already familiar with is splitting the window into panes. You split the pane either with cmd + d or cmd + shift + d.

iterm2-split-panes

The default shortcut to cycle the focus of the panes is either cmd + [ (move focus left) or cmd + ] (move focus right). If you use a standard keyboard layout, you would have to move your fingers away from the home row to press these keys.

You may find it way easier (like I do) to remap these actions to cmd + h (move left) and cmd + l (move right). This is inspired by vim, and for me, intuitive to apply. In vim, you move your cursor to the left with h and to the right with l. (And for the sake of completeness: To the bottom with j and to the top with k :) )

open your iTerm2 settings (cmd + ,), choose "Keys", click the little plus symbol at the bottom left, select "Previous Pane" or "Next Pane" and assign your favourite key binding so that you don't have to lift your fingers from the home row.

iterm2-keybindings

Something which is to my individual taste and probably something not everyone will like: I have disabled the dimming of inactive panes (as seen in the picture with the split pane above). If you prefer this, too, you can change it at "Settings/Appearance/Dimming".

iterm2-pane-dimming

Change Your Color Preset With dark() and light()

If you use a light color theme during daytime (e.g. rosé-pine-dawn) and change to a dark color theme in the evening (e.g. rosé-pine), how you maybe might do it now is by opening the preferences menu with cmd + ,, clicking on profiles, choose your profile, click on colors, then choose your favorite color theme from the dropdown. Finally, you close the preferences window (e.g. with cmd + w or with your mouse on the close symbol at the thop left).

Phew, that are two keyboard shortcuts plus four mouse navigations and clicks! We can do better than that.

I enter the command dark() to change my color theme to rosé-pine, and the command light() to change to rosé-pine-dawn.

iterm2-light-dark

(As you can see, I couldn't yet figure out how to change the color of the status bar at the bottom, too. For now I accept that the status bar is dark, luckily, it doesn't look too bad.)

To do that, you have to create three custom functions in any of your terminal dot files. If you are using zsh, then you would have to edit the file ~/.zshrc. The tilde symbol ~ represents your home directory, e.g. /Users/davidkuda/. Another synonym for ~ is the global variable $HOME, which is normally present in any unix environment. Therefore, the ~/ in ~/.zshrc means "in your home directory /Users/davidkuda/".

The dot in front of the word "zshrc" in ~/.zshrc means that the file is hidden. If you open your finder and search the file, you will not find it. And if you type ls ~ (list files in ~) will also not list a hidden file, unless you add the -a option (ls -a ~).

So here is the change you need to do:

change_color_preset() { echo -e "\033]1337;SetColors=preset=$1\a" }
dark() { change_color_preset rose-pine }
light() { change_color_preset rose-pine-dawn }

You see the $1 in the first line. This represents the first argument passed to the function. In the line two and three, you see that you call the function with an argument.

The string that gets executed is an escape code that iTerm2 offers to be used as an API to iTerm2.

Use The Minimal Theme For a Better Look of The Top Bar And Your Tabs

If you use a color theme like the popular catpuccin or rosé pine (the theme I use) then most likely the Mac standard light / dark theme will interfere with your color scheme. You can avoid that by using iTerm2's minimal theme.

iterm2-minimal

choose "Appearance", from "Theme", select "minimal".

Now let's compare the minimal theme with the regular theme.

The Minimal Theme

Notice how well and seamlessly the tabs at the top integrate with your color scheme! wonderful, delightful, joyful. Love it. :)

iterm2-theme-minimal

The Regular Theme During Daytime (Light Mode)

Notice how much of a break this leads too! A shame that this is the default and the way more beautiful looking minimal theme is so hidden and has to be discovered.

iterm2-theme-regular-light

The Regular Theme During Night (Dark Mode)

I find this even worse than the light mode, since the dark gray of the Mac's dark mode isn't really working so well with the dark theme of the color scheme.

iterm2-theme-regular

Activate The Status Bar

You can add system information to the bottom of your terminal by activating the "status bar". You may have noticed my status bar in the screenshots above.

To do so, open your iTerm2 settings with cmd + ,, from Profiles, choose yours, select "Session", and at the very bottom, you find the radio button to activate the status bar (wow, it's really well hidden").

iterm2-statusbar-radio

Version Control Your iTerm2 Config

If you ever happen to change to another mac, it would take you long to change all the settings again to your likings (color theme, keymaps, status bar, etc.).

Your configuration is probably located at ~/.config/iterm2/. The tilde symbol (~) stands for your home directory, e.g. /Users/davidkuda/ and is synonymous to the environment variable $HOME.

Normally, you would encounter folders in this directory, but iTerm2 uses a .plist file and has a rather unusual but specific name, namely: "com.googlecode.iterm2.plist".

iterm2-config

cd ~/.config/
ls -1a # make sure you see the file
git init
git add com.googlecode.iterm2.plist
git commit --message "version control my iTerm2 config"
# I have left the "git add remote" etc out and leave that up to you.
# Once on a new mac, restore by copying file to this folder.

Change The Names of Your Tabs

You can change the name of the current tab by pressing cmd + i. Enter a new session name and hit enter, et voilà, your tab is renamed.