How do I make Geany my default editor on Ubuntu?

18,006

Solution 1

The command line way is:

sudo update-alternatives --install /usr/bin/editor editor /usr/bin/geany 10

and then use sudo update-alternatives --config editor to select Geany if necessary.

As a graphical alternative to the command-line method, consider using Gnome Alternatives (sudo apt-get install galternatives). Run GAlternatives, select editor in the left column, and then add/choose Geany on the right.

Solution 2

As an alternative, this also worked for me:

xdg-mime default geany.desktop $(grep MimeType /usr/share/applications/geany.desktop | sed 's/MimeType=//' | sed 's/;/ /g')

This line fetches all MimeTypes gedit is registered for, performs some cleanup (the sed commands) and finally sets geany as default application for them.

I found it here along with a bunch of useful info on colour schemes.

Solution 3

This is a little late but I thought it may help someone.

My problem is I don't like to copy and paste things I don't understand, so here's an explanation of the answers so far.

First and foremost, there are two issues here and both answers are, in there own right, correct:

  1. the default command-line editor - solved by 'izx'
  2. the file-type (mime-type) association in the desktop session for GUI applications - solved by 'Steve'.

Here in a little more detail:

  1. command line solution -from 'izx'

    • adds geany (a GUI application) to the alternative editor list and sets it as default.
    • I always thought that editor was usually reserved for text-based editors like vi, vim, nano, etc, but I have just checked and this seems to work as well.
    • the result means you can your chosen default will be used to open the file when for example:
  2. mime-type solution - from 'Steve'

At file level, there are two lists of importance:

/usr/share/applications/defaults.list - the system defaults list.

~/.local/share/applications/mimeapps.list - the users personal desktop session defaults list

What does the command do?

From the xdg-mime man page (man xdg-mime)

xdg-mime - command line tool for querying information about file type handling and adding descriptions for new file type

The xdg-mime default... command adds entries to the users personal list.

Let's break the command down.

Command:

xdg-mime default geany.desktop $(grep MimeType /usr/share/applications/geany.desktop | sed 's/MimeType=//' | sed 's/;/ /g')

The command can be read as:

set geany.desktop as the default application for the mime-type outputted by $(grep MimeType /usr/share/applications/geany.desktop | sed 's/MimeType=//' | sed 's/;/ /g')

Looking at

$(grep MimeType /usr/share/applications/geany.desktop | sed 's/MimeType=//' | sed 's/;/ /g')
  • takes all mime-types from the geany.desktop file
  • removes the "MimeType="
  • replaces ";" with " "
  • giving us:
    text/plain text/x-chdr text/x-csrc text/x-c++hdr text/x-c++src text/x-java text/x-dsrc text/x-pascal text/x-perl text/x-python application/x-php application/x-httpd-php3 application/x-httpd-php4 application/x-httpd-php5 application/xml text/html text/css text/x-sql text/x-diff

Looking at the users personal file after running the command, we can see all the file-associations set for the geany.desktop application:

[Default Applications]
x-scheme-handler/mailto=userapp-Thunderbird-ZP00XW.desktop
message/rfc822=userapp-Thunderbird-ZP00XW.desktop
application/x-extension-eml=userapp-Thunderbird-ZP00XW.desktop
application/x-perl=sublime_text.desktop
text/plain=geany.desktop
text/x-chdr=geany.desktop
text/x-csrc=geany.desktop
text/x-dtd=sublime_text.desktop
text/x-java=geany.desktop
text/mathml=sublime_text.desktop
text/x-python=geany.desktop
text/x-sql=geany.desktop
text/x-c++hdr=geany.desktop
text/x-c++src=geany.desktop
text/x-dsrc=geany.desktop
text/x-pascal=geany.desktop
text/x-perl=geany.desktop
application/x-php=geany.desktop
application/x-httpd-php3=geany.desktop
application/x-httpd-php4=geany.desktop
application/x-httpd-php5=geany.desktop
application/xml=geany.desktop
text/html=geany.desktop
text/css=geany.desktop
text/x-diff=geany.desktop

Knowing this, here is my particular problem and how I solved it.

Problem:

I wanted to changed the default "file opening" application in Nautilus from "gedit" -> "sublime text".

Solution:

Find the system defaults for gedit with:

$less /usr/share/applications/defaults.list | grep gedit
application/x-perl=gedit.desktop
text/plain=gedit.desktop
text/x-chdr=gedit.desktop
text/x-csrc=gedit.desktop
text/x-dtd=gedit.desktop
text/x-java=gedit.desktop
text/mathml=gedit.desktop
text/x-python=gedit.desktop
text/x-sql=gedit.desktop

Replace "gedit" with "sublime_text" and add the entries to the "Default Applications" section of my personal defaults.list

