Skip to content

add optional clearing of cursorword highlight on leave#35

Open
satorunooshie wants to merge 1 commit intoitchyny:masterfrom
satorunooshie:master
Open

add optional clearing of cursorword highlight on leave#35
satorunooshie wants to merge 1 commit intoitchyny:masterfrom
satorunooshie:master

Conversation

@satorunooshie
Copy link
Copy Markdown

Summary

This PR adds an optional behavior to clear CursorWord highlights when
leaving a window or buffer, and refactors the highlight-clear logic into a
reusable function.

Motivation

When moving between windows or buffers, cursorword highlights can remain
visible in the window you just left, which can be visually noisy. Some users
prefer that highlights are cleared as soon as they leave a window, while
others prefer the current behavior, so this should be configurable.

Changes

  • Add cursorword#clear() in autoload/cursorword.vim to:

    • Delete the current window's CursorWord match (if present).
    • Reset w:cursorword_match and w:cursorword_state.
  • Refactor the timer-based cursorword#cursormoved() to call
    cursorword#clear() instead of duplicating the clear logic inline, keeping
    its behavior identical to before.

  • Add a new global option g:cursorword_clear_on_leave:

    • When non-zero, cursorword#clear() is called on WinLeave,BufLeave.
    • When unset or zero, WinLeave,BufLeave does nothing and the original
      behavior is preserved.
  • Keep the non-timer cursorword#cursormoved() implementation as
    call cursorword#matchadd() so there is no behavioral change when timers
    or g:cursorword_delay disable the timer path.

Usage

To enable clearing highlights when leaving a window or buffer:

let g:cursorword_clear_on_leave = 1

Without this setting, cursorword behaves exactly as before.

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