Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Ok, so I finally made the great change. In my .zshenv, I changed my EDITOR:

export EDITOR=vim

There are a couple of questions I have that are so minor that I didn't want to start separate questions for them. Here they are:

  1. How do I get zsh to distinguish between insert mode and command mode like in vim? Preferably this would change the cursor from an underline to a block like in vim, but displaying text at the bottom would work as well.

  2. How do I get it to act more like vim? For instance, I'd rather it be in command mode by default and not go out of it after one command.

share|improve this question
add comment

3 Answers 3

up vote 16 down vote accepted

1.) (see http://zshwiki.org/home/examples/zlewidgets and http://pthree.org/2009/03/28/add-vim-editing-mode-to-your-zsh-prompt/ ):

function zle-line-init zle-keymap-select {
    RPS1="${${KEYMAP/vicmd/-- NORMAL --}/(main|viins)/-- INSERT --}"
    RPS2=$RPS1
    zle reset-prompt
}
zle -N zle-line-init
zle -N zle-keymap-select

Where:

2.) i suspect that you have to write another zsh-widget to do that, get inspired by the first of the two links for the first problem.

share|improve this answer
add comment

akira's solution has the following problem when using multiline prompts: when going from ins to cmd mode, the prompt redraw causes few lines to be deleted from the previous output (and the new prompt is displayed few lines above). How many lines depends on how many lines you have in your prompt.

The way to deal with that is to use zle-line-finish, without using zle reset-prompt there. An example:

vim_ins_mode="[INS]"
vim_cmd_mode="[CMD]"
vim_mode=$vim_ins_mode

function zle-keymap-select {
  vim_mode="${${KEYMAP/vicmd/${vim_cmd_mode}}/(main|viins)/${vim_ins_mode}}"
  zle reset-prompt
}
zle -N zle-keymap-select

function zle-line-finish {
  vim_mode=$vim_ins_mode
}
zle -N zle-line-finish

And then you can add it to your right-prompt, for example:

RPROMPT='${vim_mode}'

This is straight from my blog post about it:

share|improve this answer
    
This answer should get a lot of votes. This is the first time I've seen this solution, and it works where the others don't. I spent an hour fiddling around with the zle-line-init widget to no avail. Changed it to match what Pawel provided and bingo! –  Colin R Nov 28 '12 at 5:34
    
Thanks! It still isn't 100% bulletproof - from time to time I experience a situation where some lines from my previous output are deleted - but it happens so rarely that I just ignore it. –  Paweł Gościcki Nov 28 '12 at 10:06
    
RPROMPT2 should be set as well so that the status is displayed in continuation lines. Also, when using this you may want to do setopt transient_rprompt so that modes for previously accepted lines aren't displayed. –  qqx Mar 24 '13 at 15:59
    
Thanks @qqx! Those are very cool tips! –  Paweł Gościcki Mar 24 '13 at 20:19
    
One thing that is still missing: If I switch back to emacs mode (bindkey -e) it still shows [INS]. –  Daniel Oct 28 '13 at 17:33
show 2 more comments
zle-line-init() { zle -K vicmd; }
zle -N zle-line-init

these two lines make sure it starts in command mode

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.