How do I make Geany my default editor on Ubuntu?
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.
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.
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:
- the default command-line editor - solved by 'izx'
- the file-type (mime-type) association in the desktop session for GUI applications - solved by 'Steve'.
Here in a little more detail:
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:
- you type "editor myFile.txt" in the console.
- going into edit-mode in less (see http://www.cyberciti.biz/faq/edit-file-when-youre-viewing-withmore-less/)
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