Prevent Vim from updating its undo tree

前端 未结 2 1462
抹茶落季
抹茶落季 2020-12-20 15:19

I have a Vimscript function which is called on BufWritePre to check the integrity of the file. Typically this involves trimming whitespace and checking that th

2条回答
  •  醉梦人生
    2020-12-20 16:02

    If your BufWritePre action is performing manipulations that ultimately leave your file unchanged, you can:

    :wundo 
    

    ...Make changes leaving file the same afterwards...

    :rundo 
    

    This will leave you with your undo history prior to the temporary change, however if the file doesn't match it's previous state you'll get the error File contents changed, cannot use undo info.

    If you wish to make the changes done during the BufWritePre impossible to undo, you can:

    :set noundofile
    

    .. Perform changes ...

    :set undofile
    

    However, this will lose all history prior to the BufWritePre

提交回复
热议问题