I use bindkey -v (for bash-ers set -o vi I think that works in zsh too) or vi(m) mode. but it bugs me that I don't have any visual cue to tell me whether I'm in insert mode or command mode. Does anyone know how I can make my prompt display the mode?

link|improve this question

feedback

3 Answers

you can try VimMode

link|improve this answer
3  
I was hoping for something a bit less linkish and a bit more explanatory. I like to know how things work. – xenoterracide Aug 19 '10 at 6:29
Actually it is all there. Look at the comments the functions and how they are bound to the mode change events. – Martin Dec 30 '11 at 18:38
feedback

You've already found zle-keymap-select which is executed whenever the mode changes. You could use it to set some other visual indicator than the prompt, depending on what your terminal supports it (and your taste in mode indicator display, of course).

There is a standard terminfo capability to change the shape of the cursor. However some terminals display the same cursor in both modes. Xterm's notion of a less visible cursor is to make it blink (and this must be enabled with the -bc command line argument or cursorBlink resource).

zle-keymap-select () {
  case $KEYMAP in
    vicmd) print -rn -- $terminfo[cvvis];; # block cursor
    viins) print -rn -- $terminfo[cnorm];; # less visible cursor
  esac
}

With some terminals, you can also change the cursor color with print -n '\e]12;pink\a' (by color name) or print -n '\e]12;#abcdef\a' (by RGB specification). These sequences are described in the xterm documentation, in the ctlseqs file; modern terminal emulators typically emulate xterm, though they might not support all its features.

link|improve this answer
feedback
up vote 1 down vote accepted

I found this via SU. Here's the basic example, though I'm still customizing it for myself:

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

I'd explain it except I don't really understand it yet

link|improve this answer
I tried this approach but found one issue. If you do something like CTRL+C while in vi-command mode, the prompt will reset, but indicate youre in command mode when youre really in insert mode. zle-line-init should always change the indicator to insert mode. For some reason $KEYMAP is not updated properly when zle-line-init is called. – Patrick Apr 21 at 19:25
feedback

Your Answer

 
or
required, but never shown

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