I vim somefile.txt often without using sudo. Is it possible to use sudo within an open vim session so you don't have to close the file and reopen? New to Vim and Linux in general so any help is very appreciated. Thank you.
Well seems like I was late to the party. As said you should use :w !sudo tee % to switch to sudo. If you would like to change the permissions of the file so you will not need sudo again you could use :!chmod +w % in command mode with %getting replaced by the filename to change the permissions of the file afterwards, as stated here: How to change file permission from within vi.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With