Created
June 16, 2009 06:11
-
-
Save nclark/130562 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do you ever try to edit some shit, like /etc/hosts or some apache | |
config, and forget to sudo? and then you have to f-ing exit vim and | |
re-run the command with sudo out in front of it? i hate that shit. | |
so here's a way to deal with that. | |
1. install the sudo.vim plugin | |
mkdir -p ~/.vim/plugin && cd ~/.vim/plugin \ | |
&& curl -o sudo.vim \ | |
'http://www.vim.org/scripts/download_script.php?src_id=3477' | |
2. expire sudo timestamp (for the purposes of demonstration) | |
% sudo -k | |
3. edit a file you can't write | |
% vi /etc/hosts | |
in your vi session, it will tell you that it's read only. | |
"/etc/hosts" [readonly] 6575L, 205583C | |
if you're at all like me, you generally miss that warning, and don't | |
realize until you start typing and then see this in red: | |
-- INSERT -- W10: Warning: Changing a readonly file | |
oh shit, now i have to fucking exit, then re-edit the file w/sudo. | |
shit on that. | |
5. but now that you're rolling with this plugin, just make your | |
changes. when you're done, type this: | |
:wq! sudo:% | |
'%' completes to the pathname for the file you're editing. you will | |
be prompted for your password by sudo. enter that shit. | |
DUNZO. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment