[vim/vim] Implementing substitution preview (Discussion #19624)

15 views
Skip to first unread message

Foxe Chen

unread,
Mar 9, 2026, 10:27:28 PM (3 days ago) Mar 9
to vim/vim, Subscribed

I've been thinking on how to do this for the past couple of days, and here are my thoughts

Originally I was going to do this something like 'inccommand' or :command-preview in Neovim, however I have been thinking of a more generalized API that substitution preview would be based upon:

Essentially a transaction on a buffer can be started, creating a sort of copy-on-write (like in filesystems) behaviour for the buffer. If a line is changed, then the underlying data block storing the line is not modified in place, instead a new copy is created. Any reads on the buffer (:write, getline(), ...) would not be aware of the changes and use the original buffer contents before the transaction. However when drawing the buffer in the window, the changes will be displayed. When the transaction is "committed" finally, then the changes are actually merged with the buffer, and if the transaction is "discarded", then the changes are discarded.

During a transaction:

  • b:changedtick is not modified
  • Any changes do not affect the undo system

There would also be the risk of a transaction on a buffer not being matched with a "commit" or "discard" due to something like a bug in a plugin. The obvious solution to this would to be add a warning before exiting Vim, indicating that a transaction is ongoing.

There is also the risk of Vim crashing during a transaction, the solution to this would be make the buffer transaction feature be part of how Vim stores buffer text internally (memline.c/memfile.c), so it is part of the swap file.

There would also need to be feature to allow adding a callback as a User command is typed, however that shouldn't be too complex.

This explanation is definitely missing a lot of other things/nuances that I have been thinking of as well, and I may just be overcomplicating things a lot... However this is the gist of what I have thought of so far.


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/19624@github.com>

Maxim Kim

unread,
Mar 9, 2026, 11:22:09 PM (3 days ago) Mar 9
to vim/vim, Subscribed

Something like traces.vim would be awesome to have built-in.

https://github.com/markonm/traces.vim


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/19624/comments/16061375@github.com>

Foxe Chen

unread,
Mar 11, 2026, 8:49:32 PM (16 hours ago) Mar 11
to vim/vim, Subscribed

Closed #19624 as resolved.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/repo-discussions/19624/discussion_event/2455553@github.com>

Reply all
Reply to author
Forward
0 new messages