-5

How can I circumvent the errors, such as E212 and E13, in the commands?

:'a,'bw set_question_tags.php
:'a,'bw >> set_question_tags.php

In some cases, even with Pavel's command:

"create_a_file_and_save.php" E212: Can't open file for writing
hhh
  • 50,788
  • 62
  • 179
  • 282
  • 2
    What does sudo tag have to do with it? I don't see any problems with access; did I misunderstood something? – P Shved Aug 29 '09 at 11:57
  • You mentioned the permissions of the directory but not the user you're doing this under. While we could assume 'root', why assume when you can tell us? – Otis Sep 04 '09 at 20:51
  • 1
    you'd better make it a different question. Because it indeed is a different question... – P Shved Sep 04 '09 at 20:53
  • @Otis: The user is not root who did the command. – hhh Sep 04 '09 at 20:54
  • 2
    to create files in the directory, you should have write permissions for it. the useer ther executes vim doesn't, I suppose... – P Shved Sep 04 '09 at 21:02
  • @Pavel: you are on the right tracks. I try to find the way to switch to the appropriate user and save a new file. The problem is that I should do something like: :!su root back-to-vim 'a,'bw! new_file.php – hhh Sep 04 '09 at 21:16

2 Answers2

2

(Sorry, since the OP completely changed his question, my answer stopped making sense)

So, you basically need a command that appends text to the file even if it doesn't exist? Try using exclamation mark:

:'a,'bw! set_question_tags.php
:'a,'bw!>> set_question_tags.php
P Shved
  • 96,026
  • 17
  • 121
  • 165
  • It is not different, I rollbacked it to the original adding only more relevant information. – hhh Sep 04 '09 at 21:01
  • You see, this site is not about solving your problems. It is about answering questions. So if your problem is not solved after question is answered, you're to ask another one instead of editing the original one. – P Shved Sep 05 '09 at 03:24
0

The question consisted of two parts, the exclamation mark solved some problems but some needed sudo rights. Since I have changed my system, I cannot verify things anymore. I will here however answer the question because now it seems clear to me.

1. E212 problem solved

:'a,'bw! !sudo tee save_to_new_file_with_different_user.php

:'a,'bw! !sudo tee -a append_to_a_file_with_different_user.php

2. For E13 problem, please, see Pavel Shved's answer.

This answer does not address the sudo part in my inital question that is How can I circumvent the errors, such as E212 and E13, in the commands? When I found it, I had to change the acceptance of the question because it did not address it, only a part.

3. About Sudo problem

The saver clearly had no permission to some files because s/he was unable to save without sudo and not solved just by ! -mark. Either the file was made by sudo or the another user had not shared the file to saver, the reason for E212 from manuals:

                                                   *E190* *E212*  

Cannot open "{filename}" for writing Can't open file for writing

For some reason the file you are writing to cannot be created or overwritten. The reason could be that you do not have permission to write in the directory or the file name is not valid.

The E13 problem had nothing do with E212 error, from Vim's manuals:

                                                    *E13* *E189*  

File exists > (add ! to override) "{filename}" exists (add ! to override)

You are protected from accidentally overwriting a file. When you want to write anyway, use the same command, but add a "!" just after the command. Example: > :w /tmp/test changes to: > :w! /tmp/test

hhh
  • 50,788
  • 62
  • 179
  • 282