I'm not really sure this question is approprate here, but you can add a new "Build System" under Tools -> Build System -> New Build System...
As with all configuration in Sublime Text its just JSON, so it should be pretty straight forward. The main thing you are going to want to configure is the "cmd" key/val. Here is the build config for launching chrome on my mac.
Save that as Chrome.sublime-build, relaunch Sublime Text and you should see a new Chrome option in the build list. Select it, and then you should be able to launch Chrome with Cmd+B on a Mac (or whatever hotkey you have configured for build, maybe its F7 or Ctrl+B on a Windows machine)
At least this should give you a push in the right direction.
Edit:
Another thing I end up doing a lot in Sublime Text 2 is if you right click inside a document, one of the items in the context menu is Copy File Path, which puts the current file's full path into the clipboard for easy pasting into whatever browser you want.
Sublime Text 3
(linux example)
"shell_cmd": "google-chrome '$file'"
Install the View In Browser plugin using Package Control or download package from github and unzip this package in your packages folder(that from browse packages)
after this, go to Preferences, Key Bindings - User, paste this
Here is another solution if you want to include different browsers in on file.
If you and Mac user, from sublime menu go to, Tools > New Plugin. Delete the generated code and past the following:
import sublime, sublime_plugin
import webbrowser
class OpenBrowserCommand(sublime_plugin.TextCommand):
def run(self,edit,keyPressed):
url = self.view.file_name()
if keyPressed == "1":
navegator = webbrowser.get("open -a /Applications/Firefox.app %s")
if keyPressed == "2":
navegator = webbrowser.get("open -a /Applications/Google\ Chrome.app %s")
if keyPressed == "3":
navegator = webbrowser.get("open -a /Applications/Safari.app %s")
navegator.open_new(url)
Save.
Then open up User Keybindings. (Tools > Command Palette > "User Key bindings"), and add this somewhere to the list:
There seem to be a lot of solutions for Windows here but this is the simplest:
Tools -> Build System -> New Build System, type in the above, save as Browser.sublime-build:
{
"cmd": "explorer $file"
}
Then go back to your HTML file. Tools -> Build System -> Browser. Then press CTRL-B and the file will be opened in whatever browser is your system default browser.
egyamado's answer was really helpful! You can enhance it for your particular setup with something like this:
import sublime, sublime_plugin
import webbrowser
class OpenBrowserCommand(sublime_plugin.TextCommand):
def run(self, edit, keyPressed, localHost, pathToFiles):
for region in self.view.sel():
if not region.empty():
# Get the selected text
url = self.view.substr(region)
# prepend beginning of local host url
url = localHost + url
else:
# prepend beginning of local host url
url = localHost + self.view.file_name()
# replace local path to file
url = url.replace(pathToFiles, "")
if keyPressed == "1":
navigator = webbrowser.get("open -a /Applications/Firefox.app %s")
if keyPressed == "2":
navigator = webbrowser.get("open -a /Applications/Google\ Chrome.app %s")
if keyPressed == "3":
navigator = webbrowser.get("open -a /Applications/Safari.app %s")
navigator.open_new(url)
We store sample urls at the top of all our templates, so the first part allows you to highlight that sample URL and launch it in a browser. If no text is highlighted, it will simply use the file name. You can adjust the command calls in the keybindings to your localhost url and the system path to the documents you're working on.
I have similar situation like you. I dont wannt sublime open editor for binary like jpg png files. Instead open system default application is more reasonable.
create one Build. Just like the accepted answer. But it will both open default application and hex editor.
I choose the third way, it's quite sutiable for me. It will open jpg file in system default application and quickly close the edit mode automaically at the same time. As to the first two ways, you can set "preview_on_click": false, to stop openning automaticlly the hex editor compromisely.