commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
I often forget to sudo before editing a file I don't have write permissions on. When you come to save that file and get the infamous "E212: Can't open file for writing", just issue that vim command in order to save the file without the need to save it to a temp file and then copy it back again.
There is 1 alternative - vote for the best!
Write a file you edited in Vim but that you do not have the permissions to write to (unless you use sudo.) Same as #1204 but without the echo to stdout that I find annoying.
Calls sudo tee like all the other lines, but also automatically reloads the file.
Optionally you can add
command Wq :execute ':W' | :q
command WQ :Wq
to make quitting easier
probably just like 1204, but uses tee as a filter (+ I actually understand how this one works)
If you can do better, submit your command here.
You must be signed in to comment.