1

I am using ITerm2 on Mac OSX, and I am trying to get the "skip words" hotkey (alt left, alt right) to work. On ITerm2, this is done by mapping ⌥ ← to b, and ⌥ → to f (found here: https://coderwall.com/p/h6yfda/use-and-to-jump-forwards-backwards-words-in-iterm-2-on-os-x). However, it seems like VIM's skip words function responds not to the b and f escape sequences, but to [1;5C and [1;5D (found here: https://stackoverflow.com/a/9611698/800735).

So it seems like I need a different set of hotkeys to skip words on VIM, and another set on Iterm2. What I would like to do is remap the escape sequences b and f to [1;5C and [1;5D in ITerm2, for some consistency. I know that its been done on XTerm by adding this to .Xresources: URxvt*keysym.Meta-f: \033[1;5C URxvt*keysym.Meta-b: \033[1;5D

Is there an equivalent in ITerm2?

Thanks

Community
  • 1
  • 1
cozos
  • 787
  • 10
  • 19

1 Answers1

2

The first page mentioned (Use ⌥ ← and ⌥→ to jump forwards / backwards words in iTerm 2, on OS X) is vague about the "command line". Given that it is talking about OSX, the author is likely referring to bash, and making some keys send useful bindings for that shell. bash has predefined key bindings which treat the escape character as a meta modifier.

The other page (How to get Cmd-left/right working with iTerm2 and Vim (without requiring .vimrc changes)?) is solving an analogous problem with vim. But vim treats the escape character specially. So the binding used there is an escape sequence (which is not necessarily universally available — but if it works for you, not a problem).

Since iTerm2 does not really know which program you are using, one approach to this would be to use the escape sequences which iTerm2 sends (and vim accepts) in your bash ".inputrc" file.

Here are a few links discussing that solution (it is not a new problem):

The 5 in the escape sequence, by the way, is for the control modifier, documented in XTerm Control Sequences.

Community
  • 1
  • 1
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • Thanks, so Bash controls the mapping between escape sequences and functions (i.e forward-word, backward-word) in the terminal? The default mapping in ITerm2 was `f -> forward-word`, `b -> backward-word`. Where did those come from (since `[1;5C` and `[1;5D` seem to be the default for bash). I apologize for my ignorance regarding how terminals work ;P – cozos Mar 29 '16 at 19:28
  • Bash's escape-f and escape-b probably predate the control sequences used in xterm which iTerm2 supports. – Thomas Dickey Mar 30 '16 at 20:06