iTerm 2: How to set keyboard shortcuts to jump to

2019-01-12 13:05发布

I can see that Ctrl+left/right jumps to the beginning/end of line. How to change this to Cmd+left/right arrow?

In order to get Alt+left/right arrow working correctly for word jumping follow this article.

14条回答
混吃等死
2楼-- · 2019-01-12 13:32

To jump between words and start/end of lines in iTerm2 follow these steps:

  • iTerm2 -> Preferences ( + ,)
  • Open the “Keys” tab
  • Add the following Global Shortcut Keys

Move cursor one word left

  • Keyboard Combination: +
  • Action: Send Hex Code
  • Code: 0x1b 0x62

Move cursor one word right

  • Keyboard Combination: +
  • Action: Send Hex Code
  • Code: 0x1b 0x66

Move cursor to beginning of line

  • Keyboard Combination: +
  • Action: Send Hex Code
  • Code: 0x01

Move cursor to end of line

  • Keyboard Combination: +
  • Action: Send Hex Code
  • Code: 0x05

Delete word

  • Keyboard Combination: + ←Delete
  • Action: Send Hex Code
  • Code: 0x1b 0x08

Delete line

  • Keyboard Combination: + ←Delete
  • Action: Send Hex Code
  • Code: 0x15

Undo

  • Keyboard Combination: + z
  • Action: Send Hex Code
  • Code: 0x1f

Don't forget to remove the previous bindings:

  • Open the “Profiles” tab
  • Click the sub-tab ”Keys”
  • Remove the mappings for key combinations + and +
查看更多
萌系小妹纸
3楼-- · 2019-01-12 13:32

For quick reference of anyone who wants to go to the end of line or start of line in iTerm2, the above link http://hackaddict.blogspot.com/2007/07/skip-to-next-or-previous-word-in-iterm.html notes that in iTerm2:

  • Ctrl+A, jumps to the start of the line, while
  • Ctrl+E, jumps to the end of the line.
查看更多
女痞
4楼-- · 2019-01-12 13:34

In iTerm 3.0.12 you can switch to Natural Text Editing preset:

enter image description here

iTerm → Preferences → Profiles → Keys

Warning As it is a preset, it can override the keys you have binded before. So it's better to save your current key bindings before applying a preset.

查看更多
Summer. ? 凉城
5楼-- · 2019-01-12 13:34

Just to help out anyone that is having the same issue but specifically using Zsh shell with iTerm 2. It turns out that Zsh doesn't read /etc/inputrc properly, and so fails to understand any key bindings you set up through the preferences!

To fix this, you need to add some key bindings to your .zshrc file, such as:

# key bindings
bindkey "\e[1~" beginning-of-line
bindkey "\e[4~" end-of-line

Note the backslashes in the example above before the "e", the linked article does not show them, so add them into your .zshrc file when adding bindings.

查看更多
贪生不怕死
6楼-- · 2019-01-12 13:36

The old fashion emacs bindings can still work in iterm2 and os x terminal:

Preferences -> Profiles -> Keys (sub tab in profiles)

  • Set Left/Right option <kbd>⌥</kbd> key acts as +Esc (similar in os x terminal)

This should enable alt-f and alt-b for moving words by words. (Still ctrl-a and ctrl-e always work as usual)

If set as meta those old bindings will work while some iterm2 bindings unavailable.

查看更多
我只想做你的唯一
7楼-- · 2019-01-12 13:37

Follow the tutorial you listed above for setting up your key preferences in iterm2.

  1. Create a new shorcut key
  2. Choose "Send escape sequence" as the action
  3. Then, to set cmd-left, in the text below that:
    • Enter [H for line start
      OR
    • Enter [F for line end
查看更多
登录 后发表回答