0

When I open up a file remotely using scp (and possibly other protocols), running the undo command (right away, or repeatedly if I've made edits) clears the file. Why does this happen - is it a bug?

My guess is that it is a quirk of how remote editing is implemented - like Vim is actually opening a new local file, and then the first change is to copy all the text of the remote file into the new file.

1
  • There's a manual not-perfect workaround - to exec :set undoreload=0 | edit once file is open. This cut the undo history. I however could not make it exec automatically with autocmd. Tried autocmd EVENT scp://* :set undoreload=0 | edit with EVENT either of BufRead BufEnter BufFilePost.
    – Tag Wint
    Commented Jul 26, 2018 at 17:36

1 Answer 1

1

Vim is using netrw to enable transparent remote file editing, see :h scp.

Try running :set modified? before and after :undo, you will see that a temporary buffer (probably stored locally) is created, then the content is fetched and written by the plugin.

It is not a perfect user experience but I guess it's how it works !

2
  • Is it to be understood as "there's nothing you can do about it" ?
    – Tag Wint
    Commented Jul 26, 2018 at 17:31
  • @TagWint as far as I know, yes. I think you can restore the last version of the file using :e!.
    – LEI
    Commented Jul 26, 2018 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.