Save a file you edited in VIM without the needed permissions (no echo) Address: http://www.commandlinefu.com/commands/view/5147/save-a-file-you-edited-in-vim-without-the-needed-permissions-no-echoSave a file you edited in VIM without the needed permissions (no echo)
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.
You don't need to use sudo to save a file that requires editing permission and save a file that you are writing. You find that you have no permission to write (unless you use SUDO ), use the following command to solve the problem:
The following command explains how to write a file to a command. Tee reads stdin and writes it to stdout and the file. Because sudo is used, you can write it back to the file, for personal testing, you do not need to>/dev/null. You can also directly stdout to the file: W! Sudo tee>/dev/null % Article Comments: W! Sudo tee % save
A file you edited in VIM without the needed permissions
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
Temp File and then copy it back again.
Command W: Execute ': silent W! Sudo tee %>/dev/null' |: Edit!
Save a file you edited in VIM without the needed permissions
CILS sudo tee like all the other lines, but also automatically reloads the file.
Optionally you can add
Command WQ: Execute ': W' |: Q
And
Command WQ: WQ
To make quitting easier