Emacs keybindings in zsh not working (Ctrl-A, Ctrl-E)

My Emacs keybindings in zsh are not working (CtrlA, CtrlE). I use zsh on OS X.

They might be bound to some other thing. I'm currently using oh-my-zsh.

And my .zshrc is over here.

enter image description here


Solution 1:

I got the problem solved. Looks like oh-my-zsh was overriding the default keybindings.

When I added the below line at the end of my .zshrc, CtrlE and CtrlA worked:

bindkey -e

Solution 2:

Generally speaking, you can find the code of a key by typing CtrlV and the key. You can then use this key with bindkey to map it to a zsh keyboard functionality (e.g. beginning-of-line).

In your specific case that would be CtrlV CtrlA and CtrlV CtrlE.

Then you can put the code in your .inputrc, the system /etc/inputrc, or your .zshrc like this:

bindkey '^A' beginning-of-line
bindkey '^E' end-of-line

This works for other keys too. For instance, I had some trouble with Home and End.

You should be able to use this trick in any terminal session : tty,