Skip to main content
10 votes
Accepted

How to open a file as sudo from within vim?

One workaround is to open the file normally: :e file And then use the sudo tee trick when writing the file: :w !sudo tee % If you don't have read permission on the file, you're going to need to ...
Rich's user avatar
  • 32.3k
8 votes

Saving a non user file with NeoVim, eg root owned /etc/pulse/default.pa

There’s a plugin for this. The reason the old :w !sudo tee % doesn't work with Neovim has to do with the refactoring following a client-server architecture, the team is working on a solution though ...
Tae's user avatar
  • 2,135
5 votes

How can I automate filetype detection when using sudoedit?

tpope/vim-eunuch Like you've discussed, $SUDO_COMMAND can be used to find the original filename(s). Together with a nifty usage of fnameescape and doautocmd it is possible to deduce the correct ...
timss's user avatar
  • 291
4 votes

How to open a file as sudo from within vim?

I use the SudoEdit plugin, which defines the commands SudoRead and SudoWrite, which allow me to read and write with sudo permissions a file I didn't think to open with sudoedit.
garyjohn's user avatar
  • 6,379
3 votes

Saving a non user file with NeoVim, eg root owned /etc/pulse/default.pa

Try suda.vim : https://github.com/lambdalisue/suda.vim In case you use vim plug, after plugging it (adding the line) with Plug 'lambdalisue/suda.vim' do a :PlugInstall and thereafter with :SudaWrite ...
himanshuxd's user avatar
2 votes
Accepted

Saving a non user file with NeoVim, eg root owned /etc/pulse/default.pa

You could try this :W command: com -bar W exe 'w !sudo tee >/dev/null %:p:S' | setl nomod Broken down: " ┌ write the buffer on the standard input of a shell command (`:h w_c`) " ...
user938271's user avatar
  • 5,987

Only top scored, non community-wiki answers of a minimum length are eligible