Last Updated: August 12, 2019
·
11.63K
· willybarro

Keybindings for MacOSX users on iTerm2

Have you ever tried to use "Command + back arrow", "Option + front arrow" and such text navigation commands on iTerm? If you did, you've noticed that it simply won't work out of the box and searching for that on Google turns up to be a big mess with confounding results.

There are lots of information in many blog posts, stackoverflow posts and old blog comments (2007), but no centralized solution.

So, here's a centralized solution :D

How to fix

  1. Open up your iTerm;
  2. Click on "iTerm > Preferences";
  3. Go to "Profiles";
  4. Choose your default profile (it may be called "Default" if you didn't changed anything);
  5. Go to "Keys" (inside the Profile tab);
  6. On "Left option key act as:" click the "+Esc" box.
  7. Below the "Profile Shortcut Keys" grid, click on "+" button and add:

COMMAND + <-

ESC+ "[H"

Picture

COMMAND + ->

ESC+ "[F"

Picture

OPTION + <-

ESC+ "b"

Picture

OPTION + ->

ESC+ "f"

Picture

OPTION + Delete

ESC+ "0x1b 0x7f"

Picture


BONUS! Word delete backslash

After getting proud of myself for making my iTerm work as expected, I've tried to delete the last word of a line like this:

$ cat /var/log/nginx.log

And BAM! It deleted the whole path. So... Here's a way to fix that too.

Add this line to your .bashrc file:

bind '\C-w:unix-filename-rubout'

Some background information...

I wrote that tutorial after doing a clean-install of Mavericks on my MacOSX and forgotten to backup my iTerm2 configs. Shame on me!

Kids, never forgets to backup your iTerm configs :)

5 Responses
Add your response

Thanks!

over 1 year ago ·

Please, put a note with the hexa so we can copy it ;)
You are amazing, as always, tho... :*

over 1 year ago ·

Valeu! :D

over 1 year ago ·

Highly recommend doing this in the Preferences > Keys pane instead of per-profile if you want this setting to be consistent across both local and SSH'd/tmux'd environments. If you use OS X and Ubuntu out of the box, it should give the behavior you expect!

over 1 year ago ·

Great tip! Btw if you wish to use OPTION + DEL (not 'backspace') you can do map it using:
Shortcut: ⌥ Del →
Action: Send Escape Sequence
Esc+: d

over 1 year ago ·