Tuesday, May 27, 2014

How to Open a New Buffer Without Saving the Old One

In Vim, there are many ways to accomplish the same thing. The other day I was trying to open a new buffer without having to save the old one.

I finally figured out how to do it:

:b! {new_file}

The The b! forces the new buffer without saving the old one. At the same time, the old buffer remains in the buffer list. If you save changes to the new buffer, you can go back to the old one by rewinding the buffer list like this:

:rew

The reason the file name is enclosed in curly braces is because the name inside the curly braces is an actual file name and not the name of a buffer. Without the curly braces, the file name becomes a buffer name.

Obviously, there are many other ways to accomplish the same thing. This is just one way to hide the current buffer from view, without modifying it, so that a new buffer can be viewed.

There are so many ways to do essentially the same thing in Vim that I get lost in it all. I'm always looking for a better way.

Ed Abbott

No comments:

Post a Comment