35

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 ?

2
  • 3
    Check if bindkey | fgrep '^A' returns a line like ""^A" beginning-of-line".
    – chepner
    Apr 17, 2014 at 13:17
  • if I do that I get for Ctrl+A: "^A"-"^C" self-insert and for Ctrl+E: "^E"-"^F" self-insert Apr 17, 2014 at 14:00

3 Answers 3

48

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

2
  • 1
    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 🤦🏼‍♂️
    – Josh
    Mar 9, 2020 at 15:50
  • 1
    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.
    – mbafford
    Oct 25, 2020 at 12:13
34

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.

7
  • 1
    Any suggestions how to check this ? Apr 17, 2014 at 14:02
  • 4
    @JeanlucaScaljeri you don't know which keymap you are using ? bindkey -v bind vi, bindkye -e binds emacs
    – Kent
    Apr 17, 2014 at 14:13
  • 1
    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 Apr 17, 2014 at 15:06
  • 1
    @JeanlucaScaljeri write it in your ~/.zshrc
    – Kent
    Apr 17, 2014 at 15:32
  • 1
    Very likely you have Bindkey -v you letter find and remove it. Or you put -e at the end of your config
    – Kent
    Apr 19, 2014 at 13:06
16

zsh .zshrc

bindkey "^A" vi-beginning-of-line
1
  • 7
    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.
    – mareoraft
    Nov 19, 2018 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.