Looking for ALT+LeftArrowKey solution in zsh

后端 未结 10 766
孤街浪徒
孤街浪徒 2021-01-29 18:13

I just recently switched from bash to zsh, however I miss my Alt+LeftArrowKey and Alt+RightArrowKey to go back and forth a word at a

相关标签:
10条回答
  • 2021-01-29 18:27

    Run cat then press keys to see the codes your shortcut send.
    (Press Ctrl+C to kill the cat when you're done.)
    For me, (ubuntu, konsole, xterm) pressing Alt+ sends ^[[1;3D, so i would put in my .zshrc

    bindkey "^[[1;3C" forward-word
    bindkey "^[[1;3D" backward-word
    

    (Actually I prefer to use Ctrl + arrow to move word by word, like in a normal textbox under windows or linux gui.)

    Related question: Fix key settings (Home/End/Insert/Delete) in .zshrc when running Zsh in Terminator Terminal Emulator

    0 讨论(0)
  • 2021-01-29 18:29

    To make it work for me I used this answer, however I had to swap the codes (left <-> right)

    ⌥+← Send Hex Codes: 0x1b 0x66
    ⌥+→ Send Hex Codes: 0x1b 0x62

    and add the following to my ~/.zshrc

    bindkey -e
    bindkey "^[b" forward-word
    bindkey '^[f' backward-word
    
    0 讨论(0)
  • 2021-01-29 18:29

    If you're using iTerm in CSI u mode, the bindings for your .zshrc end up being:

    bindkey '^[[1;3D' backward-word
    bindkey '^[[1;3C' forward-word
    
    0 讨论(0)
  • 2021-01-29 18:30

    Though not strictly answering your question, the default binding for forward-word and backward-word are alt-f resp. alt-b.

    This works everywhere, does not require you to leave the home row, and has a nice mnemonic property (f=forward, b=back), while also being consistent with ctrl-f and ctrl-b being forward-character and backward-character.

    Rip out your arrow keys!

    0 讨论(0)
  • 2021-01-29 18:35

    On MacOS High Siera 10.13.6 or Mojave 10.14.2 and using iTerm2 with ZSH To move from words I have to put like this:

    bindkey "\e\e[D" backward-word
    bindkey "\e\e[C" forward-word
    

    Another solutions doesn't work fo rme

    0 讨论(0)
  • 2021-01-29 18:35

    If you want iTerminal to respect Emacs style shortcuts like ^Mf and ^Mb for forward/back a word I found best way to use this tip:

    Making iTerm to translate 'meta-key' in the same way as in other OSes

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