Skip to content

Fix broken vim ex commands (:w, :wq, :q!, line jumps) - #739

Merged
mehmetozguldev merged 4 commits into
athasdev:mainfrom
IzonIcy:fix-vim-ex-commands
Aug 25, 2026
Merged

mehmetozguldev merged 4 commits into
athasdev:mainfrom
IzonIcy:fix-vim-ex-commands

Conversation

@IzonIcy

@IzonIcy IzonIcy commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Fix broken vim ex commands (:w, :wq, :q!, line jumps)

Problem

The vim ex commands in src/features/vim/stores/vim-commands.ts dispatched window events that no code in the repo listens to:

  • :w dispatched a vim-save CustomEvent with zero listeners, so it silently did nothing.
  • :wq / :x dispatched the same dead event, then closed the buffer on a setTimeout(100) timer. The timer races the save that never happens; on a dirty buffer this pops an unsaved-changes dialog instead of saving and closing.
  • :{line} dispatched vim-goto-line, also with no listener, so jumping to a line number did nothing.
  • :q! called closeBuffer(), exactly like :q, so force-quit still showed the save confirmation on dirty buffers.

Fix

  • :w now calls useEditorAppStore.getState().actions.handleSave() directly, the same action the editor save shortcut uses.
  • :wq / :x await the save before closing, which also removes the setTimeout race.
  • :q! now uses the existing closeBufferForce() action to discard changes without prompting.
  • :{line} dispatches menu-go-to-line, the event the editor surface already listens to for go-to-line requests from search results, diagnostics, the debugger, and the status bar.

Also removes a dead trailing comment left after an autocomplete helper.

Testing

Adds src/features/vim/tests/vim-commands.test.ts with regression tests for all five commands (written failing-first). Full suite passes: 358 files, 1756 tests.

Note: bun check reports pre-existing cargo fmt diffs in crates/tooling on a clean checkout of main as well (stable rustfmt cannot apply the nightly-only options in rustfmt.toml). The TypeScript checks, lint, architecture checks, and tests all pass on this branch.

I agree to the Contributor License and Feedback Agreement.

The :w command dispatched a vim-save window event that had no listener,
so saving through ex commands never worked. :wq also relied on that dead
event and then closed the buffer on a 100ms timer, which raced the save
and could pop an unsaved-changes prompt right after a write. :{line}
dispatched vim-goto-line, another event without a listener, so jumping
to a line number did nothing. :q! called the same close path as :q and
still showed the confirmation prompt for dirty buffers.

:w now calls the same handleSave action as the editor save shortcut.
:wq awaits the save before closing, removing the timer race. :q! uses
the force-close action to discard changes without prompting. :{line}
dispatches menu-go-to-line, the event the editor already listens to for
go-to-line requests from search, diagnostics, and other surfaces.

Adds regression tests for all five commands under src/features/vim/tests.
Copilot AI lite review requested due to automatic review settings August 23, 2026 00:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Return the active save result and capture the originating buffer before
awaiting it. Failed or canceled writes now leave that buffer open, and tab
switches cannot redirect the close to another buffer.
@mehmetozguldev
mehmetozguldev self-requested a review August 25, 2026 13:51
@mehmetozguldev
mehmetozguldev merged commit f2fd43f into athasdev:main Aug 25, 2026
@IzonIcy
IzonIcy deleted the fix-vim-ex-commands branch August 30, 2026 21:32
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.

3 participants