Switch to Editing a File with SUDO

Here’s a very useful tip

especially if you administer your own machine and often need to edit root-owned files.

If you’re like me, you forget to open the file with SUDO. Fortunately, Emacs protects you from making a lot of changes that you can’t save by marking the buffer read only but you still have to back out of the file and reopen it with SUDO. With Thaiyar’s tiny Elisp function, you can just push a button and automatically re-open the file with SUDO.

Even if you don’t want to install the code in your config file or you find yourself on someone else’s machine, you can do the same trick manually1.

Footnotes:

1

Although to be fair, it’s not clear that that would be much easier than just starting over.

This entry was posted in General and tagged . Bookmark the permalink.