Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
@izx Thank you :) –  Programming Noob Sep 30 '12 at 8:34
    
@izx Absolutely :) I'd still love to know what was the command-line way of doing it though. Regardless, I'l mark your answer as accepted :) –  Programming Noob Sep 30 '12 at 9:06

3 Answers 3

up vote 9 down vote accepted

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.

share|improve this answer
4  
I did that and Geany is selected * 3 /usr/bin/geany 10 manual mode but when I try to open a text file by double-clicking it in Nautilus, it still opens with gedit. –  To Do Feb 18 '13 at 16:23
    
@ToDo Me too. Wonder how do I can undo those commands. –  user128334 Dec 30 '13 at 15:59

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.

share|improve this answer
1  
This worked like a charm. –  Faisal Sayed Jul 19 '13 at 4:41
1  
Awesome! Unlike the accepted answer, your solution actually works for me. Thanks! #12.04 –  king_julien Sep 9 '13 at 14:40
    
Any idea how I can undo this? –  king_julien Sep 12 '13 at 8:35
    
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... –  Steve Sep 17 '13 at 5:36

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 types

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

Hope someone finds this useful.

Cheers, Steve II ;o)

share|improve this answer
    
This is very helpful but you can also consider editing and improving existing answers, too. It's often much less work. –  Tom Brossman Jul 24 '13 at 9:41
1  
Good point Tom, thanks. I'm always a little apprehensive about editing peoples answers. I will add a comment to the accepted answer. –  Steve-B Jul 24 '13 at 13:11
    
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. –  Tom Brossman Jul 24 '13 at 16:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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