Looking for ALT+LeftArrowKey solution in zsh

后端 未结 10 764
孤街浪徒
孤街浪徒 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:43

    In zsh, you can use the bindkey command to see keyboard shortcuts.

    Use bindkey to explore options that are available without custom keybindings.

    Namely ^[b to move backward a word and ^[f to move forward a word.

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

    On Mavericks (10.9.4) the code is 1;5... so for binding alt with arrows I have my .zshrc using this:

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

    You can use CTRL+V and then the command you want to use

    in Yosemite use Rob's solution

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

    Adding the following to ~/.zshrc worked for me on OSX Mountain Lion.

    bindkey -e
    bindkey '[C' forward-word
    bindkey '[D' backward-word
    
    0 讨论(0)
  • 2021-01-29 18:49

    For anyone using iTerm, regardless of shell

    All of the solutions offered here take a backwards approach in my opinion. You're essentially telling your shell to listen for some esc sequence or other key binding you have set in your terminal, creating compatibility issues when you switch shells (If you SSH into some other shell, switch from BASH to ZSH, etc and you lose some if not all of your keybindings).

    Most shells have a set of default sequences that come pre-bound. Furthermore, while they aren't 100% consistent, they're close enough. So the easiest way that I have found to create keybinding for a particular action in the shell is to tell your terminal application to bind to the default keybindings that are consistent across shells.

    I wrote a compressive solution for getting your terminal to respond as close to native mac keybindings here

    Open the iTerm preferences +, and navigate to the Profiles tab (the Keys tab can be used, but adding keybinding to your profile allows you to save your profile and sync it to multiple computers) and keys sub-tab and enter the following:

    Move cursor one word left

    + Send Hex Codes: 0x1b 0x62

    Move cursor one word right

    + Send Hex Codes: 0x1b 0x66

    And that should give you the desired behavior not just in ZSH, but also if you SSH into a server running BASH, irb/pry, node etc.

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