I do web development and am trying out Sublime Text 2. Is there a keyboard shortcut to open the current file in specified browser (e.g. Chrome)?
Any help to get setup in Sublime Text for web development is appreciated!
I do web development and am trying out Sublime Text 2. Is there a keyboard shortcut to open the current file in specified browser (e.g. Chrome)?
Any help to get setup in Sublime Text for web development is appreciated!
egyamado's answer was really helpful! You can enhance it for your particular setup with something like this:
And then in your keybindings:
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.
Pulgin: Non Text Files https://packagecontrol.io/packages/Non%20Text%20Files Add config in the user settting
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.
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 newChrome
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'"
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:
Save. Then open up User Keybindings. (Tools > Command Palette > "User Key bindings"), and add this somewhere to the list:
Now open any html file in Sublime and use one of the keybindings, which it would open that file in your favourite browser.
Windows7 FireFox/Chrome:
just use your own path of firefox.exe or chrome.exe to replace mine.
Replace firefox.exe or chrome.exe with your own path.
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
: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.