I wanted to add set mouse=a to the .vimrc file to add point and click cursor, but the /etc/vim/vimrc file is read-only and won't allow me to edit or delete it. I tried to uninstall and reinstall vim but the .vimrc file remained unchanged.
Additionally when I try to edit it from terminal using

sudo vim /etc/vim/vimrc

it says

Found a swap file by name of 'filename'

Apparently it says I edited the same file twice.

  • this could help askubuntu.com/questions/736182/… and askubuntu.com/questions/883224/…
    – Lety
    May 10, 2019 at 9:59
  • 6
    Note that .vimrc and vimrc are not the same filename
    – wjandrea
    May 10, 2019 at 17:05
  • In this case, the solution is to edit a different file. But when you really do need sudo to edit a file, use sudoedit /etc/whatever instead of sudo vim /etc/whatever. (You'll need to add export EDITOR=/usr/bin/vim to ~/.bashrc.) You get your own .vimrc, not root's, and you can't run privileged shell commands from within vim.
    – AuxTaco
    May 10, 2019 at 20:06

2 Answers 2


User-specific changes like that should go in your personal .vimrc, which should be located in your home directory. If this file doesn’t exist yet you can simply create it. This will add your set line to ~/.vimrc creating this file if necessary:

echo 'set mouse=a' >>~/.vimrc

After that, either restart vim or source the file in a running instance with

:source ~/.vimrc

for the change to take effect.


When vim gives you this warning, it also should give you some options at the bottom:

[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:

Chose "R" if you want to recover whatever changes and "E" if you don't.

If you persistently get this message, delete the swap file named.

More information is found in the error message normally.

  • This is only the case when vim didn't close correctly previously. In this case, he doesn't have permission to edit the file that he opened. If he wanted to edit the file, he should should so with sudo. However, the correct thing to do here is to edit the user config file instead of the system one.
    – Ben
    May 11, 2019 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.