Vi save as new file
A common question!
In vi
(or vim
), you can save a file with a new name by using the following commands:
:wq!
- This will overwrite the current file with the new name. The!
is important, as it forces the overwrite.:w new_filename
- This will save the current file with the new name, without overwriting the original file. The new file will be created in the same directory as the original file.
For example, if you want to save the current file as new_file.txt
, you can use:
:w new_file.txt
This will save the current file with the new name, without overwriting the original file.
Note: If you want to save the file with a different extension, you can specify the extension along with the new filename. For example:
:w new_file.txt
This will save the file with the .txt
extension.
Also, if you want to save the file in a different directory, you can specify the full path to the new file. For example:
:w /path/to/new_file.txt
This will save the file in the specified directory.