60

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?

Lucio
  • 18,843
oblitum
  • 1,687
  • 2
  • 16
  • 27

6 Answers6

67

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

chrismarx
  • 933
  • 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. – oblitum 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. – Déjà vu May 31 '14 at 09:47
  • This option doesn't let me add a third-party app, in my case Adobe Reader. – Colin 't Hart Feb 02 '15 at 10:05
  • 1
    @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 02:41
  • I followed the instructions and set VLC as the default and now all videos work by opening with it instead. That option may not be obvious in the process. – Michael Durrant Jul 01 '19 at 14:00
  • 1
    how come this is not the chosen solution? – João Pimentel Ferreira Mar 30 '20 at 09:12
27

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:

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

LimpingNinja
  • 712
  • 4
  • 8
  • As I was looking for usability, thanks for this one. Very nice tool. – oblitum May 02 '13 at 02:55
  • is Ubuntu tweak supported for 13.10? I can't install it. http://askubuntu.com/questions/413052/ubuntu-tweak-not-working-is-it-supported-for-13-10 help plz – 842Mono Jan 30 '14 at 17:22
  • @MinaMichael well I use it without problems on 13.10 – oblitum Mar 03 '14 at 04:48
  • @pepper_chico I was having trouble with it; some tabs didn't show anything when I opened them. I uninstalled it and went to the software centre to reinstall it but couldn't find it – 842Mono Mar 04 '14 at 10:52
  • @MinaMichael try synaptic, most of times I prefer it. You may also have to use a PPA, don't recall now if I used one. – oblitum Mar 13 '14 at 19:37
  • @pepper_chico okay I have synaptic installed but I can't figure out how to use it. help please. – 842Mono Mar 15 '14 at 10:39
  • @MinaMichael for installing just follow the link this answer provides, I have used the PPA installation procedure. – oblitum Mar 15 '14 at 15:07
  • the download link goes to ubuntu tweak. and by the way "saucy" is not listed! ... I was asking that I can't use Synaptics. – 842Mono Mar 16 '14 at 17:17
  • For those still looking at this answer, you can find new releases and information on the location sites blog.

    For example, for saucy: http://blog.ubuntu-tweak.com/2013/10/13/ubuntu-tweak-0-8-6-released-for-13-10-saucy.html

    – LimpingNinja Oct 28 '15 at 12:06
  • 5
    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: http://www.ubuntuupdates.org/package/getdeb_apps/xenial/apps/getdeb/ubuntu-tweak – z33k Sep 20 '16 at 15:20
  • 1
    Warning! The current version of Tweaks (at least on Ubuntu 18.04) does not provide this feature. – Parth Patel Apr 29 '19 at 15:57
  • 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 09: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 02:23
25

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.

Tharok
  • 334
  • 2
  • 8
user2311177
  • 373
  • 2
  • 4
  • 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. –  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 07 '16 at 10:33
  • How do you change the mimetypes of files? – a06e Jun 06 '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 09:21
  • @reducingactivity that's quite limiting, though. For example, I need to open plain text files with Text Editor, and Asciidoc (.adoc) files with Atom, but they are recognized as plain text files too, so if I change the default application it'll open them always with Text Editor or always with Atom, which forces me to open them by selecting the proper application every time... it's not strange they're not mapped to a separate mimetype by default, but not having the change to add new mimetypes... meh! – Andrea Ligios Apr 24 '20 at 09:29
15
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.

thefourtheye
  • 4,924
3

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.

z33k
  • 212
  • this is not as easy when you want to set multiple file types at once or by mime type – oblitum Jan 14 '14 at 01:05
  • The OP said explicitly that they are looking for a solution that does not involve Open With (see last line of their question). – Oliver Apr 18 '21 at 15:20
  • This could have been added to the question after my answer had been posted (see the dates). – z33k Apr 19 '21 at 16:25
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