6

In emacs, M-f moves the caret to the end of the next word. In zsh, M-f (or rather alt-f) moves the caret to the beginning of the next word.

For a more consistent experience, I'd like to have zsh alt-f mirror emacs behavior.

How can I do this?

1 Answer 1

8
bindkey '\ef' emacs-forward-word

See:

zle -la | grep word

to list the widgets that contain the word word.

info --index-search=emacs-forward-word zsh

to get the documentation on a given widget.

3
  • Mapping \M-f to emacs-forward-word did not work for me. Searching with bindkey | grep forward-word showed that the correct mapping on my system was to ^[f and ^[F.
    – ehuang
    Commented Dec 23, 2013 at 19:55
  • 1
    @EricHuang, yes sorry, \M-f is f with the eighth bit set. Some terminals send that upon Alt-F but they are getting rare in those utf8 days. I'll amend the answer as \ef is likely to be useful to more people. Commented Dec 23, 2013 at 21:49
  • This is close but not the same. bash/libreadline/emacs will move the cursor to c in a-b-c. But emacs-backward-word moves the cursor to a. What is the correct zsh option which actually provides emacs-like behavior?
    – binki
    Commented Oct 21, 2020 at 2:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .