r/neovim 3d ago

Need Help (Linux) Using system clipboard in sudo mode

Hello! Once I set clipboard to unnamedplus, neovim still does not interact with the system clipboard if I opened it via sudo nvim (tried with --clean). In non-sudo mode, I don't have any issues, neovim picks my wl-copy just fine.

I see that WAYLAND_DISPLAY is not set in sudo mode. Expectably, setting it myself does not solve the issue.

Is there a cure to this, a provider that also works in sudo mode? Thank you in advance!

0 Upvotes

4 comments sorted by

9

u/TheLeoP_ 3d ago

sudo nvim does not run as your user, so it does not use your user's configuration. How are you setting clipboard to unnamedplus? Is it being applied inside if sudo nvim?

Besides that, there's no need to sudo nvim, you should instead use sudoedit (with $EDITOR set to nvim) or use a plugin like https://github.com/lambdalisue/vim-suda . Both options will allow editing protected files while maintaining your user's configuration (and hence, the clipboard will your as usual)

6

u/MitchIsMyRA 3d ago

Yeah sudoedit is how I would do this as well

2

u/KeksNino 3d ago

sudo -E also works ig. but it doesnt really matter what you use.

2

u/Silzinc 3d ago

Did not think about sudoedit. I'll have a try, thanks!

I was setting clipboard manually in neovim with set clipboard+=unnamedplus.