Making Alt key work in ITerm on Mac

 

Making the Alt Key Work in iTerm2

iTerm2 is a replacement for the default Terminal application on MacOS. It has many more handy features than Terminal , is free to download and is also open source šŸŽ‰.

However, on first install, you canā€™t use the Option or Alt key (this key: āŒ„) as you would in other applications: you canā€™t skip or jump over words by pressing Alt and the left or right keys. Instead you see sequences like [D or [C:

Broken alt key displaying escape sequences

With a little config, you can change this behaviour, which Iā€™ll explain below.

Note: I refer to the ā€œAltā€ key throughout this post, which is the text written on my old 2013 MacBook Pro keyboard, but this is normally called the ā€œOptionā€ key in MacOS.


Open the ā€œPreferencesā€ menu: either find it in the ā€œiTerm2ā€ dropdown menu along the top of the screen or press the Cmd and comma keys. āŒ˜ + ,

iTerm2 general preferences menu

Choose the ā€œProfilesā€ menu.

iTerm2 profiles menu

Select the ā€œKeysā€ tab.

iTerm2 keys tab

Within the ā€œKey Mappingsā€ pane, find the mapping for the Alt and left keys, which will look like this: āŒ„ā†. Double click it.

iTerm2 keys tab with Alt Mappings

Change the action from ā€œSend Hex Codeā€ to ā€œSend Escape Sequenceā€ (you might have to scroll a bit to find this).

In the ā€œEsc +ā€ field, type lowercase ā€œbā€ and click ā€œOKā€.

iTerm2 Alt left mapping

Open the same context menu for Alt plus right āŒ„ā†’ and again change the action to ā€œSend Escape Sequenceā€.

This time, in the ā€œEsc +ā€ field, type lowercase ā€œfā€. Click ā€œOKā€.

Close the menu and begin using the Alt and the left/right arrows immediately. The cursor will now ā€œjumpā€ over entire words as it does on other applications. Your command line navigation will now be faster and more precise.

Working alt key moving between words

Comments

Popular posts from this blog

SOX - Sound eXchange - How to use SOX for audio processing tasks in research.

Sox of Silence - Original post - http://digitalcardboard.com/blog/2009/08/25/the-sox-of-silence/

Remove white background in blogger post