Skip to content

fix(macos): make Vim mode's operators, motions, paste and marks match Vim - #4347

Merged
datlechin merged 13 commits into
mainfrom
fix/macos-vim-engine-bugs
Nov 19, 2026
Merged

datlechin merged 13 commits into
mainfrom
fix/macos-vim-engine-bugs

Conversation

@datlechin

@datlechin datlechin commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Vim mode now does what vim -u NONE does for each of these. Found while porting the engine to Windows (#4338); the Windows engine gets the same fixes.

  • Escape, leaving the command line, a failed motion and any key that is not a motion end the whole pending command: df<Esc>w, dfzw, d;w, d/<Esc>w, dxw and "a<Esc>yw no longer delete or write a register. A count or register a command does not use is dropped (3max deletes one character).
  • Every motion takes a pending operator: d% c% y%, dn d*, d} d), d]], dH dL, d'a (linewise), d`a, 2d/pattern Enter, d+ d-. A motion that finds nothing ends the command.
  • Operators follow :help exclusive (db at a line start keeps the line break, d} from the indent takes whole lines), dW stops at the line end as dw does, cw changes to the word's end, cj and cip leave a line to type on, dF and dT are exclusive, >w shifts the whole line, dj on the last line deletes nothing.
  • "a2p pastes register a twice; a counted P keeps each copy whole. A linewise paste lands on the first non-blank, yyp on a last line with no line break adds it, and a paste over several lines lands at its start.
  • Marks keep their line and column as Vim's do: lines typed, pasted or undone above a mark move it, a join carries it, deleting its line removes it, and the column survives a line that shrinks. The editor reports every edit with the undo manager's direction (SQLEditorCoordinator, willReplaceContentsIn); an edit journal keeps the positions from before each edit, so an undo or redo that reverses edits (one at a time or folded, as an undo step can join them) puts them back, as Vim's undo restores its marks. A tab switch keeps all of it.
  • After viw the next motion extends the selection; vip is Visual Line. Visual mode takes "x, and p keeps the replaced text in the unnamed register while P does not.
  • a and p on an empty line stay on it.
  • ip and ap take whole lines, so ip on the last paragraph keeps its last character; a line of only blanks ends a paragraph, and on blank lines they take the blank lines.
  • Word motions, iw and * class a character by its first scalar (VimWordScanner, shared by the adapter and the test mock), so w, e, b step over ❤️.
  • Enter, + and - go to the first non-blank of the next or previous line; {N}%, 2H, 2L, 2* and 2]] take their counts.
  • Windows (windows/src/TablePro.Editor.Model/Vim): the same behaviors where the port still had them; 0017 updated.
  • Tests changed on purpose: VimEngineTextObjectsTests.dIPDeletesInnerParagraph (linewise dip), VimEngineOperatorsTests.cWChangesWord (cw keeps the space), VimTextBufferAdapterLineIndexTests.sectionForwardStaysLinear (]] with no section lands on the last line's start); on Windows the matching DIPDeletesInnerParagraph and CWChangesWord, and two mark tests in VimCommandEdgeTests (a mark keeps its column when text is typed before it on its line).

Test plan

  • New cases in the Vim suites (apple/TableProTests/Core/Vim) for each item; each expectation was measured in Vim 9.1 with vim -u NONE.
  • SQLEditorVimMarksTests: in a real editor with Vim on, a line typed above a mark moves it and undo moves it back.
  • verify.sh test on every Vim suite and the editor coordinator suites; verify.sh lint on each changed file.
  • Windows: verify.sh --platform windows test TablePro.Editor.Model.Tests.
  • Docs: docs(features): document Vim motions after operators and how marks move docs#251 (draft) for the Vim mode page.

@datlechin
datlechin enabled auto-merge (squash) November 19, 2026 12:22
@datlechin
datlechin merged commit e4a09da into main Nov 19, 2026
86 of 94 checks passed
@datlechin
datlechin deleted the fix/macos-vim-engine-bugs branch November 20, 2026 14:22
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