When you realized you forgot sudo
When you realized you forgot sudo
When you realized you forgot sudo
Lazy vim way I do it:
ggVG"wY:q!
followed by sudo !!
then VG"wp:x
Grab entire file and stuff it in register W
Exit file
Reopen sudo
Select all and replace with register W them write
Now I understand how the Adeptus Mechanicus feel when they perform a ritual power-on.
It's funny how years of use make that so intuitive but spelled out it's a garbled mess
Lazier way:
:w !sudo tee %
Yeah learning about tee
from this thread honestly.
It's been interesting realizing I had such a useful tool at my disposal but never knew
Is there an editor that can request root privileges without restarting it? That would be quite useful.
In vim, in normal mode you can do: :w !sudo tee %
Apparently that doesn't work in NeoVim, so recently I installed the suda plugin.
Personally, I just doas nvim and then the file name that needs root access, but it's a handy plugin in case I forget.
i use micro
Sure, you can do this in emacs: https://fuco1.github.io/2017-04-20-Save-write-protected-files-with-sudo-automatically.html
It's a simple trick in Vim:
https://stackoverflow.com/a/7078429
For the lazy: :w !sudo tee > /dev/null %
kate
does this in KDE, but it's not cli.
Yeah, in emacs you use tramp
to open the file with /sudo::
(n)vim + suda.vim.
micro ftw, no need to even memorize a command, it'll just ask if you want to use sudo
:w !sudo tee %
Warning: does not work for neovim
Iirc the specific reason behind this is
As a result, sudo (without args) can't work in nvim as it doesn't have a tty to prompt the user for passwords. Nvim also used to do what vim did, but they found out spawning the tty was causing other issues (still present in vim) so they changed it.
I didn't do any editing since it's just to prove a point, but I think it does fine.
Here is an alternative Piped link(s):
Piped is a privacy-respecting open-source alternative frontend to YouTube.
I'm open-source; check me out at GitHub.
Kwrite/Kate asks you for password. Seriously, why can't they all just use pkexec or some abstraction of it?
Sadly, i currently borked all Qt apps on my Gtk setup.
So does Micro. Nano... Nano does not.
Eh, on console i can just do ssu nano <file>
. Graphical editors are in question.
One of the many reasons why I use micro
C-x C-f /sudo::/path/to/file
I love Emacs. Thanks for teaching me someyhing today
Use suda.vim for automatically dealing with such cases. Works with neovim
as well.
I'll also recommend adding the following to your init.lua
or some config file because suda
doesn't play nicely with nvim -d
or vimdiff
.
lua
-- Disable Suda in diff views if not vim.api.nvim_win_get_option(0, 'diff') then vim.g.suda_smart_edit = 1 end
The vimscript
version of the same would be:
vimscript
" Disable Suda in diff views if ! &diff let g:suda_smart_edit = 1 endif
sudoedit
is more secure btw. Many editors are not built to be ran as root, and this copies the file to a temo directory, edits it without root, and then overwrites the original file on save with root.
I am here for one reason and one reason alone: source anime is Watamote, episode 12 @18:36
Tomoko tries to approach a girl, but the wind confuses her and she runs away in embarrassment, even though the girl was really friendly and would have liked to talk to her.
In the meme, this scene is used to parallel the feeling of an external system blocking an operation that both participants would agree to.
A similar feeling could be memed with the "myth of consensual sex" format.
@Bishma @Waffelson i recently started using fish for its command line history and autocompletion
This function takes the last command and puts sudo in front of it. Actually used it in a zoom call at work without thinking and it took a second to realize why everyone was laughing. Not my invention--came across it years ago on stackoverflow or someplace and thought it was funny/useful.
Considering the function name, here’s an obligatory thefuck plug
Isn't this the same effect as just running 'sudo !!' ?
According to this super user question, someone said that
!!
won’t work in a function, so you must use thefc -ln -1
command in a subshell instead. Note the response that sayseval
shouldn’t be used (not sure why)no because it takes the previous command and adds sudo to it right?