I'm using vim all the time for text editing these days, and have a particular use case: editing a dataset using successive commands. The main problem, as often, is fixing things, ideally rather quickly.
The picture is this:
- a folder with a number of files, e.g. 1000, that need to be cleaned-up / formatted.
- the cleaning process is quite empirical: checking files, seeing things that need to be changed/erased, thinking of the regex to do it, applying it to the dataset.
I am aware, and use, batch commands as described in these lovely answers here and here, and am in awe at the variety of approaches one can have using bufdo, argdo, windo, tabdo, cfdo or lfdo.
The slight issue, however, is that if you try to undo what you just did, by doing bufdo undo, that command has no memory of the previous batch command, and so if one file was changed by the next-to-last (good) regex, but not by the last (misguided) one you applied because their was no match, then the next-to-last (good) one will be undone, alongside all the undo-s you want in all the files that have been changed by the last misguided regex.
However, there's one thing that I haven't yet come across, which is a way to streamline the use of batch commands like bufdo so that:
- it is easy and clean to undo (and would lead to a navigable undo tree for the dataset, as it were, not just for individual files).
- maybe it would be possible to see which files have been changed and where are the modifications (seems like a good use for the quickfix/location lists), so that it is possible to apply the regex, go have a quick look to see if everything is fine, before editing further.
I saw somewhere, sadly I can't find it any more now, that I could use git and commit at each step, but that's very slow compared to a do/undo workflow.
Any ideas? Thanks in advance for any feedback! Not sure if I'm confident yet to actually write such a plugin, but leads on how to start doing that could also be welcome.
:h :earlier,:h 'undofile',:h :diffthis– Matt May 14 '20 at 15:43sedcommands and then committing... I now fantasize about something more advanced, perhaps a bit like @tpope's Fugitive, where you can easily explore the changes, etc. I hope to do it some time in the future. – Jérémie Wenger May 15 '20 at 20:16