In a Linux environment, if you use the Vi/vim command to edit files without modifying permissions directly, the user will be prompted to save when saved, and the general solution is to turn off the file again with sudo permission to open the file Edit and save (if the user has sudo permission). In fact, in the Vi/vim mode through a number of simple commands, you can not close the current file to achieve the purpose of saving the file:
Enter command:%! sudo tee% >/dev/null
Enter sudo password by prompt
Enter "L" (Load File)
Input: Q command exit
About "%! sudo tee% >/dev/null "This order is described as follows:
% #VI/vim edited file contents
! #管道
sudo #以root权限操作
Tee #将标准输入 (that is, the contents of the currently edited file coming through the pipe) to the standard output, while writing to the specified file (that is, Vi/vim the currently edited file)
% #VI files edited by/vim
>/dev/null #将标准输出重定向到/dev/null (no output display)