‹ BackHN Continuity

Thread

On caring for user data: NeoVim caused Vim undo files to be deleted

384 points · 346 comments · jandeboevrie

  1. justinmk · · focus · HN ↗
    Vim undofile "data loss" happens because Vim (VIM!) will reset the undofile will reset the undofile if an external tool (git, nano) changed the file while Vim is not running.

    Go ahead, try it:

        # Make some edits, then exit vim (remember to exit).
        vim --clean +'set undofile' foo.txt
    
        # Edit the same file with non-vim; save the changes.
        nano foo.txt
    
        # Open the file again and try "u". Then post on bluesky about Vim's "duty of care".
        vim --clean +'set undofile' foo.txt
    
    
    This is documented at `:help undo-persistence`.
    1. endospore · · focus · HN ↗
      And vim will also reset it while "recover"ing the last unsaved changes. I believe no user relies on it to actually persist the history of a file. If someone is doing that whether in nvim or vim I'd seriously advise you to use a real VCS repo instead.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.