I recently switched from bash to zsh. One (annoying) difference is that when I do Esc-K (in vi editing mode) to move back in command-line history, the cursor is placed at the end of the line initially. I want it to be at the beginning of the line initially. How can I get what I want?

  • 2
    And when the previous history entry contains several lines (zsh's zle makes it less awkward than readline to enter and edit multi-line commands), would you want the cursor to go to the beginning of the first line or of the last line of that multi-line command? Commented Jan 15, 2020 at 17:57
  • Because I like it that way -- that's why. Commented Jan 15, 2020 at 19:32
  • I'm not able to reproduce it -- the difference I see between bash and zsh I is when I ESC away from the input mode, then go back and forth with k + j, zsh will put the cursor at the beginning of the last command line, and bash will put it at its end; ie different than what you describe. Better make a movie with ffmpeg -f x11grab ;-)
    – user313992
    Commented Jan 16, 2020 at 15:45
  • And btw, Stéphane Chazelas didn't ask you why you want that, but how it should work with multi-line commands.
    – user313992
    Commented Jan 16, 2020 at 15:49

1 Answer 1


For some reason, the default mappings for j and k in the vicmd key map are:

"j" down-line-or-history
"k" up-line-or-history

Remapping them as follows should make them work the way you want:

bindkey -a j vi-down-line-or-history
bindkey -a k vi-up-line-or-history
  • Actually, is bindkey -M vicmd k vi-up-line-or-history better? Commented Jun 8, 2020 at 19:54
  • 1
    I believe they are synonymous. From the man page, bindkey -a is a shortcut for bindkey -M vicmd. Both operate on the vicmd keymap. The latter may be a little more descriptive. Commented Jun 8, 2020 at 23:31

You must log in to answer this question.

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