I am using NeoVim v0.4.3. This is the latest version available in repository. I have an Arch build with the most up to date packages and kernel 5.6.4-arch1-1.
Occasionally I edit a file with nvim that I don't have permissions to edit. I only realise this as I am about to save my work.
Recently I edited
and no use of sudo.
This file has the following permissions
$ ls -la /etc/pulse/default.pa -rw-r--r-- 1 root root 4966 Jan 11 18:25 default.pa
So I did some googling and tried to save it with
:w !sudo tee %
and got this error
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper shell returned 1 Press ENTER or type command to continue
It also showed, on the highlighted bar, at the base of the screen, the following
This did'nt work.
So I tried
:w !echo password | sudo -S tee %
It then displayed the following
:w !echo password | sudo -S tee % [sudo] password for user: W12: Warning: File "/etc/pulse/default.pa" has changed and the buffer was changed in Vim as well See ":help W12" for more info. [O]K, (L)oad File:
So I pressed
O and nothing happened.
I then tried
:wq and it complained the file was read only.
I then went through the process again and this time pressed
L and it showed
:w !echo password | sudo -S tee % [sudo] password for user: W12: Warning: File "/etc/pulse/default.pa" has changed and the buffer was changed in Vim as well See ":help W12" for more info. "/etc/pulse/default.pa" [readonly] 0L, 0C Press ENTER or type command to continue
and nvim left me with a blank screen and an overwritten
etc/pulse/default.pa file with nothing in it.
I've recovered the file but want to know how to
tee the file down to disk when I open the file without the correct permissions.
I'm quite new to vim and think I got this working before but can't for the life of me remember how?