77

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

  • It is answered here: askubuntu.com/questions/977538/… - basically you want to export EDITOR=emacs - and perhaps add that to your .bashrc so it becomes your default. – SDsolar Nov 17 '17 at 21:24
  • Good question: the procedure is not intuitive! – David Jul 10 '19 at 13:18

10 Answers 10

82

The answer didn't work on 12.10. 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.

  • It does not work on 13.04. After Step 3, I see a lot of choices, but not the editor I would like to have .... of course, the idea would be to use 'Add' ... but this is grayed out and can't be selected. Argh – Marius Hofert May 23 '13 at 15:24
  • 1
    worked for me on 13.10 (replaced gedit with geany) – Alexander Malakhov Jan 29 '14 at 9:35
  • "Set as default" not showing on v 14 – atilkan Aug 31 '15 at 4:44
  • 1
    Works on 16.04 too! – Dženan Sep 5 '16 at 15:02
  • 2
    Also works on 17.04 – Jonas Dahlbæk Jul 25 '17 at 15:38
39

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
15

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
  • I don't know how, but by copying this command I accidentally cleared the whole file. I would much prefer doing this in a text editor using find-replace (as explained in this answer) for those who are not too familiar with sed. – metakermit Apr 5 '13 at 22:37
  • I did this (in a text editor with find-replace, which should have the same result), then logged out and back in but still C++ header files (*.h) are opened in gedit. – Stefan Monov Dec 14 '16 at 15:06
11

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".

  • 1
    I did try this, but I'm having a bit of a problem - whenever I double-click on a file in Nautilus, I get a dialog box that says: "Do you want to run "tasks.css", or display its contents? "tasks.css" is an executable text file." And then there are four options - Run in Terminal, Display, Cancel, Run. (This happens with every file, not just CSS files.) – begtognen Nov 16 '10 at 12:05
  • 5
    @begtognen: Sorry for the ultra-late reply. But I've been trying to find a solution for this myself. Just found one - go to Nautlius preferences (Edit > Preferences), select the "Behavior" tab and under the "Executable Text Files" section, select the radio button "View executable text files when they are opened". Fixed the issue for me. – Mussnoon Nov 22 '10 at 23:28
  • I tried this also, but Emacs doesn't appear in the list of applications. Any thoughts? – MTS Apr 1 '14 at 19:44
  • No "Remember this application" there. When outdated you might want to either delete your answer, or clearly specify for what versions of Ubuntu it works. Thanks! :-) – Nicolas Raoul Nov 21 '16 at 2:52
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

3

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
  • +1 for this answer. Particularly if you're a user and don't have sudo or don't want to modify anyone else's preferences – Loisaida Sam Sandberg Dec 13 '19 at 15:01
3
sed -i 's/gedit/emacs/g' /etc/gnome/defaults.list
2

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.

2

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

-1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.