zsh shortcut 'ctrl + A' not working
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
Related videos on Youtube
Jeanluca Scaljeri
Updated on June 15, 2022Comments
-
Jeanluca Scaljeri 5 monthsI 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 --> endHowever, when I do that I get the following
$~> my-command $~> my-command^A # did a ctrl + A hereAlthough I see this working by everybody else, on my system something seems to be different. Any suggestions what that might be ?
-
chepner over 8 yearsCheck ifbindkey | fgrep '^A'returns a line like ""^A" beginning-of-line". -
Jeanluca Scaljeri over 8 yearsif I do that I get for Ctrl+A:"^A"-"^C" self-insertand for Ctrl+E:"^E"-"^F" self-insert
-
-
Jeanluca Scaljeri over 8 yearsAny suggestions how to check this ? -
Kent over 8 years@JeanlucaScaljeri you don't know which keymap you are using ?bindkey -vbind vi,bindkye -ebinds emacs -
Jeanluca Scaljeri over 8 yearswhat 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 over 8 years@JeanlucaScaljeri write it in your~/.zshrc -
Jeanluca Scaljeri over 8 yearsIf I add something like this to my .zshrc it doesn't work:bindkey -e. So should I export something maybe ? -
Kent over 8 yearsVery likely you have Bindkey -v you letter find and remove it. Or you put -e at the end of your config -
Jeanluca Scaljeri over 8 yearscouldn't find it, but when I put that command at the end of .zshrc it works! thnx! -
mareoraft almost 4 yearsThis is the correct solution for people that want to keep the vim keymap. Usebindkey "^E" vi-end-of-lineto map ctrl + E to the end of line behavior. -
Josh over 2 yearsThis was it for me. in fact I didn't even have$VISUALset tovi, I had it set to a command which opened an IDE and the path happened to contain the wordvisual🤦🏼♂️ -
mbafford about 2 yearsThank 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.