How do I save the current buffer to a different filename and continue editing under the new name?
Answer
:saveas {newname}
Explanation
:saveas saves the buffer to a new file and redirects all future :w commands to write to that new filename — making it the true "Save As" command in Vim. This is different from :w newname (which writes a copy but keeps the original as the buffer's file) or :file newname (which renames the buffer without saving).
How it works
:saveas newfile.txt— write current buffer tonewfile.txtand set it as the new filename- After
:saveas, pressing:wwrites to the new filename, not the original - The original file is not modified or deleted
- If the new filename already exists, Vim raises an error (use
:saveas! newnameto overwrite)
Example
You have draft.md open. You want to save it as final.md and keep editing under that name:
:saveas final.md
Now the buffer is associated with final.md. Any subsequent :w writes to final.md. The original draft.md remains unchanged.
Tips
- Compare with
:w newname— this writes a copy but the buffer stays tied to the original file - Compare with
:file newname— this renames the buffer in memory but does not save to disk - Use
:saveas!to overwrite an existing file without confirmation - After
:saveas, run:!rm old-file.txtfrom within Vim to clean up the original if needed