I have this in my .vimrc, which is a key mapping to open my hosts file in a new tab:
nnoremap <Leader>hs :tabe /etc/hosts<cr>:set noreadonly<cr>
So now Vim won't bother me about readonly, which is great. However, when I save, I might compulsively hit ⌘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>
But I would only like to do this for this current buffer, as in the hosts file. Some setlocal
magic?