iTerm 2: How to set keyboard shortcuts to jump to beginning/end of line?

后端 未结 14 1629
难免孤独
难免孤独 2020-12-02 03:09

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

相关标签:
14条回答
  • 2020-12-02 03:40

    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.
    0 讨论(0)
  • 2020-12-02 03:40

    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.

    0 讨论(0)
  • 2020-12-02 03:43

    bind -p will show a list of bound escaped keys in your shell, that might help giving you more ideas / search terms.

    0 讨论(0)
  • 2020-12-02 03:48

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

    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.

    0 讨论(0)
  • 2020-12-02 03:48

    I used Travis answer and I created a dynamic profile you can import based on its instructions.

    GabLeRoux/iterm2-macos-dynamic-profile

    Instructions are in the readme and it's a lot faster to import this than it is to add them all manually. I made this an answer as per @gooli's request because this was hidden in a comment. Hope you enjoy this

    0 讨论(0)
  • 2020-12-02 03:49

    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.

    0 讨论(0)
提交回复
热议问题