How do I change the default text editor?

How can I change my default text editor from gedit to Emacs?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Here is what worked in my case:

  1. Right click on a text file.
  2. Choose "Properties" (not "Open With…")
  3. Click on the "Open With" tab.
  4. Choose your new text editor.
  5. Mark chosen text editor using a button "Set as default".

This also works on 12.04 and 13.04.

@ Edit: based on comments it does work on all distros until 20.04

Solution 2

To change default text editor across the file types, try updating gnome-text-editor configuration.

sudo update-alternatives --config gnome-text-editor

In some cases:

sudo update-alternatives --config editor

Solution 3

A more robust solution would be to replace the bindings in /usr/share/applications/defaults.list.

sed -i 's/gedit/emacs/' /usr/share/applications/defaults.list

Solution 4

Right click on a text file, point to “Open With” and it’ll show other editors in a sub-menu. Click on “Other Application…”. It’ll show you a dialog with a list of applications, select Emacs and make sure the “Remember this application for “plain text document” file” option is checked. Click “Open”.

Solution 5

I don’t use a DE, but for my configurations the next command is the best:

/usr/bin/select-editor 
  • it selects your default sensible-editor from all installed editors
  • must run with current user
  • you must have more than one editor in your system

Man pages select-editor

Solution 6

If you are working from the terminal then I would add the following to your .bashrc file (or the config file for your favorite shell):

export EDITOR=emacs
export VISUAL=emacs

Solution 7

sed -i 's/gedit/emacs/g' /etc/gnome/defaults.list

Solution 8

You can set the default text editor for a specific user in # ~/.local/share/applications/mimeapps.list by:

[Default Applications]
text/plain=gedit.desktop

For global configuration for all users you have to modify the /etc/gnome/defaults.list

Solution 9

On Ubuntu 20, you need to change the gnome-text-editor alternatives link from gedit to the one you want. However, there usually is only one such editor detected so update-alternatives --config won’t work; you’ll have to add the editor you want.

E.g. to add notepadqq:

sudo update-alternatives --install /usr/bin/gnome-text-editor gnome-text-editor /usr/bin/notepadqq 50
sudo update-alternatives --config gnome-text-editor

Solution 10

If you would like to replace gedit with any other text editor for all file types, the easiest is to edit the defaults.list file located here:

/usr/share/applications/defaults.list

Just find and replace all gedit.desktop references with your own editor (in this case emacs.desktop).
You need root permissions to edit the file. So, just do:

sudo -H gedit /usr/share/applications/defaults.list

Save the file, close it and it’s done.

Solution 11

For some reason I had to use xdg-mime:

xdg-mime default org.gnome.gedit.desktop text/plain # For current user

you can use your system-wide .desktop files under /usr/share/applications/
or local files under ~/.local/share/applications/ or create your own.

edit:
It’s also helpful to know that user configurations are stored in ~/.config/mimeapps.list which overrides the defaults.
source: https://stackoverflow.com/a/64850938/9085151

Solution 12

To set Pluma as default text editor for all user (global):

sudo sed -i 's|text/plain=gedit.desktop|text/plain=pluma.desktop|g'  /etc/gnome/defaults.list

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply