One thing that every admin (agile or not, although we hope agile) needs to do is use vi. Or vim for the slightly more civilized, which I am encouraging adoption therof by calling this the vim tip of the day in lieu of the vi tip of the day.
If you are reading this, and are thinking, “what is vim?” then you might want to skip this. If you read this and are thinking, “I dream in regex and I just can’t wait” then you might be a little let down. But for those of us that are left, here is a handy little vim tip for you.
Often I find myself looking running
sudo vim /etc/hosts
which is fine and dandy. But more often than not, I forget to sudo. When that happens and you are just about to save your work you are greeted with a “Can’t open file for writing” message. Dang! At this point you probably copy out the changes you made, exit the file, and reopen the file using sudo. All the while you are wondering, “surely there is a better way.”
Well there is.
:w !sudo tee % >/dev/null
Type this into vim and it will save your work just as if you were running vim using sudo.
I am not sure if this will be a regular feature, but I am going to try and cook up some other vim tips and share them with you.