Can I see changes before I save my file in Vim?

前端 未结 14 1781
刺人心
刺人心 2020-12-07 07:33

I use Vim. I open a file. I edit it and I want to see what I\'ve edited before I save it.

How can I do this in Vim?

14条回答
  •  死守一世寂寞
    2020-12-07 07:53

    I can recommend the histwin plugin.

    While it doesn't diff to the current saved version of the file (like the other answers), it can vimdiff changes since you started edting, and even replay your changes in order. The difference shows if you save intermediately.

    Additionally, it displays a list of all undo history branches and allows you to switch or diff between them.

    PS: While the plugin doesn't automatically track moments in the edit history since every file change, you can explicitly "tag" the moment when you save the file such that you can later vimdiff with it, if you want that. Maybe this could be automated?

提交回复
热议问题