How to save existing file to a new file (save as) in vi / vim

In the vi or vim text editor, you can save the existing file to a new file (also known as “save as”) by using the following steps:

  1. Start vi or vim and open the file that you want to save as a new file.
  2. Enter :w to write (save) the file to disk.
  3. Enter :w newfilename to write (save) the file as a new file named newfilename.

For example, if you want to save the file file1.txt as a new file named file2.txt, you would enter the following commands:

:w file2.txt

This will write (save) the contents of file1.txt to a new file named file2.txt. The original file file1.txt will still exist, but a new copy of the file will now be saved as file2.txt.

Note: If you want to save the file under a new name and close the original file, you can use the :wq command instead. This will write (save) the file to disk and quit vi or vim.

Leave a Comment