When I right-click on a markdown file (xxx.md) in Gnome Files (formerly "Nautilus"), I cannot see "Sublime Text" as a choice, even when I select "View All Applications".

I even tried adding %F to the lines Exec=/opt/sublime_text/sublime_text -n and Exec=/opt/sublime_text/sublime_text --command new_file in the [Desktop Action Window] and [Desktop Action Document], respectively, but it did not change anything.

Great solution. It would be nice if you also offered the explanation as to why this works.
– padawanTonyNov 26 '16 at 20:57

1

@padawanTony There is a cache for file types (MIME types) in Ubuntu and each MIME type has related applications. Copying the file copies over correct sublime_text.desktop file which is able to relate to text files (contains line MimeType=text/plain; which default file in local folder does not contain). Then executing the sudo-command will update MIME cache (reads in updated .desktop file) and the relation will appear in context menu. I cannot unfortunately say why we have buggy .desktop file under .local in the first place.
– MF.OXApr 7 '17 at 15:03

Would simply deleting the sublime_text.desktop entry from the local folder then also work? Would the OS usually make a fresh copy of it?
– minitaurosFeb 9 '18 at 9:27

@agustaf, I am using ubuntu 16.04 but /.local/ folder is not located could you please help
– SagarPPanchalNov 15 '18 at 4:56

@SagarPPanchal You could try creating it with mkdir -p ~/.local/share/applications and see if copying the file over still works. If that doesn't work you may want to post a new question.
– agustafNov 16 '18 at 5:07

I tried all the options as mentioned in other answers. But, somehow it didn't help me (I'm using Ubuntu 16.04 and installed Sublime-text_build-3126_amd64).

I see this problem occurs in my system only when I install Sublime editor using the package (sublime-text_build-3126_amd64.deb) downloaded from the site. However, installing Sublime from terminal resolves this problem.

I'm yet to figure out technically why there is a difference in the application behaviour between its 2 modes of installation. However, as it works for me, am sharing it here so that it might be helpful for others. The working alternative is:

Uninstall the existing sublime package. Use Synaptic Pkg Mgr and do a complete removal.

Right-click on the file you wish to open in the Sublime editor. Now, you could find the application "Sublime text" listed in the menu. Also, you could set the editor as default for the file-type by setting it in the file's properties.

Open /usr/share/applications/defaults.list (a symlink to /etc/gnome/defaults.list on my system) in Sublime and replace all instances of gedit.desktop with sublime_text.desktop. Save the file and restart your computer - it may be sufficient to log out and back in, but I suspect you'll need to completely quit Gnome for the settings to be reloaded. Once you've logged back in, Sublime Text should be listed in the right-click menu as the default choice for Markdown files, and it should be in the "Open With" menu as well for all file types that can be opened in a text editor.

EDIT:

Here are the contents of my current /usr/share/applications/sublime_text.desktop:

Still no joy. There must be something funny about my Sublime Text installation. I compared the .desktop file with the one Atom, and there is no substantial difference, but Atom appears in the open with list.
– RalphFeb 12 '16 at 13:56

@Ralph very strange. I just edited my answer with the current contents of my sublime_text.desktop, and it looks exactly the same as the one in your question. My next suggestion would be to completely uninstall Sublime (you can leave ~/.config/sublime-text-3) and reinstall it fresh. Double-check /usr/share/applications/defaults.list again to make sure all the gedit (and perhaps atom as well?) entries have been replaced with sublime_text, then reboot and try again.
– MattDMoFeb 12 '16 at 14:35