bash zsh vi 模式状态行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3622943/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
zsh vi mode status line
提问by ui_90jax
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 --
zsh 或 bash 有没有办法设置状态行?例如,在 VI 中,它会通过 -- INSERT -- 让您知道您处于插入模式
Is there an eqivalent for the command line?
命令行是否有等价物?
回答by Gilles 'SO- stop being evil'
This has already been answered at Super Userand Unix Stack Exchange. For the completeness of Stack Overflow:
这已经在Super User和Unix Stack Exchange 上得到了回答。为了 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:
如果您希望指示器位于当前行下方而不是右侧,则来自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]; }

