63

I started using Sublime Text 2 a week or so ago and I loved it so much I've spent $60 on it and now want to use it for everything.

Gedit currently has ownership of most of the text file associations. I'd essentially like to replace any association to gedit with sublime-text-2.

Any tips available on bulk association changing? Desktop-neutral methods are preferred.

  • Hope my answer (in the last) is the easiest one you can use :) – Tummala Dhanvi May 18 '15 at 6:32
  • 2
    possible duplicate of how can I change file association globally? – Lucio Aug 27 '15 at 0:08
  • 2
    @Lucio - Why would you vote to close a question asked a year earlier against a question asked a year later? – RobotHumans Aug 27 '15 at 7:56
  • 1
    I don't rely on dates to mark a post as duplicated of another one. If one post has no useful content whilst other does, then it should be marked as dupe. If both posts bring useful content over the same issue, then they should be merged. At least that is MHO. – Lucio Aug 28 '15 at 1:21
  • 1
    Possible duplicate of How to set default program? – DJCrashdummy Oct 8 '16 at 14:21
65

Running on 13.04+, update the file: /etc/gnome/defaults.list.

sudo sed -i 's/gedit.desktop/sublime-text-2.desktop/g' /etc/gnome/defaults.list  

Credit to trent for the update to 13.04+

Pre-13.04:

System wide associations:

sudo sed -i 's/gedit.desktop/sublime-text-2.desktop/g' /usr/share/applications/defaults.list

Just your user's associations:

sed -i 's/gedit.desktop/sublime-text-2.desktop/g' ~/.local/share/applications/mimeapps.list

Credit to Oli for the naming convention of the .desktop file before I started using SublimeText2.

  • 1
    Magic, thanks. I've added what the PPA users (myself included) can use based on your answer. – Oli Mar 22 '12 at 15:22
  • 4
    Last method works fine also on Ubuntu 14.04 sudo sed -i 's/gedit.desktop/sublime-text-2.desktop/g' /etc/gnome/defaults.list – Postadelmaga May 9 '14 at 21:16
  • 4
    It should be noted that Sublime Text 3 uses sublime-text.desktop which drops the version number instead of incrementing the filename to sublime-text-3.desktop – Paul Nelson Baker Jun 23 '14 at 19:44
  • 3
    Use sudo sed -i 's/gedit.desktop/sublime_text.desktop/g' /etc/gnome/defaults.list to Sublime Text 3. – Iago Aug 5 '14 at 22:20
  • 2
    Interesting, in 14.10, I had to change /usr/share/applications/defaults.list (which you indicated was for Pre 13.04 releases). Since I wanted to use Kate instead of Gedit, I modified your command as follows: sudo sed -i 's|gedit.desktop|kate.desktop|g' /usr/share/applications/defaults.list. (The vertical bars in sed are just a personal preference). – PJ Singh Oct 29 '14 at 0:31
56

Update for 16.04 Users:

Ubuntu tweak has been discontinued. Much of it's functionalities are now being provided by Unity Tweak Tool or Gnome Tweak Tool. But those still lacks Ubuntu Tweak's awesome feature of easy file-type association changing.

To install Ubuntu Tweak on these later version follow the procedure described on this answer about installing it on 16.04


There is another way to change the association. It is via using Ubuntu-tweak.

  1. Install Ubuntu tweak

  2. Open it via Dash by typing "Ubuntu tweak"

    enter image description here

  3. After opening it, Click on the Admin tab.

    enter image description here

  4. Then click on File type manager section

    enter image description here

  5. Then first select the Text catagory from the left side bar, and then click on the Associated Applications column to sort it by Application name

    enter image description here

  6. After the application is sorted by name, Select the top entry with Gedit, then Press and hold the Shift key and click on the last entry with gedit. Then click on the Edit button.

    enter image description here

  7. A new window will open where you can see all installed text editor.

    enter image description here

  8. Then select the desired application from list and click close. You can also Click on the Add button to add an application which is not installed in pre-defined system folder.

Hope this will help. If you want to reset them, you can click the reset button also.

The good thing in this solution is, you can't accidentally mess up your system .desktop file.

  • @dhanvi Just because you answered with another approach doesn't mean you must give a downvote! – Anwar May 19 '15 at 9:25
  • @dhanvi When we do answer, we typically consider things such as how easy is the solution to follow. I knew several other methods, but it was the easiest. And, setting default was not an option in 12.04 afair. And I have given a way to set several file type simultaneously. FYI, update-alternative is really not an option most of the time. – Anwar May 22 '15 at 13:36
  • maaaan this is best aprroach – Andrey Rahimov Dec 29 '15 at 12:31
12

The easiest way to do is using the nautilus files not sure if it works for others too

  1. select the type of file you want right click and select properties (Alt+Enter is the shortcut)

  2. The choose the option open with and then select the one you want as you see here I use atom by default you can also select sublime from the recommended applications enter image description here

Command line editor

you you want to choose the default editor in command line type the following command and then choose the option from there

sudo update-alternatives --config editor

since I use vi I have set it to vim you can choose what ever you want from there also here is the screen shot

screen shot

If you like this don't forget to vote up this post

  • @Oli I think this is the easiest answer hope you agree :) – Tummala Dhanvi Apr 8 '15 at 11:44
  • 1
    easiest solution, in my view (with nautilus, I mean) – mBardos May 14 '15 at 11:16
  • Hope this helped you @mBardos :) – Tummala Dhanvi May 18 '15 at 6:30
  • 2
    Your answer is not actually answering the question, since the OP wants a solution that handles multiple file type assignment at once! Please re-read the question – Anwar May 21 '15 at 9:33
-2
  1. Right click on the file
  2. Open properties
  3. Select the "Open with" tab
  4. Choose an application
  5. Click on "Set as default"

Screenshot of setting Sublime Text as default application: Set <code>Sublime Text</code> as default application"

Note: If you right click on a *.c file and if you do the above process, then only those files which have the same extension will have the new application as a default one. So similarly you should do the same for all kinds of files. Eg: *.cpp, *.py etc.

  • already mentioned the same in above answer – Tummala Dhanvi Nov 18 '16 at 17:53

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.