Saturday, February 16, 2008

Changing the Default Text Editor in GNOME

The "Preferred Applications" menu item in GNOME runs a little app that allows you to change some of the default programs used for various tasks like web browsing, music playing etc. One thing that's been missing for me is the ability to change the default text editor. Sure you can open up Nautilus, right click on a text file, and chose that way, but there are many types of text files, and they are each treated independantly.

Recently I discovered the ~/.local/** path. I'll use gvim as an example for this excersise. This is the ticket for swapping default editors once and for all! First, use the method described above (the right click in Nautilus way). Now you should have a ~/.local/share/applications/gvim.desktop file. That's good. Next, create a ~/.local/share/applications/defaults.list file, and put this in it:

    [Default Applications]
    text/plain=gvim.desktop
    application/x-perl=gvim.desktop
    text/x-chdr=gvim.desktop
    text/x-csrc=gvim.desktop
    text/x-dtd=gvim.desktop
    text/x-java=gvim.desktop
    text/mathml=gvim.desktop
    text/x-python=gvim.desktop
    text/x-sql=gvim.desktop

The contents above were taken from my own system wide /usr/share/applications/defaults.list, just with :%s/gedit/gvim/. This should at least cover the file types that gedit keeps popping open for. You could always modify the system wide defaults.list, but be prepared to lose those changes during your next update. Also, since the gvim.desktop file already existed in my local home path, I never tried just copying the one from /usr/share/applications. That might work too.

I can't believe I've been using GNOME for so long and never knew this :(

1 comment:

  1. In my ubuntu Karmic installation the correct file name is now: mimeapps.list instead of defaults.list

    ReplyDelete