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:
- Start
viorvimand open the file that you want to save as a new file. - Enter
:wto write (save) the file to disk. - Enter
:w newfilenameto write (save) the file as a new file namednewfilename.
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.