There are times when I want to test changes to a file before I overwrite the original. Is there any way I can save a file being edited to a new file?
You can give a parameter to the
:write command to save to a different file.
For example to save the current buffer to
However, keep in mind that this does not switch your buffer to that other file.
So if you keep editing and do just
:w, that will save to the current file, not to the other one. To switch to the other file, use the
To do this one step, save to another file and switch to it, use the
Vim has a "backup mode" that can be enabled by
:set backup or
:set patchmode. In that mode, Vim automatically keeps a backup copy of files that you write.
For example, if you issue
:set patchmode=.orig, and you edit an existing file
somefile.txt, then when you issue
:w normally, Vim will keep a copy of the old file as
somefile.txt.orig and save the new contents as
Yes, there is a way.
Simply specify a newfilepath at the
:w command -