shellkeyzsh

Looking for ALT+LeftArrowKey solution in zsh


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 time.

Right now, if I press Alt+LeftArrowKey I go back a couple of letters and then I'm stuck. I won't go any further backwards and it won't back to the end of the line with Alt+RightArrowKey as I would expect. I can't even use the arrow keys to go to the end of the line, only to the second to last. Can't input new chars on the line either or indeed delete.

How do I get my beloved shortcut back?

I'm on Mac OS X using Terminal if that's important.


Solution

  • 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