zsh shortcut 'ctrl + A' not working

10,756

Solution 1

you don't have to config the Ctrl+A behavior if you use default keymap (emacs keymap). It does what you are expecting.

However if you set your zle to use vi keymap, you have to define the keybind for vi-beginning-of-line. same for Ctrl+E.

So check which keymap did you set in config. If it was vi, try pressing ESC then ^ and $ should do what you want.

Solution 2

If you're wondering why this happened: You likely have $EDITOR or $VISUAL set to vi/vim which made zsh default to the vi keymap which doesn't use ctrl+a for moving the caret.

Adding bindkey -e to ~/.zshrc will restore the old behavior (emacs keymap).

Solution 3

zsh .zshrc

bindkey "^A" vi-beginning-of-line
Share:
10,756

Related videos on Youtube

Jeanluca Scaljeri
Author by

Jeanluca Scaljeri

Updated on June 15, 2022

Comments

  • Jeanluca Scaljeri
    Jeanluca Scaljeri 5 months

    I recently switch from bash to zsh shell. To be more precise, the oh-my-zsh Very nice, but the shortcut I most often use; jumping to the beginning/end of the line doesn't work anymore. From the docs it should be

    ctrl + A --> beginning
    ctrl + E --> end
    

    However, when I do that I get the following

    $~> my-command
    $~> my-command^A   # did a ctrl + A here
    

    Although I see this working by everybody else, on my system something seems to be different. Any suggestions what that might be ?

    • chepner
      chepner over 8 years
      Check if bindkey | fgrep '^A' returns a line like ""^A" beginning-of-line".
    • Jeanluca Scaljeri
      Jeanluca Scaljeri over 8 years
      if I do that I get for Ctrl+A: "^A"-"^C" self-insert and for Ctrl+E: "^E"-"^F" self-insert
  • Jeanluca Scaljeri
    Jeanluca Scaljeri over 8 years
    Any suggestions how to check this ?
  • Kent
    Kent over 8 years
    @JeanlucaScaljeri you don't know which keymap you are using ? bindkey -v bind vi, bindkye -e binds emacs
  • Jeanluca Scaljeri
    Jeanluca Scaljeri over 8 years
    what would be the preferred way to define this system wide (mac) ? For a specific user is also ok if that is easier ? Now if I open a new terminal I have to this this binding again
  • Kent
    Kent over 8 years
    @JeanlucaScaljeri write it in your ~/.zshrc
  • Jeanluca Scaljeri
    Jeanluca Scaljeri over 8 years
    If I add something like this to my .zshrc it doesn't work: bindkey -e . So should I export something maybe ?
  • Kent
    Kent over 8 years
    Very likely you have Bindkey -v you letter find and remove it. Or you put -e at the end of your config
  • Jeanluca Scaljeri
    Jeanluca Scaljeri over 8 years
    couldn't find it, but when I put that command at the end of .zshrc it works! thnx!
  • mareoraft
    mareoraft almost 4 years
    This is the correct solution for people that want to keep the vim keymap. Use bindkey "^E" vi-end-of-line to map ctrl + E to the end of line behavior.
  • Josh
    Josh over 2 years
    This was it for me. in fact I didn't even have $VISUAL set to vi, I had it set to a command which opened an IDE and the path happened to contain the word visual 🤦🏼‍♂️
  • mbafford
    mbafford about 2 years
    Thank you! This helped me with VSCode/zsh embedded terminal not respecting ^A/^E. I found other hints to make these keys work for iTerm2, but that involved changing how iTerm2 behaves rather than fixing the underlying problem.