I'm a vim user, and just recently started playing with zsh to be able to use vi mode in the shell (which isn't practical in bash due to lack of insert/command mode indicator). After reading some examples, I set up the following function to update the line accordingly (I picked the colorscheme to match vim-powerline, which I also use):
vim_ins_mode="%{$fg[white]%}%{$fg_bold[blue]$bg[white]%} INSERT %{$reset_color%}"
vim_cmd_mode="%{$fg[green]%}%{$fg_bold[black]$bg[green]%} COMMAND %{$reset_color%}"
vim_mode=$vim_ins_mode
function zle-line-init zle-keymap-select {
RPS1="${${KEYMAP/vicmd/${vim_cmd_mode}}/(main|viins)/${vim_ins_mode}}"
RPS2=$RPS1
zle reset-prompt
}
zle -N zle-line-init
zle -N zle-keymap-select
It works great, except that as I run more commands, RPS1 from previous commands gets output to the screen. As you can imagine, having multiple bright boxes all over my terminal can get quite distracting:
I'm hoping to clear this field somehow before it gets dumped into the linebuffer as previous command, but so far neither the examples nor zsh themes I looked at bother doing this. In my old .bashrc file I had a trap setup to reset the coloring of my command so that the output color is not affected, I'm wondering if something similar would be possible here? Or perhaps there is a cleaner way with zsh?
Try the following code:
function _-accept-line()
{
emulate -L zsh
local SAVEDRPS1="$RPS1"
RPS1=""
zle reset-prompt
RPS1="$SAVEDRPS1"
zle .accept-line
}
zle -N accept-line _-accept-line
Forget about this code. Zsh has an option for the behavior you want:
setopt transientrprompt
Remove any right prompt from display when accepting a command line. This may be useful with terminals with other cut/paste methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With