I find that with vim, if I try and edit a file which as a normal user I do not have write access with, even if I use sudo, I am unable to write to it, although if I use nano to edit the same file it works.
So for instance if I do:
sudo vim /var/path/to/file.conf
I will get this in the file and not be able to edit that file:
"/var/path/to/file.conf" [readonly]
But if I instead do:
sudo nano /var/path/to/file.conf
It will be able to write to the file, why is this, why does sudo not give vim write access like it does with nano? Is this some sort of bug? Or is this just something which is meant to be? Because it is very annoying.
OS Information:
Description: Ubuntu 15.04
Release: 15.04
Package Information:
vim:
Installed: 2:7.4.488-3ubuntu2
Candidate: 2:7.4.488-3ubuntu2
Version table:
*** 2:7.4.488-3ubuntu2 0
500 http://gb.archive.ubuntu.com/ubuntu/ vivid/main amd64 Packages
100 /var/lib/dpkg/status
mountto see if/var/path/tois located in the output, then post what filesystem type it's on. – NuclearPeon May 07 '15 at 17:02nanocan write to the file, so it's not on a readonly filesystem. – Eliah Kagan May 07 '15 at 17:09viandvim– NuclearPeon May 07 '15 at 17:21sudoto root to edit it (or usesudoedit, which does the same thing behind the scenes on exit). Since the file has write permissions set for root,!isn't needed to save changes when editing it as root. In this question, the user owns the file, but it's (probably) not set writable for anyone, so there's no reason to edit as root (and!is needed even withsudo). – Eliah Kagan May 07 '15 at 17:49