10

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?

makansij
  • 9,303
  • 37
  • 105
  • 183
  • Possible duplicate of [How to save as a new file and keep working on the original one in Vim?](https://stackoverflow.com/questions/4980168/how-to-save-as-a-new-file-and-keep-working-on-the-original-one-in-vim) – doelleri Jun 08 '17 at 20:05

2 Answers2

26
:w filename

Will save to filename

Yedidia
  • 969
  • 7
  • 12
9

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
Sedat Kilinc
  • 2,843
  • 1
  • 22
  • 20
vaughnjg
  • 106
  • 1