I am frequently editting a file in vi
and I want to save it under a different name than the name that I opened it under.
I have tried saving like this: :w >> new_file_name
but I ALWAYS get E212: Can't open file for writing
.
What is the correct way around this?
Navigate to the file, press R , and change the name. Press Enter to edit the file. There's a caveat though: the original buffer remains in the list of buffers.
It's time to open up the command mode of Vim by pressing the “:” key. Now, press the “w” key from the keyword followed by the space key and the new name of a file. Tap “Enter” to execute this command on Vim. Now, the exact copy of the same file has been created in the home folder with a new filename.
Another way to save your changes and exit out of VI is the ZZ command. When in command mode, type ZZ and it will do the equivalent of :wq. If any changes were made to the file, it will be saved. This is the easiest way to leave the editor, with only two keystrokes.
Two modes of operation in vi are entry mode and command mode. You use entry mode to type text into a file, while command mode is used to type commands that perform specific vi functions. Command mode is the default mode for vi .
:w filename
Will save to filename
Enter :w filename
in vi command mode, like @Yedidia said...
I think you are confusing writing terminal output to a file.
Which would be following command in order to create or overwrite text.txt
:
action > text.txt
and in order to append the output of an command to text.txt would be:
action >> text.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With