GEdit Missing from Default Association - Help Needed Please

Hello.

If I may, please allow me to ask about this issue:

In my very first couple weeks of Zorin OS - I'm into my 3rd month now (of uninterrupted!! use) - I got p'd off, angry that is, at the gedit Text Editor program because it began opening additional files, on which I clicked, in new tabs [instead of new windows].
(And I could have sworn that in the very first days of using Zorin OS it was opening everything in new windows if I recall correctly - which was upsetting me even more.)

That no longer bothers me now, because I've mostly moved on to a super cool and fun-to-use program called CorePad.

But there is still the annoyance and/or blunder that, as I was trying to sudo nautilus edit org.gnome.gedit.desktop in order to customize the Exec line therein, I somehow made the mistake to associate those desktop files - in sudo nautilus only (where the list of Open With options apparently never gets augmented), not in regular nautilus where I got plenty of text editors such as Textosaurus and LeafPad (but none of them ever want to show up in the restricted sudo Open-With list) - .. I associated the desktop file(s) with LibreOffice Writer.

Can somebody please help me re-associate them with gedit Text Editor?

No, Text Editor is no longer in that Open With restricted list, unfortunately. The only text editor in there now remains LibreOffice Writer.
(I can't remember exactly what I've done to make it disappear from there, but it's version 41 now - gedit - so I'm sure I've updated it when trying to fix the new-tabs annoyance.)

Pretty big, or, I don't know, deep, rather, mess I made, huh?

Right click on a file of the type you wish to open with gedit. Choose Properties, then "open with" (perhaps you have to search for other applications). Now choose gedit here and then set as default.

I'm a little lost. You're talking about at least 4 different programs now... can you clarify what files have you edited, what have you installed, and what is the expected behavior?

Whenever you make changes to configuration file, always make a backup of upfront. If something goes wrong, you can revert back to it.

Welcome to the Forum!

You could try a sudo apt reinstall gedit and look if it affects the .desktop File and set it back to default. If that should help, here are the Content of the File:

[Desktop Entry]
Name=Text Editor
Comment=Edit text files
Exec=gedit %U
Terminal=false
Type=Application
StartupNotify=true
MimeType=text/plain;
# TRANSLATORS: Do NOT translate or transliterate this text!
#              This is an icon file name.
Icon=org.gnome.gedit
Categories=GNOME;GTK;Utility;TextEditor;
Actions=new-window;new-document;
# TRANSLATORS: Do NOT translate or localize the semicolons!
#              The list MUST also end with a semicolon!
#              Search terms to find this application.
Keywords=Text;Editor;Plaintext;Write;gedit;
DBusActivatable=true
X-Ubuntu-Gettext-Domain=gedit

[Desktop Action new-window]
Name=New Window
Exec=gedit --new-window

[Desktop Action new-document]
Name=New Document
Exec=gedit --new-document

For the Future, I would suggest to be a bit more careful about to change Stuff like that and copy the default before changing to have it save if something doesn't work.

Hi, guys, and thanks.
But it's more in-depth.

I fear maybe I have not gone in-depth enough and clear enough with what I (still) need to fix.

Forpii, of course I can do what you said. In normal nautilus. But what I want to do (or wanted to do) was to edit said .desktop file in sudo nautilus -- see what I mean: installed-by-me text editors never appear when sudo opens the folder and I try 'Open With Other Application'. Only Text Editor and LibreOffice Writer are available there; well, now, for me, only Writer remains.
It's a weird mess, I realize.

Zenzen, well, yes, I installed all those text editors but I'm only talking about the Zorin default gedit Text Editor.
In order for me to edit a .desktop file in usr/share/applications, I used sudo nautilus to open that folder, then open with - I saw on a web page I should do that - but I somehow made the mistake of opening the .desktop file with LibreOffice Writer. Of course the changes to the .desktop file (in usr/share/applications to be clear) didn't take, and then I also lost gedit from that basic sudo open-with list..

...which, Ponce-De-Leon, brings me to the fact that I did reinstall gedit, and I can still use it just fine now. But it's not showing up in the basic 'Open With Other Application' list when right-clicking on org.gnome.gedit.desktop in "sudo nautilus usr/share/applications".
Or are you saying "sudo apt reinstall gedit" does it better? I think I just used "install" to get gedit back.
The .desktop file is no longer the issue, though. I've figured out since then to just edit .desktop files on the Desktop (or if need be use sudo gedit path command - I know this now, but back then I was a bigger newb -) instead of the main protected one.
By the way, LOL, being used to rename Desktop shortcuts at will easily in Windows, perhaps my biggest shock switching to Linux has been how much more complicated it is to rename Desktop shortcuts for programs/apps in Zorin OS.
I have seen the contents of the file, but modifying it using LibreOffice Writer was a bad thing. I think that's when "Text Editor" disappeared from the basic/trusted (sudo nautilus folder) open-with list.
See what I mean?
Thank you for wishing me welcome, as well.
Dang straight, I'm being more careful since then. But, hey, you live, you learn - as a newb I thought at least one of those online posts about forcing gedit to open new file in new window was bound to work. Should have just switched to CorePad first. (Text Editor gedit still opens new tabs even after modifying the Exec line to "=gedit --new-window %U", by the way - got that from an Ask Ubuntu 2024 page.)
But, indeed, what I'm hoping to do now, if possible, would be to restore gedit Text Editor to the (very basic) open-with list of programs available when you sudo nautilus a protected folder. If possible.

Ah, okay! Now I understand. So, You open Nautilus with sudo and then You want workon a File with Gedit. You wrote that only ''Text Editor on LibreOffice Writer are available''. Text Editor is Gedit. That is a Gnome Name Thing like Nautilus isn't cales Nautilus; it is called Files.

Two other Options for this:

Open a terminal and type sudo gedit [File-Path] and then the File will be openend in a Gedit Window and You can work on it. To give You an Example:

sudo gedit etc/default/grub

That would make me able to work on my Grub File.

the other Option would be to navigate in Nautilus (normal, not with sudo) in the Directory with the File You want change and then click in the Searchbar from Nautilus right on the Menu Buttons and choose the Option ''Open in Terminal'':

Then a Terminal will open in the Directory and You only hae to type sudo gedit [File-Name] in my Example:

sudo gedit grub

Are you logging in on Wayland?

Looking into this, it looks like the .deb (non-flatpak) Gedit has no trouble on elevated launch on X11.

However, on Wayland, it does not work.

1 Like

Okay, I'm in Wayland and have made a Test. I have the nautilus-admin Package installed to switch an opened Nautilus in Admin Mode. That works. I have directly the ''Open with Text Editor'' Option.

When I open Nautilus with sudo nautilus in the Terminal, I don't have that and have to go to ''Open with other Program'' and get this empty window where I have to click at the Bottom on the ''show all Applications'' Button (not sure if this is the appropriate english Term of it):

And then I get the Text Editor Entry:

I'm not sure if this is a X11/Wayland Thing (of Course it can be). I would guess that this is like it is because You open Nautilus directly with sudo. So, maybe the Solution could be to install the nautilus-admin Package and use this Option in the right-click Menu.

1 Like

Excellent point. So it may be a Polkit thing, instead.

But, I recommend against ever opening a GUI application with Sudo.
Instead, use pkexec.

I use Nemo - and the extension that adds "Open as Root". Very similar to the Nautilus "Open as Admin".

1 Like

@Aravisian That's very interesting, I didn't know that. I thought it is the same.

What difference does it make whether you run
sudo thunar (nautilus/nemo)
or
thunar (nautilus/nemo) >open here as administrator (root)
or
pkexec thunar (nautilus/nemo)?

Is it better to just run instead
sudo gedit path/to/file
if a file requires root permissions to edit and not to open the filemanager with sudo?

In Windows, you can easily copy the path of a file to the clipboard by right-clicking "Copy path to file".
How does this work in Linux? I really miss this function (or haven't found it yet).

I recommend sudo nano /path/to/file
Running sudo gedit is no different from sudo thunar or sudo nautilus.

This action uses pkexec, not sudo.

The Sudo Utility operates to elevate a command to root.
If you want to elevate the file manager with terminal, elevate only the terminal command with sudo:

sudo -i

Then launch your file manager:

thunar

Or all at once using the pkexec utility:

pkexec thunar

If you launch directly with sudo thunar then it must bypass polkit and allows root access to your User Directory. That is an insecure scenerio.
Doing this can cause root-owned config files to be created in your home directory which can lead to breakage.
On Wayland it is even worse, with many wayland apps having deprecated sudo permissions for GUI apps entirely. This is because GUI applications need access to the compositor, Display and environment variables. So the rule of thumb is - do not use sudo utility for launching GUI applications.
Use pkexec for launching GUI apps.

Use sudo for elevating to root in a CLI environment.

EDIT: A better way to put this:
If you use sudo to elevate a command, you are giving the computer an instruction to do One Thing you want it to do.
If you were to use sudo to elevate an application - you permitting that application to do Any Number Of things that It wants to do.

1 Like