Skip to content

Optimize showing hints in visual mode #2416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dtor
Copy link
Contributor

@dtor dtor commented Jul 6, 2025

These 2 changes optimize showing hint text in visual mode by avoiding hooking "CursorMoved" events unless absolutely needed and refactoring code to not require as many checks.

This should help with issue #711 (although more changes are needed to fully fix it).

dtor added 2 commits July 5, 2025 22:48
Prevent redundant recreation of the virtual text hint for selection
shortcuts by checking if an existing extmark is already in the correct
position. This avoids unnecessary API calls and improves performance.
Triggering autocommands on CursorMove event is pretty expensive,
especially if they are not buffer-local, as they are triggered very
often. Additionally the command itself is more expensive as it has to
test whether it was triggered for the right buffer and right mode.

Refactor the visual mode autocommands to be created for particular
buffer when entering visual mode, and cleaned up upon exiting visual
mode:

- there is only global "ModeChanged" autocommand that triggers when
  entering visual mode
- a new autocommand group is created when entering visual mode and
  "CursorMoved", second "ModeChanged", and "BufLeave" autocommands are
  made buffer-local and moved there
- the new group is deleted when leaving visual mode or leaving buffer

Making most of the autocommands local to the buffer reduces unnecessary
checks and improves the overall efficiency of hint display.
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