Sublime Forum

Easy way to open URLs in content?

#1

I’ve just switched to Sublime Text 2 from TextMate and the only feature I seem to be missing so far is the ability to quickly open URLs in documents in the browser. In TextMate, if your cursor is within a URL, Fn+Enter would open it in the default browser.

I’ve tried searching plugins and various keyboard combos but can’t seem to find anything similar in Sublime Text 2. Is there a way to enable this, a plugin that will do the trick, or am I missing something really obvious? If it is theoretically possible but it hasn’t been done yet, I’ll happily take a stab at creating a plugin.

[size=85](Just to assist anyone who might be trying to find this post in future… hyperlinks, links, clickable URLs in text… :smile:)[/size]

0 Likes

#2

I know there is another implementation out there but I couldn’t find it. For now, here is a very simple plugin that opens the selected URL in a new tab (in your default web browser). It does funny things when the selected text is not a URL.

# -------------------------------------------
# { "keys": "alt+e"], "command": "open_url" }
# -------------------------------------------

# Open the URL in the current selection
class OpenUrlCommand(sublime_plugin.TextCommand):
   def run(self,edit):
      for region in self.view.sel():
         if not region.empty():
            url = self.view.substr(region)
            webbrowser.open_new_tab(url)
0 Likes

#3

And from a different thread (https://forum.sublimetext.com/t/open-in-browser/414/1):

[quote=“jps”]Open in Browser is implemented by the plugin Packages/HTML/OpenInBrowser.py

If you open that up, you can see that it’s hardcoded to only be enabled file names that end in .html or .htm - it would be easy to modify your local copy to use a different set of file extensions.[/quote]

Edit: This functionality will open the current file in the web browser, not open a URL that is in the text…

0 Likes

#4

Hi, I’ve extended the code to open the URL under the cursor.
gist.github.com/3542836

0 Likes

#5

It’s such a great idea to have this readily available that I turned it into a plugin that’s now available via the ST2 Package Manager and is posted here https://github.com/noahcoad/open-url

0 Likes