application/x-perl=sublime_text.desktop
text/plain=sublime_text.desktop
text/x-chdr=sublime_text.desktop
text/x-csrc=sublime_text.desktop
text/x-dtd=sublime_text.desktop
text/x-java=sublime_text.desktop
text/mathml=sublime_text.desktop
text/x-python=sublime_text.desktop
text/x-sql=sublime_text.desktop

Solution 4

Because there are comments indicating that the accepted answer was not correct I feel I should point out this question can not have a single answer. If the question was changed to specify the CLI and the queries for the GUI moved to a new thread this would clear up the confusion. Too late for that I guess.

Anyway for nautilus (aka files) on gnome under Ubuntu 14.04. And given the accepted answer, you might (like I did) expect the equivalent would be:
donotdothisssudo update-alternatives --install /etc/alternatives/gnome-text-editor gnome-text-editor /usr/bin/geany 10

That's what I thought and it broke the links, so don't do that! If you did, this is what they were for me:
lrwxrwxrwx /usr/bin/gnome-text-editor -> /etc/alternatives/gnome-text-editor lrwxrwxrwx /etc/alternatives/gnome-text-editor -> /usr/bin/gedit

While repairing this error I recreated these links as follows:
lrwxrwxrwx /usr/bin/gnome-text-editor -> /etc/alternatives/gnome-text-editor lrwxrwxrwx /etc/alternatives/gnome-text-editor -> /usr/bin/geany

As all I have really done is to replace the secondary simlink, and I have desired response in my system my guess is that the task is simply this:
sudo ln -s /usr/bin/geany /etc/alternatives/gnome-text-editor

However running a CLI command to change something which is GUI specific, must be wrong. The place where my hands take me when searching for this change option is the nautilus menu system, next to the individual file type setting. However the only reason that I go there is because that is where part of the solution is. In my view if you have followed the logic of DPKG (update-alternatives), and included it in your distribution then you do not want a user space application like Nautilus interfering with your settings manager app. My humble suggestion to fix this would be to add a new editor settings control to settings >> details >> default applications, which would need to be a new page from the users point of view. The Nautilus team would then need to change its menu so that the user is redirected to that new page. This would compromise where my hands have taken me to look for the setting, where my hands 'should' have taken me instead and manages a single point entry process into a system setting. It looks like this change would need to be within the port of debian's galternatives, although I am just guessing. Of course there would be no point charging ahead with that kind of thing without the Nautilus team on board with the idea, they would also need to specify the API or equivalent mechanism.

The settings page in my view would need to cover both the default gnome editor selection and the application used to open each individual file (which is to replace the current functionality provided by Nautilus).

I post this as a passing thought, feel free to drive it forwards if it appeals to you. Sadly I don't know the procedure and the protocol necessary to do so myself.

Share:
18,006
Anubhav Mishra
Author by

Anubhav Mishra

Updated on September 18, 2022

Comments

  • Anubhav Mishra
    Anubhav Mishra over 1 year

    I actually want to change the default text editor on my Ubuntu 12.04 from nano to Geany. When I used this code:

    update-alternatives --config editor
    

    .. I don't see Geany in the list.

    So to add Geany, this is supposed to work right?

    update-alternatives --install /usr/bin/geany geany /usr/bin/geany 10
    

    Also, on a side note, can you tell me if you would personally suggest me to change the default editor from nano to Geany, and why?

  • Faisal Sayed
    Faisal Sayed almost 11 years
    This worked like a charm.
  • Sanam Patel
    Sanam Patel almost 11 years
    This is very helpful but you can also consider editing and improving existing answers, too. It's often much less work.
  • Steve-B
    Steve-B almost 11 years
    Good point Tom, thanks. I'm always a little apprehensive about editing peoples answers. I will add a comment to the accepted answer.
  • Sanam Patel
    Sanam Patel almost 11 years
    Don't worry about editing someone else's post here, it is expected. Edits get peer-reviewed until you hit 2000 rep, then they go straight through. Keeping all the good info in one answer makes it easy to find later.
  • king_julien
    king_julien over 10 years
    Awesome! Unlike the accepted answer, your solution actually works for me. Thanks! #12.04
  • king_julien
    king_julien over 10 years
    Any idea how I can undo this?
  • andrey
    andrey over 10 years
    No idea, but look at the answer below because (the other) Steve has done a great job of explaining what this one actually does - you should be able to reverse engineer the effects from there. Why are you undoing it? Its been a great solution for me and has worked perfectly for me for over 6 months...
  • JeroenD
    JeroenD over 10 years
    @ToDo Me too. Wonder how do I can undo those commands.
  • VeganEye
    VeganEye over 3 years
    I used this: sudo update-alternatives --install /usr/bin/gnome-text-editor gnome-text-editor /usr/bin/geany 100