The Computer Oracle

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

--------------------------------------------------
Become or hire the top 3% of the developers on Toptal https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Light Drops

--

Chapters
00:00 Question
00:35 Accepted answer (Score 41)
00:59 Answer 2 (Score 9)
01:50 Thank you

--

Full question
https://superuser.com/questions/523564/e...

Question links:
[oh-my-zsh]: https://github.com/robbyrussell/oh-my-zs...
[here]: https://github.com/Takehiro-Adachi/dotfi...
[image]: https://i.stack.imgur.com/BwkbA.png

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#macos #keyboardshortcuts #zsh

#avk47



ACCEPTED ANSWER

Score 42


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



ANSWER 2

Score 9


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,