A lot of times, I end up accidentally closing a file with :wq when I only want to do :w. Since I work with multiple tabs and windows, the buffer is still there and I can open it with :ls followed by :b <number>. However, my previous changes are lost and I cannot undo anymore. Is there any way to set up vim so that it remembers the undo tree of unclosed buffers?If that is not possible, a way to make vim confirm before quitting on :wq is also OK.
Any way to retrieve lost undo tree after closing window (but buffer is still open)
undo redo;quit
What is most likely happening in your case is that the buffer is automatically unloaded because you don't have the option 'hidden' enabled.This option not only resolves the issue you reported, but is also required when you want to navigate between buffers without being forced to write the changes before doing so. Personally, I can't imagine working in Vim without it.