Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save file under different name in vi

Tags:

vi

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?

like image 530
makansij Avatar asked Jun 08 '17 20:06

makansij


People also ask

How do I rename a file in vi?

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.

How do I save a file in vim as a new name?

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.

What does ZZ do in vi?

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.

What are the 2 modes of vi editor?

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 .


2 Answers

:w filename

Will save to filename

like image 60
Yedidia Avatar answered Sep 20 '22 11:09

Yedidia


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
like image 21
vaughnjg Avatar answered Sep 20 '22 11:09

vaughnjg