salcode / ironcode-vim

A Vim Configuration focused on WordPress development and predominantly used on a Mac with Neovim
9 stars 1 forks source link

Add mapping or function for sudo tee write to read only file trick #98

Open salcode opened 7 years ago

salcode commented 7 years ago

See :SudoWrite from https://github.com/tpope/vim-eunuch as one possiblility

for more information about the sudo tee trick see http://www.geekyboy.com/archives/629

salcode commented 7 years ago
" :W sudo saves the file 
" (useful for handling the permission-denied error)
command W w !sudo tee % > /dev/null

from amix/vimrc

salcode commented 6 years ago

or

" Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee > /dev/null %

We had this previously but we had the % before the >, I'm not sure why this removed (or if if also gives the correct behavior).

See this explanation of why this works