Home Download Buy Blog Forum Support

Easy way to open URLs in content?

Easy way to open URLs in content?

Postby peterc on Wed Dec 21, 2011 7:05 am

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.

(Just to assist anyone who might be trying to find this post in future.. hyperlinks, links, clickable URLs in text.. :-))
peterc
 
Posts: 2
Joined: Wed Dec 21, 2011 7:01 am

Re: Easy way to open URLs in content?

Postby jbjornson on Wed Dec 21, 2011 9:29 am

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.

Code: Select all
# -------------------------------------------
# { "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)
jbjornson
 
Posts: 353
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: Easy way to open URLs in content?

Postby jbjornson on Wed Dec 21, 2011 9:43 am

And from a different thread (http://www.sublimetext.com/forum/viewtopic.php?f=3&t=764):

jps wrote: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.


Edit: This functionality will open the current file in the web browser, not open a URL that is in the text...
jbjornson
 
Posts: 353
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: Easy way to open URLs in content?

Postby KatsuomiK on Sat Sep 01, 2012 6:34 am

Hi, I've extended the code to open the URL under the cursor.
https://gist.github.com/3542836
KatsuomiK
 
Posts: 1
Joined: Sat Sep 01, 2012 6:25 am

Re: Easy way to open URLs in content?

Postby noahcoad on Thu Jan 17, 2013 7:56 pm

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
noahcoad
 
Posts: 2
Joined: Fri Nov 09, 2012 5:28 pm


Return to General Discussion

Who is online

Users browsing this forum: svenax, ToddFiske, Yahoo [Bot] and 27 guests