Vim icon indicating copy to clipboard operation
Vim copied to clipboard

perf: optimize movement commands with count to execute instantly

Open borjao-dev opened this issue 1 year ago • 0 comments

What this PR does / why we need it:

Previously, movement commands with counts (e.g., 20j, 50k) would loop through each individual movement, causing visible lag and poor performance. This made the extension feel sluggish compared to native Vim, especially with large count values.

This PR optimizes the four basic movement commands (j, k, h, l) by overriding execActionWithCount to calculate the target position directly instead of looping:

  • MoveDown (j): Calculates target line as current + count
  • MoveUp (k): Calculates target line as current - count
  • MoveLeft (h): Calculates target character with surrogate pair handling
  • MoveRight (l): Calculates target character with surrogate pair handling

All special cases are preserved:

  • Interactive window history navigation
  • Foldfix mode compatibility
  • Operator context (d20j, y10k work correctly)
  • Visual mode selections
  • Column preservation for vertical movements
  • Boundary checks (don't exceed document limits)

Which issue(s) this PR fixes

Fixes #8557

Special notes for your reviewer:

Additionally fixed build issues encountered during development:

  • Updated test/index.ts to use new glob API (async/await pattern)
  • Added skipLibCheck to tsconfig.json for node_modules compatibility
  • Added ignoreDeprecations: "6.0" to silence baseUrl warning

The optimization provides instant cursor movement for any count value, matching native Vim's performance. Tested on Windows 10 and Ubuntu 22.04 with various count values (1-200) in Normal, Visual, and Operator-pending modes.

Note:

Those changes were made by GitHub Copilot, using Claude Sonnet 4.5 agent

borjao-dev avatar Oct 27 '25 03:10 borjao-dev