Save 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.
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.
Calls 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
本文提供了一种在没有编辑权限的情况下,使用 Vim 保存文件的方法。通过使用 `:w! sudo tee` 命令,可以在不需要 sudo 权限的情况下将修改的内容保存到目标文件中,从而避免了常见的 ‘E212: Can’t open file for writing’ 错误。
1万+

被折叠的 条评论
为什么被折叠?



