Skip to content

fix(motion): use 'foldedLine' cursorMove unit for j/k over folds#9940

Draft
jaidhyani wants to merge 1 commit intoVSCodeVim:masterfrom
jaidhyani:fix/j-k-foldedline
Draft

fix(motion): use 'foldedLine' cursorMove unit for j/k over folds#9940
jaidhyani wants to merge 1 commit intoVSCodeVim:masterfrom
jaidhyani:fix/j-k-foldedline

Conversation

@jaidhyani
Copy link
Copy Markdown

Summary

Fixes #1004.

j/k in Normal and Visual modes now skip over folded regions without unfolding them, by using the new foldedLine unit added to VS Code's built-in cursorMove command (microsoft/vscode#296106).

Root cause

Previously, MoveDown/MoveUp called position.getDown()/position.getUp(), which returns model-space positions. If the next model line is inside a fold, VS Code interprets that as navigating into a hidden region and auto-unfolds it.

The foldfix workaround (toggling folds off/on around the move) was fragile and had edge cases.

Fix

Adds MoveDownByFoldedLine and MoveUpByFoldedLine motion classes that delegate to cursorMove with by: 'foldedLine'. VS Code core handles fold detection and skipping natively, with no extension-side fold awareness needed.

j/k now always use these motions (except VisualBlock mode, which uses model-line movement intentionally).

Changes

  • src/actions/motion.ts: MoveDownByFoldedLine, MoveUpByFoldedLine classes; updated MoveDown/MoveUp exec actions
  • src/textEditor.ts: added 'foldedLine' to CursorMoveByUnit type
  • package.json: deprecated vim.foldfix setting with a message pointing to this fix

Dependency

Requires the foldedLine unit to be available in the installed VS Code version (microsoft/vscode#296106). Until that ships, the setting vim.foldfix continues to work as a fallback for users on older VS Code versions.

Use VS Code's 'foldedLine' cursorMove unit as the default movement
for j/k, which moves by logical lines while treating each folded
region as a single step.

On VS Code versions without this unit, the command degrades to
standard line movement (no regression). The existing foldfix
workaround is preserved for users on unpatched VS Code.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Folded code unfolds if you spend some (unknown number) of ms idle in a fold

1 participant