71

I recently upgraded from Snow Leopard to Lion and Xcode 4.1, and word jumping stopped working in both Terminal and iTerm2. Did the mappings change?

This is with and without a homebrew installation of readline.

My .inputrc looks like this:

"\e[1;5D": backward-word
"\e[1;5C": forward-word

Thanks!

Carson
  • 17,073
  • 19
  • 66
  • 87
  • 1
    To clarify "stopped working": when I press `Ctrl+[left]` or `Ctrl+[right]`, nothing happens. `Ctrl+A` and `Ctrl+E` still work for line jumping. – Carson Jul 23 '11 at 17:16
  • 2
    Ctrl+[left|right] for me switch between spaces and full-screen apps. Not sure if that's the default or not. Do you see the same behaviour? – Rob Cowie Jul 23 '11 at 18:36
  • 7
    That's probably it. You can turn them off in Keyboard Shortcuts in System Preferences. Select the "Mission Control" category. – Nicholas Riley Jul 23 '11 at 20:59

6 Answers6

152

Just add the escape sequences in iTerm settings as global shortcut keys.

Word backward (option-arrowleft):

a iTerm settings

Same with word forward, just use F.

Nik
  • 2,902
  • 2
  • 16
  • 11
  • 4
    Here's a more detailed description of Nik's method: https://coderwall.com/p/h6yfda I think it's better to use Option than Control for word skipping so iTerm is consistent with every other OSX app. – Powers Jul 13 '14 at 14:29
  • Is there a list somewhere which describes more of these esoteric escape sequences and hex codes? – Jonathan Aug 11 '14 at 09:49
  • Not sure, Jonathan. I think these control codes are special to iTerm. – Nik Aug 27 '14 at 19:40
  • 9
    Make sure, they are not overridden by Profile keys. Also it should be f and not F, b and not B – Nitin Nov 05 '15 at 20:27
  • 2
    @Nitin - F and B works just fine here, but whatever works for you :) – Nik Nov 06 '15 at 09:12
  • 1
    For some weird reason this doesn't work on Sierra and iTerm2. What could be the problem? – Mladen Petrovic Nov 02 '16 at 11:26
  • 1
    You definitely (though this may depend on your OS/iTerm version, keyboard layout) do not want to turn the alt/opt keys into escape characters as suggested by the coderwall article. It'll prevent you from using these keys to access special chars. I.e. on a FIN keyboard you couldn't type some quite essential chars like: `|{}[]$`. It also seems to be totally unnecessary as simply modifying the key shortcuts seems to be enough. So please don't read the coderwall artcile, it'll only confuse you. Just set the key combo to send escape sequence b/f. – Timo May 12 '17 at 06:45
  • thank you! iterm2 high sierra m1 works perfectly! – WiRight Sep 21 '21 at 08:15
26

The easiest/quickest way I have found is under Profiles > Keys > 'Load Preset...' > 'Natural Text Editing'.

Then use the option key rather than the control key.

(iterm2 version 3)

typingduck
  • 825
  • 10
  • 15
19

Killing a fly with a cannon:

  • Go to Preferences... > Profiles > Keys
  • Press Load Preset...
  • Select Natural Text Editing

Then, you can move a word backwards using Option ⌥ + and a word forwards using Option ⌥ + , move to the start of the line using fn + and to the end of the line with fn + . Also you can delete a word backwards using Option ⌥ + , delete the whole line using Command ⌘ + .

If the preset doesn't appear, reinstall iTerm2. If you installed it using Homebrew+Cask:

brew cask reinstall iterm2

source and credits https://apple.stackexchange.com/a/293988/330806

best wishes
  • 5,789
  • 1
  • 34
  • 59
6

mission control took over the same commands as word jumping. thanks to rob cowrie and nicholas riley for the heads-up on that.

Carson
  • 17,073
  • 19
  • 66
  • 87
5

I added the following in my /etc/inputrc

# word jump on SHIFT left/right arrows
"\e[1;2D": backward-word
"\e[1;2C": forward-word

it works great

Olivier Refalo
  • 50,287
  • 22
  • 91
  • 122
0

Following the steps listed in the above answers, I found that on my laptop the first bash (1.bash) will not be able to jump words by pressing option + arrow. Instead, it will simply type in "[D","[C". However, if I create a new bash window (2. bash), the word jump works.