我的 .vimrc 中有这个,这是在新选项卡中打开主机文件的键映射:
nnoremap <Leader>hs :tabe /etc/hosts<cr>:set noreadonly<cr>
所以现在 Vim 不会因为 readonly 问题困扰我,这很棒。但是,当我保存时,我可能会强制击中⌘</kbd>s or :w
. I would like to overwrite both (are they the same?) calls to call our normal NVW (nasty Vim way) to write as sudo:
:w !sudo tee % >/dev/null<cr>
但我只想对这个当前缓冲区执行此操作,就像在 hosts 文件中一样。有setlocal
什么魔法?