The title about covers it: I know that
w! newFileName
will write to newFileName while continuing to edit the original file.
But I want to
Thanks.
The sav
command should do what you want.
Reference:
:sav[eas][!] [++opt] {file}
Save the current buffer under the name
{file}
and set the filename of the current buffer to{file}
.The previous name is used for the alternate file name. The
[!]
is needed to overwrite an existing file. When'filetype'
is empty filetype detection is done with the new name, before the file is written. When the write was successful'readonly'
is reset.
Another way of accomplishing this is to :w newName
and then CTRL-^
(which is the same as CTRL-6
) to switch to the new name.
When you :w
to a new name, it sets that as the "alternate" file name, and CTRL-^
switches that to primary. See :help alternate
for more information on this. Also useful is the :f newName
which just renames the buffer (saving the old name as the alternate) without saving anything.
I like this a little better than the :saveas
command because it doesn't introduce a new command, only a new shortcut, which is occasionally useful in other contexts as well. It's always surprising to me that switching to the new name is not the default behavior of :w newName
whenever I encounter it; it's hard for me to think of a use case where the existing behavior would be preferable.
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