48

gedit is set by default to open about any source file. I've gone through the file properties and changed default application to VIM for C and C++ files.

I'd need to do this for any source file I open now, for python files, for text files, for ruby, any, since gedit is set to open all of them.

How can I change this to open with VIM without going the hassle of setting "open with" one by one?

  • @DJCrashdummy this is not a duplicate if you take the time to read the discussion in both questions. Besides this being answered correctly by 3+ years already. – pepper_chico Oct 8 '16 at 16:39
  • @peper_chico please update the chosen solution accordingly, cause this is misleading – João Pimentel Ferreira yesterday
24

This answer only works in Ubuntu 16.04 or prior; the comments have a link to a Xenial release of Ubuntu-Tweak. In newer versions of Ubuntu this will not work as Ubuntu-Tweak is no longer supported by the author.

Comments have suggested that Chris Marx answer below is the right way, but it does not resolve the answer of administrative management - for example, setting the type for many items.

Note: Ubuntu 16.04 is still LTS and Ubuntu 14.04 is not EOL

The EASIEST way for you to do this would be to install the program Ubuntu Tweak.

Once you have it downloaded you simply open it up, change to Admins tab and then under System choose File Type Manager. Once in here select the file category Text and using shift-click and/or control-click select all of the file types you want, then click Edit on the bottom right.

This will allow you to multi-set the mimetype opener for all of the files.

See screen:

http://i.stack.imgur.com/BZtGN.jpg

  • As I was looking for usability, thanks for this one. Very nice tool. – pepper_chico May 2 '13 at 2:55
  • 4
    Note: Ubuntu tweak isn't supported any more and the link provided does not contain the tool mentioned. – rohithpr Jul 13 '16 at 10:04
  • 1
    for anyone looking for this: supported or not there's a xenial package in GetDeb repository: ubuntuupdates.org/package/getdeb_apps/xenial/apps/getdeb/… – z33k Sep 20 '16 at 15:20
  • 1
    @LimpingNinja Have you considered deleting this answer as it is no longer applicable (as consolation - there is badge for such action) – reducing activity Nov 10 '19 at 9:20
  • 1
    @MateuszKonieczny I have considered this, but my concern with deleting the answer is that 16.04 is still supported (LTS) and 14.04 is end of support but not yet EOL. Since there is a package for 16.04, I'll add a tag for now - but would like to know if there is a reasonable answer for > 16.04 that covers this actual scenario. – LimpingNinja Dec 23 '19 at 2:23
56

Seems like the answer here

is actually the easiest, specifically going to a file's properties, going to the "open with" tab, and then setting as default for that file type. Here's the picture:

enter image description here

  • 1
    Again, just as I have commented already in o'rety's answer: "this is not as easy when you want to set multiple file types at once or by mime type" and this question is about this. The chosen answer is still the right one. – pepper_chico Mar 13 '14 at 16:11
  • ah my mistake, I was reading that as "setting multiple file's types", not setting multiple default file type associations at once. my mistake- – chrismarx Mar 13 '14 at 17:58
  • This is actually the more natural answer (from the GUI and without manually writing text files or installing 3rd party stuff). It requires a one type at a time setup, though, since Ubuntu does not offer a Open With in a multiple selection -> Properties. – Ring Ø May 31 '14 at 9:47
  • This option doesn't let me add a third-party app, in my case Adobe Reader. – Colin 't Hart Feb 2 '15 at 10:05
  • @ringø I know I'm 2 years behind, but since I'm still the accepted answer it seems, I need to say that your comment about this being the natural answer doesn't resolve the OP question which specifically asks: "How can I change [all source files] to open with VIM without going the hassle of setting "open with" one by one". – LimpingNinja Mar 31 '16 at 2:41
19

speaking about how things works globally, for the entire system, the most important thing is

/usr/share/applications/defaults.list

which is the file that holds the associations between a given mime type and the application that is supposed to handle that kind of file.

If you don't know the mime type of a file simply use the command

mimetype

like so

mimetype img.jpg 
img.jpg: image/jpeg

text files, python scripts, web pages, usually any given file has its own mime type.

  • 2
    Please update the path(s) in your answer. I'm saying this because I see /usr/share/applications/defaults.list as a link to /etc/gnome/defaults.list in Lubuntu 13.10. – user25656 Jan 21 '14 at 11:50
  • 2
    In Ubuntu 14.04 changing /usr/share/gnome/applications/defaults.list had no effect for me. Changing /usr/share/applications/defaults.list as suggested did the trick. – Marcus Junius Brutus Apr 7 '16 at 10:33
  • How do you change the mimetypes of files? – becko Jun 6 '19 at 14:05
  • Make sure to log out for changes to register. – Andrew Jun 19 '19 at 13:49
  • @becko AFAIK you are unable to change mime type of files, you can change what will open a given mime type. – reducing activity Nov 10 '19 at 9:21
11
touch ~/.local/share/applications/defaults.list

Add the following lines to ~/.local/share/applications/defaults.list

[Default Applications]
text/plain=gvim.desktop

Now every file on your machine will open with gvim, by default.

  • What if I wanted to open console vim in Xterm instead? – Adrian Keister Jun 16 '13 at 19:29
  • 1
    In my current Ubuntu 14 setup this appears to be mimeapps.list instead of defaults.list. – glenatron Aug 21 '14 at 9:35
  • @glenatron Ubuntu 15 works with defaults.list – laktak Aug 11 '15 at 6:35
2

I guess the easiest graphical way would be:

Files (nautilus) >> select a file >> right click & Properties >> "Open With" tab >> select a program you fancy >> "Select as default". Done.

This method comes from this post on HowToGeek: http://www.howtogeek.com/117709/how-to-change-your-default-applications-on-ubuntu-4-ways/ where they also talk about how to change default Terminal programs.

  • this is not as easy when you want to set multiple file types at once or by mime type – pepper_chico Jan 14 '14 at 1:05
1

Go to Details from Unity Dash, click on Default Applications on the left pane. Change the file associations as per your preference. No additional installation required and you can set all your default applications from one place.

enter image description here

  • This answer does not show a way to handle C++ files, for example. – LimpingNinja Oct 28 '15 at 12:07
  • Thanks for adding that answer. (Although only for completeness' sake.) – PythoNic Mar 22 '16 at 14:50
  • 1
    Think about removing the one in .local/share/applications/ if you have a strange behavior. – Natim Dec 21 '16 at 21:01

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