Vim Error 'E212: Cannot open file for writing', when trying to create new files outside of home dir
Solution 1
Thanks for the answers. I ended up solving the issue by changing the the folder owner to myself, using chown
. This resulted in me not having to use sudo everytime I wanted to create/edit a file.
Solution 2
Sorry I am not able to comment yet. Try to run command :sudo -s
by this you will login as root. Then, I guess, you can do whatever work you want to.
Solution 3
You need to run vim as root.
sudo vim /var/www/file
Related videos on Youtube
Jakeimo
Updated on September 18, 2022Comments
-
Jakeimo over 1 year
I am running Wheezy Debian. When I try to create a new file in a directory other than my home directory, such as
/var/www
, I get the following error in vim:E212: Cannot open file for writing.
I assume this is because I do not have the correct privileges to create files outside of my home directory?
My user account is in the sudoers file with
(ALL=(ALL) ALL)
, and I have administrator access.I'm aware of tricks such as
:w !sudo tee %
, however this still results in a readonly file.What am I missing here?
-
terdon almost 10 yearsPlease don't do that. There's a reason why those directories are protected. You should use sudo every time you want to create a file, it's not that hard and it's worth it to keep your system secure.