sudo vim can't write file

terminal

spotify.desktop can be written by root owner, so, I use $ sudo vim spotify.desktop to edit it, but, find that I can't save the modifications. The error is "only readable". Does anybody know how to solve it? Thanks in advance.


Solution 1:

I believe the proper way to do this is with the sudoedit spotify.desktop command, assuming you have the following in your .bashrc:

export VISUAL=vim
export EDITOR=$VISUAL

See this accepted answer for the differences between sudo vim and sudoedit.

Solution 2:

You cannot write that file because it is on another filesystem that is read-only.

Check mount | grep spotify, you'll see that it's "ro" mounted. Even root cannot write this.

You'd need to edit the file(s) where they are mounted from and writeable on your disk. In this case it is a snap archive, which you'd even need to unsquash first.

Are you sure the desktop file you are looking for is not rather in /var/lib/snapd/desktop/applications/ ?