Sometimes I open a file that needs admin permissions to be written but I forget to type sudo, so I open it with my regular user. (I usually use nano, but the question can be extended to other console editors, eg: vim)
Then I work on this file and when I try to save it I get the permission error for not being admin.
What I usually do then is either exit without saving, opening again with sudo and redoing the job.
I tried cutting all the file content and putting it to the clipboard hoping that I can exit the file, open it again with sudo and I can paste it. But when exiting nano it appears that whatever was cut and put in the clipboard is lost.
Forgetting to open a file with sudo is probably something that happens from time to time to everybody (at least to me). So I'm wondering if there's a way of saving the changes or saving the file as an admin even if nano was open by a regular user (typing the admin's password)