this post was submitted on 20 Jun 2024
30 points (96.9% liked)

Neovim

2161 readers
3 users here now

founded 1 year ago
MODERATORS
 

I made a small plugin that other people might find handy. It checks if the file open in the current buffer has write access and if not, prompts for sudo (or any other command at your choice) and copies the file.

No longer do you need to care about forgetting to use sudoedit or anything else, just edit the files you want to edit! This could change the world!!1!

But in all seriousness, this is my first neovim plugin and I barely spent an hour on it but it's simple and it gets the job done. It scratches a minor itch and maybe you'll also find it useful.

top 5 comments
sorted by: hot top controversial new old
[–] [email protected] 4 points 4 months ago (1 children)

cmap w!! w !sudo tee > /dev/null %

[–] [email protected] 1 points 2 months ago

Does it work with neovim?

According to this stackoverflow answer, it only works in Vim.

[–] [email protected] 1 points 2 months ago* (last edited 2 months ago)

I am currently using SudaWrite from vim-suda.

I will check out for sure. Thank you for posting.

[–] [email protected] 0 points 2 months ago (1 children)

I have a few

suggestion

  • add alternative (like mini repo)

question

  • does it work in Windows?
  • how it is different from the alternative?
[–] [email protected] 2 points 2 months ago

how it is different from the alternative?

I made this because I wanted to be able to change the command used for saving, and also so that I don't need to use any special commands to edit files in the first place. I just open the file I want to edit and if it needs sudo to edit, it prompts me.

does it work in Windows?

No. I don't use Windows so I'm not really interested in getting it to work.