Search code examples
zshprezto

In prezto how to get CTRL-RARROW working?


after installing prezto when I press CTRL - RIGHTARROW I can see these characters

source python;5C;5C;5C;5C

Whereas emacs key bindings like ALT- f work fine. I just want my default keybindings where I can navigate using CTRL keys.

My efforts:

  • Raised a issue on github + browsed other similar issues as well. Couldnt figure out how their solution would help my case.
  • Tried setting zstyle ':prezto:module:editor' key-bindings '' but it did not work.
  • I have also checked modeles/editor/init.zsh but the script is too long n I dont wanna make random changes and later keep maintaining those.

Can anyone suggest a way so that my keybindings remain "UNCHANGED" even after .zpreztorc is loaded ?


Solution

  • If you're using the prezto editor module, it will override your key bindings. If you have it set to emacs mode with

    zstyle ':prezto:module:editor' key-bindings 'emacs'
    

    you will need to add your key bindings to that named keymap. You can do that with

    bindkey -M emacs '^[[1;5C' forward-word
    bindkey -M emacs '^[[1;5D' backward-word
    

    This will need to be run after the editor module is loaded. You can do that by adding it to the bottom of your .zshrc file. I use the vi keymap, so I need to add the key bindings to both the viins and vicmd keymaps.

    for keymap in 'emacs' 'viins' 'vicmd'; do
        # [Ctrl-RightArrow] - move forward one word
        bindkey -M $keymap '^[[1;5C' forward-word
        # [Ctrl-LeftArrow] - move backward one word
        bindkey -M $keymap '^[[1;5D' backward-word
    done
    
    unset keymap