Vi打開(kāi)某個(gè)文件,保存時(shí)提示只讀時(shí)的簡(jiǎn)單做法
命令行模式下:
輸入
<pre>
:w !sudo tee %
</pre>
再輸入
<pre>
:q!
</pre>
現(xiàn)在已經(jīng)保存并退出了。
用法:
<pre>
:w !sudo tee %
</pre>
:w = Write a file.<br >
!sudo = Call shell sudo command.<br >
tee = The output of the vi/vim write command is redirected using tee.<br >
% = Triggers the use of the current filename.<br >
Simply put, the ‘tee’ command is run as sudo and follows the vi/vim command on the current filename given.