Skip to content

fix: visual mode highlight lingers after put#341

Open
hernancerm wants to merge 1 commit intojeffreytse:masterfrom
hernancerm:fix-hl-lingers-after-put
Open

fix: visual mode highlight lingers after put#341
hernancerm wants to merge 1 commit intojeffreytse:masterfrom
hernancerm:fix-hl-lingers-after-put

Conversation

@hernancerm
Copy link
Copy Markdown

@hernancerm hernancerm commented Apr 4, 2026

Problem

The highlight set after a normal mode p or P lingers. Current master behavior:

hl-lingers-after-put.mp4

Solution

Do not highlight text put with p or P (changes in zvm_vi_put_after and zvm_vi_put_before).

Personally, I don't use highlights for yank/put, so I'm happy with this solution. Nonetheless, I understand if this removal is not desired, I listed alternative solutions below. Let me know if you want me to rework the solution. Behavior from this branch:

hl-lingers-after-put-fixed.mp4

Alternative solutions

  1. Highlight on put but clear on cursor move, like ctrl+y on bindkey -e (emacs) or p/P on bindkey -v (vi).
  2. Highlight on put but with a timer, like yanky.nvim. Perhaps not possible in a zsh plugin.

The alternative solution 1 seems more correct than the solution of this branch, as it would make ZVM match the behavior of bindkey -v insofar highlights, but the cost would be (likely) scattering zvm_highlight clear on every place where the cursor can be moved.

Notes

Related: #329

The videos were recorded using vhs with this tape file so the inputs are exactly the same on both tests:

hl-lingers-after-put.tape
Output hl-lingers-after-put.mp4

Set TypingSpeed 0.5s
Set Shell zsh

Hide
Type@5ms "curl -L raw.githubusercontent.com/jeffreytse/zsh-vi-mode/refs/heads/master/zsh-vi-mode.zsh | source /dev/stdin && clear"
# Type@5ms "curl -L raw.githubusercontent.com/hernancerm/zsh-vi-mode/refs/heads/fix-hl-lingers-after-put/zsh-vi-mode.zsh | source /dev/stdin && clear"
Enter
Sleep 0.2s
Show

# Single hihglight lingers

Sleep 0.5s
Type@0.2s "echo foo"
Ctrl+[
Sleep 0.5s
Type "yiwpibar"
Ctrl+[
Sleep 0.5s
Type "A"
Sleep 0.5s
Backspace 3
Enter

# Multiple hihglights linger

Sleep 0.2s
Type@0.2s "foo bar"
Ctrl+[
Sleep 0.5s
Type "yiwpio"
Ctrl+[
Sleep 0.5s
Type "0yiwPio"
Ctrl+[
Sleep 0.5s
Type "A baz"
Ctrl+[
Sleep 0.5s
Type "yiwpio"
Ctrl+[
Sleep 0.5s
Type@0.2s "Iecho "
Enter

Sleep 0.5s

Thanks for the plugin!

@hernancerm hernancerm force-pushed the fix-hl-lingers-after-put branch from b5c5c9b to be23742 Compare April 15, 2026 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant