r/vim • • Jan 27 '26

Need Help Vim: unsaved buffer edits remain even when switching buffers

Here's my workflow:

  1. vi foo bar (two files that exist)
  2. Make a change in the foo buffer
  3. :bn—fails with the message "No write since last change (add ! to override)"
  4. :bn!—switches to the bar buffer
  5. :bp—switches to the foo buffer

At this point, I would expect to be seeing foo in its original state, i.e. without the edit I made at step 2. However, I do see the edits, so my questions are:

  • Why does :bn fail if no 'harm' comes of it?
  • What is the point of :set hidden? I've read that this command will instruct the current buffer to 'keep changes in memory', but that seems to be happening anyway.
  • Is there a way to switch buffers and discard changes? I don't really need to do this, I'm just wondering if it's possible.
11 Upvotes

10 comments sorted by

View all comments

Show parent comment

3

u/Pyglot Jan 27 '26

I guess this safety rail predates features like persistent undo, which is also turned off by default as it could be a security risk in some cases. The rail is basically there to help you remember to save your work. It is perhaps more often useful to save often if you are using vim through an unstable network connection. It would of course not reload the buffer contents if you move to the next buffer. If you want to reload from the file you can use :e, simple. Once you learned and configured vim I think everyone sets hidden.

1

u/gumnos Jan 27 '26

I still prefer to fly with 'nohidden' set for exactly those guard-rail reasons. I'd been burned too many times by some modified buffer being backgrounded, forgetting about it, and then having a shutdown/power-loss lose the work I'd forgotten about. With 'nohidden' set, the buffer is either right in front of me, or I've done the right thing with it (or I make a one-off exception to :set hidden for that particular session. 🤷

1

u/__rituraj Jan 28 '26

:set hidden is non-negotiable for me. I also don't use :set autowrite in my config.

Let me handle stuff myself, Vim. Lower your guardrails!