Sublime Text 2 keyboard shortcut to open file in specified browser (e.g. Chrome)

wwwuser picture wwwuser · Nov 5, 2011 · Viewed 109.6k times · Source

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!

Answer

J. Holmes picture J. Holmes · Nov 6, 2011

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.

{
    "cmd": ["open", "-a", "Google Chrome", "$file"]
}

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'"