Iterm2

This article talks about how to set up iterm2 to make it easier to user.

Iterm2 is probably the most well-known and powerful terminal on Mac. It has a lot of cool features. It is definitely the best terminal recommended on Mac.

Items To Tune

Item2 is a pretty awesome terminal, but there are still some rooms to make it better.

Hotkeys

The biggest caveat I found with iterm2 is that it doesn’t come with a lot of escape codes, meaning certain hotkeys might not work.

For example, by default, ctrl+option+<arrow> is not working, these hotkeys were used by us switch tmux windows in here. Another missing hotkey is ctrl+<backspace>. This is used to erase the previous word in here.

To see what escape codes are covered, go to iterm2 Settings -> Profiles -> Keys -> Key Mappings, you’ll see all the supported escape codes. You can add more escape codes here to support the above hotkeys.

At the last section of this article, I’ll paste a iterm2 profile that will cover a relatively complete set of escape codes.

Blue Color

By default, the blue color is very dark, making it really hard to see texts in blue. The default blue color can be changed in iterm2 Settings -> Profiles -> Colors.

Font

The default font for iterm2 is Monaco. It is a pretty good font if you are using a high DPI screen. If you are not using a high DPI screen, e.g., 1440p on a 32 inch monitor, texts in Monaco might not be so sharp.

A recommended font is Terminus TTF, which was derived from a bitmap font. It is super sharp even if you have a low DPI screen. To install it, just type in (assuming you have homebrew):

brew install --cask font-terminus

Here’s a recommended config for all the above changes. To apply this, save the following json into a file.

