zsh-vimode-visual
zsh-vimode-visual copied to clipboard
But zsh already has a visual mode...
You reference http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html in your documentation. If you go there and search for the word "visual", you'll find that zsh already has a visual mode. In addition to viins and vicmd, visual and viopp keymaps were added three years ago. Are you perhaps stuck using an ancient release of zsh? Or has oh-my-zsh tricked you because it stupidly rebinds v to edit-command-line? Zsh also comes with functions for implementing the surround plugin which you seem to have duplicated.
Or have I somehow misunderstood what this plugin is going?
It just shows —VISUAL—
Like vim.
Maybe try it? :)
dezza: What's "it" in this case? The plugin does a lot more than show -- VISUAL --, and in fact it doesn't do that for me.
@okapia you need to have a zsh theme that recognizes vi-mode and uses that to show -VISUAL- or similar
If all you want is the display -VISUAL- or similar when in visual mode, use a zle-line-pre-redraw
hook. This plugin seems to rebind every key and practically reinvents the entire visual feature. All you need is a dozen lines like:
zle-line-pre-redraw() {
[[ $KEYMAP != vicmd ]] && return
local new="$RPS1"
if (( REGION_ACTIVE )); then
new="(VIS)"
else
new="(CMD)"
fi
if [[ $new != $RPS1 ]]; then
RPS1="$new"
zle .reset-prompt
fi
}
zle -N zle-line-pre-redraw
You might also want to use the zle-keymap-select
hook to catch switching between insert and normal modes.
@okapia Thanks for the snippet, I eventually learned more about zsh
and realised that it is best to write things yourself, so I made custom keybindings and mode indicators for the builtin vi-mode.
I had implemented command, insert and replace mode indicators, but got stuck on visual, because it wouldn't update it from zle-keymap-select
. I then found your comment again, and line-pre-redraw
works perfectly!