I open a new, unsaved buffer in Vim with :enew
. My status line says "[No Name]".
If I do :w /tmp/foo
, the status line changes to "/tmp/foo".
How can I write the contents to a file while keeping the buffer unsaved (unmodified, unnamed)?
Close buffer named Name (as shown by :ls ). Assuming the default backslash leader key, you can also press \bd to close (delete) the buffer in the current window (same as :Bclose ).
The :wa and :xa commands only write a file when its buffer has been changed. By contrast, the :w command always writes the current buffer to its file (use :update to save the current buffer only if it has been changed). Warning: If you enter :qa! , Vim will discard all changes without asking "are you sure?".
For example, when you start VIM without supplying a file for it to open, VIM starts with an empty buffer. If you want to save the changes to that buffer, then you have to tell VIM what file to write those changes to. So again, a buffer resides in memory.
If you want to have the buffer unsaved, but save the contents to another file, you can try this trick:
:%!tee new-filename
This will work only on a UNIX system as it executes external tee
command.
On the other hand, if you want to name the buffer, but leave it unsaved, try this:
:file new-filename
To learn more, read
:help :file_f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With