{
    "Profiles": [
        {
            "Custom Command": "Yes",
            "Guid": "1001E50F-4E0B-4467-B9B4-FE868517C0BC",
            "Name": "sweworld-iterm2-config",
            "Option Key Sends" : 2,
            "Right Option Key Sends" : 2,
            "Normal Font" : "TerminusTTF 16",
            "Ansi 4 Color" : {
                "Red Component" : 0.09893798828125,
                "Blue Component" : 1,
                "Green Component" : 0.30184742994606495
            },
            "Foreground Color" : {
                "Red Component" : 0.72156862745098038,
                "Color Space" : "sRGB",
                "Blue Component" : 0.90196078431372551,
                "Alpha Component" : 1,
                "Green Component" : 0.83921568627450982
            },
           "Keyboard Map" : {
                "0xf72c-0x40000" : {
                    "Name" : "[C-Prior]",
                    "Text" : "",
                    "Action" : 2
                },
                "0xf72d-0x40000" : {
                    "Name" : "[C-Next]",
                    "Text" : "",
                    "Action" : 0
                },
                "0xf700-0x220000" : {
                    "Name" : "[S-up]",
                    "Action" : 10,
                    "Text" : "[1;2A",
                },
                "0xf701-0x220000" : {
                    "Name" : "[S-down]",
                    "Action" : 10,
                    "Text" : "[1;2B",
                },
                "0xf703-0x220000" : {
                    "Name" : "[S-right]",
                    "Action" : 10,
                    "Text" : "[1;2C",
                },
                "0xf702-0x220000" : {
                    "Name" : "[S-left]",
                    "Action" : 10,
                    "Text" : "[1;2D",
                },
                "0xf72b-0x20000" : {
                    "Name" : "[S-end]",
                    "Action" : 10,
                    "Text" : "[1;2F",
                },
                "0xf729-0x20000" : {
                    "Name" : "[S-home]",
                    "Action" : 10,
                    "Text" : "[1;2H",
                },
                "0xf700-0x280000" : {
                    "Name" : "[M-up]",
                    "Action" : 10,
                    "Text" : "[1;3A",
                },
                "0xf701-0x280000" : {
                    "Name" : "[M-down]",
                    "Action" : 10,
                    "Text" : "[1;3B",
                },
                "0xf703-0x280000" : {
                    "Name" : "[M-right]",
                    "Action" : 10,
                    "Text" : "[1;3C",
                },
                "0xf702-0x280000" : {
                    "Name" : "[M-left]",
                    "Action" : 10,
                    "Text" : "[1;3D",
                },
                "0xf72b-0x80000" : {
                    "Name" : "[M-end]",
                    "Action" : 10,
                    "Text" : "[1;3F",
                },
                "0xf729-0x80000" : {
                    "Name" : "[M-home]",
                    "Action" : 10,
                    "Text" : "[1;3H",
                },
                "0xf700-0x2a0000" : {
                    "Name" : "[M-S-up]",
                    "Action" : 10,
                    "Text" : "[1;4A",
                },
                "0xf701-0x2a0000" : {
                    "Name" : "[M-S-down]",
                    "Action" : 10,
                    "Text" : "[1;4B",
                },
                "0xf703-0x2a0000" : {
                    "Name" : "[M-S-right]",
                    "Action" : 10,
                    "Text" : "[1;4C",
                },
                "0xf702-0x2a0000" : {
                    "Name" : "[M-S-left]",
                    "Action" : 10,
                    "Text" : "[1;4D",
                },
                "0xf72b-0xa0000" : {
                    "Name" : "[M-S-end]",
                    "Action" : 10,
                    "Text" : "[1;4F",
                },
                "0xf729-0xa0000" : {
                    "Name" : "[M-S-home]",
                    "Action" : 10,
                    "Text" : "[1;4H",
                },
                "0xf700-0x240000" : {
                    "Name" : "[C-up]",
                    "Action" : 10,
                    "Text" : "[1;5A",
                },
                "0xf701-0x240000" : {
                    "Name" : "[C-down]",
                    "Action" : 10,
                    "Text" : "[1;5B",
                },
                "0xf703-0x240000" : {
                    "Name" : "[C-right]",
                    "Action" : 10,
                    "Text" : "[1;5C",
                },
                "0xf702-0x240000" : {
                    "Name" : "[C-left]",
                    "Action" : 10,
                    "Text" : "[1;5D",
                },
                "0xf72b-0x40000" : {
                    "Name" : "[C-end]",
                    "Action" : 10,
                    "Text" : "[1;5F",
                },
                "0xf729-0x40000" : {
                    "Name" : "[C-home]",
                    "Action" : 10,
                    "Text" : "[1;5H",
                },
                "0xf700-0x260000" : {
                    "Name" : "[C-S-up]",
                    "Action" : 10,
                    "Text" : "[1;6A",
                },
                "0xf701-0x260000" : {
                    "Name" : "[C-S-down]",
                    "Action" : 10,
                    "Text" : "[1;6B",
                },
                "0xf703-0x260000" : {
                    "Name" : "[C-S-right]",
                    "Action" : 10,
                    "Text" : "[1;6C",
                },
                "0xf702-0x260000" : {
                    "Name" : "[C-S-left]",
                    "Action" : 10,
                    "Text" : "[1;6D",
                },
                "0xf72b-0x60000" : {
                    "Name" : "[C-S-end]",
                    "Action" : 10,
                    "Text" : "[1;6F",
                },
                "0xf729-0x60000" : {
                    "Name" : "[C-S-home]",
                    "Action" : 10,
                    "Text" : "[1;6H",
                },
                "0xf700-0x2c0000" : {
                    "Name" : "[C-M-up]",
                    "Action" : 10,
                    "Text" : "[1;7A",
                },
                "0xf701-0x2c0000" : {
                    "Name" : "[C-M-down]",
                    "Action" : 10,
                    "Text" : "[1;7B",
                },
                "0xf703-0x2c0000" : {
                    "Name" : "[C-M-right]",
                    "Action" : 10,
                    "Text" : "[1;7C",
                },
                "0xf702-0x2c0000" : {
                    "Name" : "[C-M-left]",
                    "Action" : 10,
                    "Text" : "[1;7D",
                },
                "0xf72b-0xc0000" : {
                    "Name" : "[C-M-end]",
                    "Action" : 10,
                    "Text" : "[1;7F",
                },
                "0xf729-0xc0000" : {
                    "Name" : "[C-M-home]",
                    "Action" : 10,
                    "Text" : "[1;7H",
                },
                "0xf700-0x2e0000" : {
                    "Name" : "[C-M-S-up]",
                    "Action" : 10,
                    "Text" : "[1;8A",
                },
                "0xf701-0x2e0000" : {
                    "Name" : "[C-M-S-down]",
                    "Action" : 10,
                    "Text" : "[1;8B",
                },
                "0xf703-0x2e0000" : {
                    "Name" : "[C-M-S-right]",
                    "Action" : 10,
                    "Text" : "[1;8C",
                },
                "0xf702-0x2e0000" : {
                    "Name" : "[C-M-S-left]",
                    "Action" : 10,
                    "Text" : "[1;8D",
                },
                "0xf72b-0xe0000" : {
                    "Name" : "[C-M-S-end]",
                    "Action" : 10,
                    "Text" : "[1;8F",
                },
                "0xf729-0xe0000" : {
                    "Name" : "[C-M-S-home]",
                    "Action" : 10,
                    "Text" : "[1;8H",
                },
                "0xf727-0x80000" : {
                    "Name" : "[M-insert]",
                    "Action" : 10,
                    "Text" : "[2;3~",
                },
                "0xf727-0xa0000" : {
                    "Name" : "[M-S-insert]",
                    "Action" : 10,
                    "Text" : "[2;4~",
                },
                "0xf727-0x40000" : {
                    "Name" : "[C-insert]",
                    "Action" : 10,
                    "Text" : "[2;5~",
                },
                "0xf727-0x60000" : {
                    "Name" : "[C-S-insert]",
                    "Action" : 10,
                    "Text" : "[2;6~",
                },
                "0xf727-0xc0000" : {
                    "Name" : "[C-M-insert]",
                    "Action" : 10,
                    "Text" : "[2;7~",
                },
                "0xf727-0xe0000" : {
                    "Name" : "[C-M-S-insert]",
                    "Action" : 10,
                    "Text" : "[2;8~",
                },
                "0xf728-0x20000" : {
                    "Name" : "[S-delete]",
                    "Action" : 10,
                    "Text" : "[3;2~",
                },
                "0xf728-0x80000" : {
                    "Name" : "[M-delete]",
                    "Action" : 10,
                    "Text" : "[3;3~",
                },
                "0xf728-0xa0000" : {
                    "Name" : "[M-S-delete]",
                    "Action" : 10,
                    "Text" : "[3;4~",
                },
                "0xf728-0x40000" : {
                    "Name" : "[C-delete]",
                    "Action" : 10,
                    "Text" : "[3;5~",
                },
                "0xf728-0x60000" : {
                    "Name" : "[C-S-delete]",
                    "Action" : 10,
                    "Text" : "[3;6~",
                },
                "0xf728-0xc0000" : {
                    "Name" : "[C-M-delete]",
                    "Action" : 10,
                    "Text" : "[3;7~",
                },
                "0xf728-0xe0000" : {
                    "Name" : "[C-M-S-delete]",
                    "Action" : 10,
                    "Text" : "[3;8~",
                },
                "0xf72c-0x20000" : {
                    "Name" : "[S-prior]",
                    "Action" : 10,
                    "Text" : "[5;2~",
                },
                "0xf72c-0x80000" : {
                    "Name" : "[M-prior]",
                    "Action" : 10,
                    "Text" : "[5;3~",
                },
                "0xf72c-0xa0000" : {
                    "Name" : "[M-S-prior]",
                    "Action" : 10,
                    "Text" : "[5;4~",
                },
                "0xf72c-0x40000" : {
                    "Name" : "[C-prior]",
                    "Action" : 10,
                    "Text" : "[5;5~",
                },
                "0xf72c-0x60000" : {
                    "Name" : "[C-S-prior]",
                    "Action" : 10,
                    "Text" : "[5;6~",
                },
                "0xf72c-0xc0000" : {
                    "Name" : "[C-M-prior]",
                    "Action" : 10,
                    "Text" : "[5;7~",
                },
                "0xf72c-0xe0000" : {
                    "Name" : "[C-M-S-prior]",
                    "Action" : 10,
                    "Text" : "[5;8~",
                },
                "0xf72d-0x20000" : {
                    "Name" : "[S-next]",
                    "Action" : 10,
                    "Text" : "[6;2~",
                },
                "0xf72d-0x80000" : {
                    "Name" : "[M-next]",
                    "Action" : 10,
                    "Text" : "[6;3~",
                },
                "0xf72d-0xa0000" : {
                    "Name" : "[M-S-next]",
                    "Action" : 10,
                    "Text" : "[6;4~",
                },
                "0xf72d-0x40000" : {
                    "Name" : "[C-next]",
                    "Action" : 10,
                    "Text" : "[6;5~",
                },
                "0xf72d-0x60000" : {
                    "Name" : "[C-S-next]",
                    "Action" : 10,
                    "Text" : "[6;6~",
                },
                "0xf72d-0xc0000" : {
                    "Name" : "[C-M-next]",
                    "Action" : 10,
                    "Text" : "[6;7~",
                },
                "0xf72d-0xe0000" : {
                    "Name" : "[C-M-S-next]",
                    "Action" : 10,
                    "Text" : "[6;8~",
                },
                "0x7f-0x40000" : {
                    "Name" : "[C-backspace]",
                    "Action" : 10,
                    "Text" : "[127;5u",
                },
                "0x000a-0xc0000" : {
                    "Name" : "[C-M-return]",
                    "Action" : 10,
                    "Text" : "[13;13u",
                },
                "0x000a-0x20000" : {
                    "Name" : "[S-return]",
                    "Action" : 10,
                    "Text" : "[13;2u",
                },
                "0x000a-0x40000" : {
                    "Name" : "[C-return]",
                    "Action" : 10,
                    "Text" : "[13;5u",
                },
                "0x000a-0x60000" : {
                    "Name" : "[C-S-return]",
                    "Action" : 10,
                    "Text" : "[13;6u",
                },
                "0x0009-0xc0000" : {
                    "Name" : "[C-M-tab]",
                    "Action" : 10,
                    "Text" : "[9;13u",
                },
                "0x0009-0x20000" : {
                    "Name" : " [S-tab]",
                    "Action" : 10,
                    "Text" : "[9;2u",
                },
                "0x0009-0x40000" : {
                    "Name" : " [C-tab]",
                    "Action" : 10,
                    "Text" : "[9;5u",
                },
                "0x0009-0x60000" : {
                    "Name" : " [C-S-tab]",
                    "Action" : 10,
                    "Text" : "[9;6u",
                },
                "0x21-0xe0000" : {
                    "Name" : "[C-M-S-1]",
                    "Action" : 10,
                    "Text" : "[33;14u",
                },
                "0x21-0x60000" : {
                    "Name" : "[C-S-1]",
                    "Action" : 10,
                    "Text" : "[33;6u",
                },
                "0x22-0xc0000" : {
                    "Name" : "[C-M-\"]",
                    "Action" : 10,
                    "Text" : "[34;14u",
                },
                "0x22-0x40000" : {
                    "Name" : "[C-\"]",
                    "Action" : 10,
                    "Text" : "[34;6u",
                },
                "0x23-0xe0000" : {
                    "Name" : "[C-M-S-3]",
                    "Action" : 10,
                    "Text" : "[35;14u",
                },
                "0x23-0x60000" : {
                    "Name" : "[C-S-3]",
                    "Action" : 10,
                    "Text" : "[35;6u",
                },
                "0x24-0xe0000" : {
                    "Name" : "[C-M-S-4]",
                    "Action" : 10,
                    "Text" : "[36;14u",
                },
                "0x24-0x60000" : {
                    "Name" : "[C-S-4]",
                    "Action" : 10,
                    "Text" : "[36;6u",
                },
                "0x25-0xe0000" : {
                    "Name" : "[C-M-S-5]",
                    "Action" : 10,
                    "Text" : "[37;14u",
                },
                "0x25-0x60000" : {
                    "Name" : "[C-S-5]",
                    "Action" : 10,
                    "Text" : "[37;6u",
                },
                "0x26-0xe0000" : {
                    "Name" : "[C-M-S-7]",
                    "Action" : 10,
                    "Text" : "[38;14u",
                },
                "0x26-0x60000" : {
                    "Name" : "[C-S-7]",
                    "Action" : 10,
                    "Text" : "[38;6u",
                },
                "0x27-0xc0000" : {
                    "Name" : "[C-M-']",
                    "Action" : 10,
                    "Text" : "[39;13u",
                },
                "0x27-0x40000" : {
                    "Name" : "[C-']",
                    "Action" : 10,
                    "Text" : "[39;5u",
                },
                "0x28-0xe0000" : {
                    "Name" : "[C-M-S-9]",
                    "Action" : 10,
                    "Text" : "[40;14u",
                },
                "0x28-0x60000" : {
                    "Name" : "[C-S-9]",
                    "Action" : 10,
                    "Text" : "[40;6u",
                },
                "0x29-0xe0000" : {
                    "Name" : "[C-M-S-0]",
                    "Action" : 10,
                    "Text" : "[41;14u",
                },
                "0x29-0x60000" : {
                    "Name" : "[C-S-0]",
                    "Action" : 10,
                    "Text" : "[41;6u",
                },
                "0x2a-0xe0000" : {
                    "Name" : "[C-M-S-8]",
                    "Action" : 10,
                    "Text" : "[42;14u",
                },
                "0x2a-0x60000" : {
                    "Name" : "[C-S-8]",
                    "Action" : 10,
                    "Text" : "[42;6u",
                },
                "0x3d-0xe0000" : {
                    "Name" : "[C-M-S-=]",
                    "Action" : 10,
                    "Text" : "[43;14u",
                },
                "0x3d-0x60000" : {
                    "Name" : "[C-S-=]",
                    "Action" : 10,
                    "Text" : "[43;6u",
                },
                "0x2c-0xc0000" : {
                    "Name" : "[C-M-,]",
                    "Action" : 10,
                    "Text" : "[44;13u",
                },
                "0x2c-0x40000" : {
                    "Name" : "[C-,]",
                    "Action" : 10,
                    "Text" : "[44;5u",
                },
                "0x2e-0xc0000" : {
                    "Name" : "[C-M-.]",
                    "Action" : 10,
                    "Text" : "[46;13u",
                },
                "0x2e-0x40000" : {
                    "Name" : "[C-.]",
                    "Action" : 10,
                    "Text" : "[46;5u",
                },
                "0x2f-0xc0000" : {
                    "Name" : "[C-M-/]",
                    "Action" : 10,
                    "Text" : "[47;13u",
                },
                "0x2f-0x40000" : {
                    "Name" : "[C-/]",
                    "Action" : 10,
                    "Text" : "[47;5u",
                },
                "0x30-0xc0000" : {
                    "Name" : "[C-M-0]",
                    "Action" : 10,
                    "Text" : "[48;13u",
                },
                "0x30-0x40000" : {
                    "Name" : "[C-0]",
                    "Action" : 10,
                    "Text" : "[48;5u",
                },
                "0x31-0xc0000" : {
                    "Name" : "[C-M-1]",
                    "Action" : 10,
                    "Text" : "[49;13u",
                },
                "0x31-0x40000" : {
                    "Name" : "[C-1]",
                    "Action" : 10,
                    "Text" : "[49;5u",
                },
                "0x32-0xc0000" : {
                    "Name" : "[C-M-2]",
                    "Action" : 10,
                    "Text" : "[50;13u",
                },
                "0x32-0x40000" : {
                    "Name" : "[C-2]",
                    "Action" : 10,
                    "Text" : "[50;5u",
                },
                "0x33-0xc0000" : {
                    "Name" : "[C-M-3]",
                    "Action" : 10,
                    "Text" : "[51;13u",
                },
                "0x33-0x40000" : {
                    "Name" : "[C-3]",
                    "Action" : 10,
                    "Text" : "[51;5u",
                },
                "0x34-0xc0000" : {
                    "Name" : "[C-M-4]",
                    "Action" : 10,
                    "Text" : "[52;13u",
                },
                "0x34-0x40000" : {
                    "Name" : "[C-4]",
                    "Action" : 10,
                    "Text" : "[52;5u",
                },
                "0x35-0xc0000" : {
                    "Name" : "[C-M-5]",
                    "Action" : 10,
                    "Text" : "[53;13u",
                },
                "0x35-0x40000" : {
                    "Name" : "[C-5]",
                    "Action" : 10,
                    "Text" : "[53;5u",
                },
                "0x36-0xc0000" : {
                    "Name" : "[C-M-6]",
                    "Action" : 10,
                    "Text" : "[54;13u",
                },
                "0x36-0x40000" : {
                    "Name" : "[C-6]",
                    "Action" : 10,
                    "Text" : "[54;5u",
                },
                "0x37-0xc0000" : {
                    "Name" : "[C-M-7]",
                    "Action" : 10,
                    "Text" : "[55;13u",
                },
                "0x37-0x40000" : {
                    "Name" : "[C-7]",
                    "Action" : 10,
                    "Text" : "[55;5u",
                },
                "0x38-0xc0000" : {
                    "Name" : "[C-M-8]",
                    "Action" : 10,
                    "Text" : "[56;13u",
                },
                "0x38-0x40000" : {
                    "Name" : "[C-8]",
                    "Action" : 10,
                    "Text" : "[56;5u",
                },
                "0x39-0xc0000" : {
                    "Name" : "[C-M-9]",
                    "Action" : 10,
                    "Text" : "[57;13u",
                },
                "0x39-0x40000" : {
                    "Name" : "[C-9]",
                    "Action" : 10,
                    "Text" : "[57;5u",
                },
                "0x3a-0xc0000" : {
                    "Name" : "[C-M-\\:]",
                    "Action" : 10,
                    "Text" : "[58;14u",
                },
                "0x3a-0x40000" : {
                    "Name" : "[C-\\:]",
                    "Action" : 10,
                    "Text" : "[58;6u",
                },
                "0x3b-0xc0000" : {
                    "Name" : "[C-M-;]",
                    "Action" : 10,
                    "Text" : "[59;13u",
                },
                "0x3b-0x40000" : {
                    "Name" : "[C-;]",
                    "Action" : 10,
                    "Text" : "[59;5u",
                },
                "0x3c-0xe0000" : {
                    "Name" : "[C-M-S-,]",
                    "Action" : 10,
                    "Text" : "[60;14u",
                },
                "0x3c-0x60000" : {
                    "Name" : "[C-S-,]",
                    "Action" : 10,
                    "Text" : "[60;6u",
                },
                "0x3d-0xc0000" : {
                    "Name" : "[C-M-=]",
                    "Action" : 10,
                    "Text" : "[61;13u",
                },
                "0x3d-0x40000" : {
                    "Name" : "[C-=]",
                    "Action" : 10,
                    "Text" : "[61;5u",
                },
                "0x3e-0xe0000" : {
                    "Name" : "[C-M-S-.]",
                    "Action" : 10,
                    "Text" : "[62;14u",
                },
                "0x3e-0x60000" : {
                    "Name" : "[C-S-.]",
                    "Action" : 10,
                    "Text" : "[62;6u",
                },
                "0x5c-0xc0000" : {
                    "Name" : "[C-M-\\]",
                    "Action" : 10,
                    "Text" : "[92;13u",
                },
            },
        },
    ]
}

And then go to iterm2 Settings -> Profiles -> Import JSON profiles, select the saved json file.

iterm2-config

Once it is applied, set the loaded profile as the default one, and restart your iterm2 to make them take effects.