Sublime Forum

Open web browser with specified link and selected text

#1

Iā€™m learning a new language and find myself constantly looking up the language spec in google or on msdn. I would love to be able to double click on a word, and press a hotkey ( F1 ) and have sublime open my web browser with a hardcoded link and insert the selected text into the URL

does anyone have anything like this already? Is it possible? Iā€™m using the very latest sublime text 2 on OSX.

thanks in advance!

0 Likes

#2

This should do you :smile:

[code]import sublime, sublime_plugin
import webbrowser

class OpenHelpCommand(sublime_plugin.TextCommand):

def run(self,edit):
	msdnLink = 'http://social.msdn.microsoft.com/Search/en-gb?query={0}';
	for region in self.view.sel():
		if not region.empty():
			syntax = self.view.substr(region)
			webbrowser.open_new(msdnLink.format(syntax))[/code]

I assigned the key to Ctrl+F1 :smile:

Select the function/word/whatever you want to lookup and itā€™ll open a new browser window (tab in Chrome, probably Firefox/Opera too) taking you to MSDN :smile:

0 Likes

#3

wow, thanks! :smile: Looks simple enough?

Unfortunately, it doesnā€™t seem to be working for me under OSX. I copied the code exactly and saved it to:

/Users/jack/Library/Application Support/Sublime Text 2/Packages/User/OpenHelpCommand.py
then bound a key with it in the User Key Bindings with this:

{ "keys": "ctrl+f1"], "command": "OpenHelpCommand" },

The console shows the python file compiling fine, but nothing happens. I canā€™t get the sample hello world plugin to work either ( or any other plugin Iā€™ve tried to write ). Is there something else I need to install on the Mac?

I appreciate the help though :smile:

0 Likes

#4

ahā€¦ never would have guessed that. Iā€™ll have to read up on creating plugins.

ctrl+f1 still doesnā€™t work. Itā€™s worth mentioning Iā€™m using the windows keybindings in the mac version.

the binding below does work however and itā€™s plenty good. Thanks for your help

	{ "keys": "f1"], "command": "open_help" },
0 Likes

#5

[quote=ā€œpanamajackā€]ahā€¦ never would have guessed that. Iā€™ll have to read up on creating plugins.

ctrl+f1 still doesnā€™t work. Itā€™s worth mentioning Iā€™m using the windows keybindings in the mac version.

the binding below does work however and itā€™s plenty good. Thanks for your help

	{ "keys": "f1"], "command": "open_help" },

Woops forgot to mention. Command is always dropped, and the definition is snake cased.

OpenHelpCommand - open_help

Try ctrl+f2 ?

0 Likes