dmacro.vim
dmacro.vim copied to clipboard
Undo in a single operation
Actions performed in Vim's builtin macro playback can be undone as if they were a single edit (one u for each macro playback). Currently, dmacro-recorded macros do not match this behavior, which is a bit jarring. If dmacro were to prevent individual actions in a macro from going into the undo history and instead make the whole macro playback an undoable item, it would make it a lot more consistent with vim's built-in functionality.
I understand the request, and I agree that this behavior would be better.
If there is an API that allows access to the undo history, it should be possible to implement this. Do you know of any such API?
I looked around, and I found some info in the manual about undo blocks (:h undo-blocks). Seems like it could be what we're looking for, if not it's related. I bet looking in to how macros work would offer some more insight. There's also this bit of _editor.lua that I found while searching around. It uses some commands with vim.api.nvim_command() to do what looks like some undo history manipulation. Might be useful. I was able to find this by doing gd on vim.api and looking through api.lua file that it brought me to. If this isn't what we want, there could be some other insights hiding in the .lua files for various `vim.*' objects.
Hope this helps!
PS: if you need to look into the vim undo history to see what's going on, you might find the undotree plugin helpful.