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

前端 未结 14 1765
刺人心
刺人心 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:52

    Source the following and use :DIFF command

    function! s:diff()
        let tmpa = tempname()
        let tmpb = tempname()
        earlier 100h
        exec 'w '.tmpa
        later 100h
        exec 'w '.tmpb
        update
        exec 'tabnew '.tmpa
        diffthis
        vert split
        exec 'edit '.tmpb
        diffthis
    endfunction
    command! -nargs=0 DIFF call diff()
    

提交回复
热议问题