Might not be one that 99% of Vim users don't know about, but it's something I use daily and that any Linux+Vim poweruser must know.
(可能不是99%的Vim用户不知道的,但这是我每天使用的东西,任何Linux + Vim poweruser都必须知道。)
Basic command, yet extremely useful.
(基本命令,但非常有用。)
:w !sudo tee %
I often forget to sudo before editing a file I don't have write permissions on.
(在编辑我没有写入权限的文件之前,我经常忘记sudo。)
When I come to save that file and get a permission error, I 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. (当我来保存该文件并获得权限错误时,我只发出该vim命令以保存文件而无需将其保存到临时文件,然后再将其复制回来。)
You obviously have to be on a system with sudo installed and have sudo rights.
(你显然必须在安装了sudo的系统上并拥有sudo权限。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…