How do I change the default text editor?

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