Here’s a nifty bit of Elisp to make opening a file as root a bit easier:
#Emacs Tip of the day: Opening a file as root (screenshot attached).
If you `M-x uf/sudo-edit`, it will ask for a filename and open it as root. If you `C-u M-x uf/sudo-edit`, it will reopen the file visited by the current buffer as root. pic.twitter.com/9KmgR8g02A
— Vedang Manerikar (fosstodon.org/vedang) (@vedang) January 12, 2023
When I first saw it, the idea seemed familiar and it is, in fact, very similar to some code offered by Bozhidar Batsov. I (very) slightly prefer Batsov’s version because it handles my most frequent use case by default. Most of the time when I want to edit a root file, I forget to open it with the sudo
tag and have to abort the edit and reopen it. Batsov’s version handles this automatically.