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
- Open up your iTerm;
- Click on "iTerm > Preferences";
- Go to "Profiles";
- Choose your default profile (it may be called "Default" if you didn't changed anything);
- Go to "Keys" (inside the Profile tab);
- On "Left option key act as:" click the "+Esc" box.
- Below the "Profile Shortcut Keys" grid, click on "+" button and add:
COMMAND + <-
ESC+ "[H"
COMMAND + ->
ESC+ "[F"
OPTION + <-
ESC+ "b"
OPTION + ->
ESC+ "f"
OPTION + Delete
ESC+ "0x1b 0x7f"
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 :)
Written by Willy Barro
Related protips
5 Responses
Thanks!
Please, put a note with the hexa so we can copy it ;)
You are amazing, as always, tho... :*
Valeu! :D
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!
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