this post was submitted on 01 Nov 2024
62 points (75.0% liked)

Linuxsucks

357 readers
1 users here now

Rules:

  1. FOSS advocates and Linux evangelists aren't welcome. -We ask that you block us.
  2. Moderation is heavy handed. Try to stay on topic (that is LINUXSUCKS!).
  3. No Complaining Mute the sub if users, content, or rules bother you *it's ok to report rule violations

founded 1 year ago
MODERATORS
 
all 43 comments
sorted by: hot top controversial new old
[–] billbasher@lemmy.world 18 points 1 year ago (2 children)

:w !sudo tee %

If you are in vim you can do this

[–] stoicmaverick@lemmy.world 2 points 1 year ago* (last edited 1 year ago) (1 children)

Does it work in Helix as well?

[–] billbasher@lemmy.world 2 points 1 year ago

It looks like you can run shell commands so it should be possible although the syntax may be a bit different. I haven’t used Helix.

[–] madthumbs@lemmy.world -3 points 1 year ago

Does it have the same effect as sudoedit?

[–] Shadow@lemmy.ca 11 points 1 year ago (2 children)

Same shit happens with notepad in windows when editing the hosts file.

[–] MisterD@lemmy.ca 5 points 1 year ago (1 children)

Notepad++ handles this gracefully

It offers to relaunch itself elevated without losing what you just edited.

[–] superkret@feddit.org 2 points 1 year ago

And vim lets you elevate from inside it also.
This isn't an OS issue at all.

[–] madthumbs@lemmy.world -5 points 1 year ago* (last edited 1 year ago) (2 children)

You're right, some AI chat told me it wouldn't even open (by default). But at least it has a decent suggested solution in the error.

[–] theunknownmuncher@lemmy.world 2 points 1 year ago

Kudos for being willing to try it and see!

One very minor detail to note, in your test you weren't actually overwriting the original file that you opened, but instead Notepad appended a .txt to the filename, which is its default behavior, but you still got the same type or error because you didn't have write permission for any file in that directory.

[–] Clent@lemmy.world 9 points 1 year ago
:w !sudo tee %

Further research because you wouldn't use sudo for something you don't understand, right?

Right?!?

[–] Ephera@lemmy.ml 5 points 1 year ago (1 children)

Modern versions of Vim warn about this. I guess, this might still be an annoyance with other editors?

[–] Steamymoomilk@sh.itjust.works 4 points 1 year ago

This is why i love micro. When you tell it to save without sudo it asks to elevate your privileges.

[–] neidu3@sh.itjust.works 3 points 1 year ago

Ironically, I did this today when editing /etc/sudoers

[–] baggins@lemmy.ca 1 points 1 year ago

I saw a one liner somewhere that lets you privesc the vi process you're running from the vi command prompt

[–] theunknownmuncher@lemmy.world 0 points 1 year ago (2 children)

The bike meme is accurate in that it is you who did it to yourself

[–] GBU_28@lemm.ee 5 points 1 year ago (1 children)

This description accurately describes the joke

[–] theunknownmuncher@lemmy.world -1 points 1 year ago (1 children)

Based on the community, I figured it was trying to imply that this is somehow Linux's fault

[–] GBU_28@lemm.ee 2 points 1 year ago (1 children)

This reply is a reasonable consideration

[–] theunknownmuncher@lemmy.world -1 points 1 year ago

Based on the other replies to my original comment, it seems that I was right...

[–] Anticorp@lemmy.world 0 points 1 year ago

If you open it in code instead of vim or nano, then you can escalate the privileges if needed. It's also easier to work with overall.