Trying to get used to zsh to match the new Mac default, and one of the things that's tripping me up is the differences in vi mode. I already found the answers at How can I make zsh's vi mode behave more like bash's vi mode? and How do I customize zsh's vim mode? are very helpful, but there are still a couple annoyances.

One of those is cursoring through the history: whenever I move up or down in the command list, the cursor moves to the end of the line instead of staying at the beginning like it does in ksh or bash. I'm including the answer I came up with in case it might help someone else, but if there's a better solution please let me know!

1 Answer 1


The only solution I've found is to bind the cursor up and down keys to functions that both move up or down and move to the start of the line, as two actions:

zle-up-and-back() {
  zle .up-line-or-history
  zle .beginning-of-line
zle -N zle-up-and-back
bindkey -M vicmd k zle-up-and-back      # k in command mode
bindkey -M vicmd '^[[A' zle-up-and-back # cursor-up key in command mode
bindkey -M viins '^[[A' zle-up-and-back # cursor-up key in insert mode

zle-down-and-back() {
  zle .down-line-or-history
  zle .beginning-of-line
zle -N zle-down-and-back
bindkey -M vicmd j zle-down-and-back       # j in command mode
bindkey -M vicmd '^[[B' zle-down-and-back  # cursor-down key in command mode
bindkey -M viins '^[[B' zle-down-and-back  # cursor-down key in insert mode

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.