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

前端 未结 14 1821
刺人心
刺人心 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 08:02

    If you want to use vim for comparison like in vimdiff, you could do something like this:

    Edit your .vimrc and add:

    nmap  :w !vim -M -R - -c ":vnew % \| windo diffthis"
    

    From there on you will see your changes and can quit the diff view using qall like in vimdiff by pressing F8 in command mode. Replace F8 with any key you like.

    Edit: Added -M to disallow any modification, because it is not save.

提交回复
热议问题