Reputation: 16294
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)?
Upvotes: 6
Views: 3641
Reputation: 3086
You can set the name of a buffer with :file
:
:file foo
This doesn't affect the modified
status of the buffer. And you can set the modified
status of a buffer by setting the modified
option:
:setlocal modified
This doesn't affect the name of the buffer (or other attributes, for that matter).
Upvotes: 2
Reputation: 2053
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
Upvotes: 7
Reputation: 1
vi testFile
:w newFilename
:buf testFile
Upvotes: 0