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

后端 未结 14 2152
野性不改
野性不改 2020-12-02 04:31

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 set

相关标签:
14条回答
  • 2020-12-02 04:50

    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

    [{ "keys": [ "f12" ], "command": "view_in_browser" }]

    now F12 will be your shortcut key.

    0 讨论(0)
  • 2020-12-02 04:50

    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.

    1. create one Build. Just like the accepted answer. But it will both open default application and hex editor.
    2. Pulgin OpenDefaultApplication https://github.com/SublimeText/OpenDefaultApplication It will have context right click menu OpenInDefaultApplication. But It will both open default application and hex editor as well
    3. Pulgin: Non Text Files https://packagecontrol.io/packages/Non%20Text%20Files Add config in the user settting

      "binary_file_patterns": ["*.JPG","*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds", "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip"],
      "prevent_bin_preview": true,
      "open_externally_patterns": [
         "*.JPG",
         "*.jpg",
         "*.jpeg",
         "*.JPEG",
         "*.png",
          "*.PGN",
         "*.gif",
          "*.GIF",
          "*.zip",
          "*.ZIP",
          "*.pdf",
          "*.PDF"
      ]
      

    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.

    0 讨论(0)
  • 2020-12-02 04:52

    or try this

    "cmd": ["cmd","/K","start http://localhost/Angularjs/$file_name"]

    0 讨论(0)
  • 2020-12-02 04:55

    This worked on Sublime 3:


    To browse html files with default app by Alt+L hotkey:

    Add this line to Preferences -> Key Bindings - User opening file:

    { "keys": ["alt+l"], "command": "open_in_browser"}
    


    To browse or open with external app like chrome:

    Add this line to Tools -> Build System -> New Build System... opening file, and save with name "OpenWithChrome.sublime-build"

    "shell_cmd": "C:\\PROGRA~1\\Google\\Chrome\\APPLIC~1\\chrome.exe $file"
    

    Then you can browse/open the file by selecting Tools -> Build System -> OpenWithChrome and pressing F7 or Ctrl+B key.

    0 讨论(0)
  • 2020-12-02 04:59

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

    0 讨论(0)
  • 2020-12-02 05:01

    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.

    0 讨论(0)
提交回复
热议问题