0

I have set up an autocommand, that makes some changes to the file I'm working on, whenever I save. Everything works nice and dandy, except one thing.

Whenever I save, and press . afterwards, or undo some commands with u, I also undo whatever was done by the the save autocommand!

Is there some way to use execute normal or a similar command, without saving it to the vim history?

  • How does . undo it? What's in the autocommand? One destructive solution (you'd lose all undo history in that buffer from prior to the save) might be setlocal undolevels=-1, run the command(s), setlocal undolevels&. Hopefully someone has something better. – B Layer Dec 18 '18 at 4:56
  • 1
    No and please note, it wouldn't really make sense to disable undo for a specific action. You might be able to use undojoin or disable undo completly for a short time, so that vim "forgets" what it needs to undo. – Christian Brabandt Dec 18 '18 at 7:13
  • Disable undo for a short time sounds fine to me – hgiesel Dec 18 '18 at 14:23
  • That's what my comment is about. Setting 'undolevels' to -1 disables undo. You'll have to live with the possibility of losing any previous undo history for that file, though. – B Layer Dec 18 '18 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.