Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zsh vi mode status line

Tags:

bash

vi

zsh

Is there a way in zsh or bash to have a status line? e.g. in VI it will let you know that you are in insert mode with -- INSERT --

Is there an eqivalent for the command line?

like image 652
ui_90jax Avatar asked Sep 01 '10 23:09

ui_90jax


1 Answers

This has already been answered at Super User and Unix Stack Exchange. For the completeness of Stack Overflow:

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

And if you want the indicator below the current line rather than to the right, from Unix Stack Exchange:

terminfo_down_sc=$terminfo[cud1]$terminfo[cuu1]$terminfo[sc]$terminfo[cud1]
function zle-line-init zle-keymap-select {
    PS1_2="${${KEYMAP/vicmd/-- NORMAL --}/(main|viins)/-- INSERT --}"
    PS1="%{$terminfo_down_sc$PS1_2$terminfo[rc]%}%~ %# "
    zle reset-prompt
}
preexec () { print -rn -- $terminfo[el]; }
like image 54
Gilles 'SO- stop being evil' Avatar answered Sep 20 '22 13:09

Gilles 'SO- stop being evil'