Home Download Buy Blog Forum Support

creating someway to run my code in a browser

creating someway to run my code in a browser

Postby p3aul on Sun Apr 28, 2013 12:20 am

Sublime2 is a great code editor. Unfortunately, it doesn't come with the default ability to run the code in a browser if you are a web programmer, this is essential. I tried to follow a method I saw here: viewtopic.php?f=2&t=3851
, but when it came to entering the key bindings I got stuck. Here is what it said:


Re: how to view in browser

Postby C0D312 on Wed Nov 23, 2011 7:30 am
To to Tools > New Plugin. Copy and paste this in the the plugin:

Code: Select all
Code: Select all
    import sublime, sublime_plugin
    import webbrowser


    class OpenBrowserCommand(sublime_plugin.TextCommand):
       def run(self,edit):
          url = self.view.file_name()
          webbrowser.open_new(url)


The it said to:
Open up your User Keybindings. (Tools > Command Palette > "User Key bindings")
Add this somewhere to the list:
Code: Select all
Code: Select all
       { "keys": ["ctrl+shift+b"], "command": "open_browser" }


Where I get hung up is the last part, "User Key bindings". When I click on Command Palette I get a list box with an input box at the top. Nothing says key bindings and there are no Ok or cancel buttons of any sort.

Please help me, as a code editor without the ability to test your code is pretty useless to a web programmer.
Thanks,
Paul
p3aul
 
Posts: 3
Joined: Sat Apr 27, 2013 6:00 pm

Re: creating someway to run my code in a browser

Postby Lemon on Sun Apr 28, 2013 9:27 am

In the command palette if you type "key" you should see two options:
"Preferences: Key Bindings - Default"
"Preferences: Key Bindings - User"

Use the arrow keys to move to the one you want ("User") and press enter to run the command, which in this case will open up a JSON file for your own key bindings.
Then just paste in the JSON you were given and save.
Now ctrl+shift+b should execute the open_browser command.
Lemon
 
Posts: 27
Joined: Wed Jul 11, 2012 12:49 pm

Re: creating someway to run my code in a browser

Postby p3aul on Sun Apr 28, 2013 7:57 pm

Thank you for replying! I followed the steps like you said but it still doesn't work :(
p3aul
 
Posts: 3
Joined: Sat Apr 27, 2013 6:00 pm

Re: creating someway to run my code in a browser

Postby agibsonsw on Sun Apr 28, 2013 8:38 pm

p3aul wrote:Thank you for replying! I followed the steps like you said but it still doesn't work :(


After pressing Ctrl-Shift-B Press Ctrl-' (apostrophe or back-tick) to open the Console and check for any error messages.

Another option is to create a build file named, for example, PreviewInBrowser.sublime-build containing:

Code: Select all
{
    //"cmd": ["C:\\Users\\Andrew\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe", "$file"]
    "cmd": ["C:\\Program Files\\Mozilla Firefox\\firefox.exe", "$file"]

}

This option will then be available from the Tools menu, Build System. Once you've selected this option it will be available to run by pressing Ctrl-B.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: creating someway to run my code in a browser

Postby p3aul on Sun Apr 28, 2013 10:33 pm

Thanks for trying to help, but I think I'll go back to Notepad++ After comparing the two, for me, Notepad++ comes out ahead. Sublime2 is just not user-friendly. :(
p3aul
 
Posts: 3
Joined: Sat Apr 27, 2013 6:00 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot] and 14 guests