developer tip

지정된 브라우저 (예 : Chrome)에서 파일을 여는 Sublime Text 2 키보드 단축키

optionbox 2020. 8. 3. 08:29
반응형

지정된 브라우저 (예 : Chrome)에서 파일을 여는 Sublime Text 2 키보드 단축키


웹 개발을하고 Sublime Text 2를 시험하고 있습니다. 지정된 브라우저 (예 : Chrome)에서 현재 파일을 여는 키보드 단축키가 있습니까?

웹 개발을 위해 Sublime Text로 설정하는 데 도움을 주시면 감사하겠습니다.


이 질문이 여기에 해당되는지 확실하지 않지만 아래에 새 "빌드 시스템"을 추가 할 수 있습니다 Tools -> Build System -> New Build System...

Sublime Text의 모든 구성과 마찬가지로 JSON 만 있으므로 매우 간단합니다. 구성하려는 주요 사항은 "cmd"키 / val입니다. 내 Mac에서 크롬을 시작하기위한 빌드 구성이 있습니다.

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

로 저장하고 Chrome.sublime-buildSublime Text를 다시 시작 Chrome하면 빌드 목록에 옵션이 표시됩니다. 그것을 선택하면 Mac 에서 Cmd+ B(또는 빌드를 위해 구성 한 핫키 , Windows 컴퓨터에서 + F7또는 Ctrl+)로 Chrome을 시작할 수 있어야합니다B

적어도 이것은 당신에게 올바른 방향으로 밀어야합니다.

편집하다:

Sublime Text 2에서 많은 일을 끝내는 또 다른 것은 문서 내부를 마우스 오른쪽 버튼으로 클릭하면 상황에 맞는 메뉴의 항목 중 하나 Copy File Path는 현재 파일의 전체 경로를 클립 보드에 넣어 원하는 브라우저에 쉽게 붙여 넣을 수 있다는 것입니다.


Sublime Text 3 (리눅스 예) "shell_cmd": "google-chrome '$ file'"


최신 빌드 (2207)에 "HTML 파일에 대한 브라우저 컨텍스트 메뉴에서 열기"가 추가되었습니다. 출시일은 2012 년 6 월 25 일입니다.


Windows7 FireFox / Chrome :

    {
       "cmd":["F:\\Program Files\\Mozilla Firefox\\firefox.exe","$file"]
    }

firefox.exe 또는 chrome.exe의 경로를 사용하여 내 것을 대체하십시오.

firefox.exe 또는 chrome.exe를 원하는 경로로 바꾸십시오.


패키지 제어를 사용하여 View In Browser 플러그인을 설치 하거나 github 에서 패키지를 다운로드 하고 패키지 폴더에서 패키지를 압축 해제하십시오 (패키지 찾아보기에서)

그런 다음 환경 설정, 키 바인딩-사용자로 이동하여 붙여 넣습니다.

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

이제 F12가 바로 가기 키입니다.


이것은 Sublime 3에서 작동했습니다.


Alt + L 단축키로 기본 앱으로 html 파일을 찾아 보려면 :

Preferences -> Key Bindings - User파일 여는 데 다음 줄을 추가 하십시오.

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


크롬과 같은 외부 앱으로 탐색하거나 열려면 :

이 줄을 Tools -> Build System -> New Build System...파일 열기에 추가 하고 이름으로 저장"OpenWithChrome.sublime-build"

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

그런 다음 또는 키를 선택 Tools -> Build System -> OpenWithChrome하고 눌러 파일을 찾아 F7보거나 열 수 있습니다 Ctrl+B.


FBar 를 클릭하면 브라우저에서 파일을 열 수있는 기능을 제공하는 SideBarEnhancements 플러그인을 설치할 수 있습니다 .

Chrome에서 정확하게 열려면“Side Bar.sublime-settings”파일을 수정하고로 설정 "default_browser"해야합니다 "chrome".

Sublime Text 2 에서이 비디오 자습서 를 배우는 것이 좋습니다 .


사전 정의 된 URL로 기본 브라우저를 시작하는 Windows에서 :

도구> 빌드 시스템> 새 빌드 시스템 :

{
    "cmd": ["cmd","/K","start http://localhost/projects/Reminder/"]
}

ctrl+ B와 짜잔!


여기에는 Windows 용 솔루션이 많이있는 것 같지만 가장 간단합니다.

도구-> 빌드 시스템-> 새 빌드 시스템 을 입력하고 다음과 같이 저장하십시오 Browser.sublime-build.

{
    "cmd": "explorer $file"
}

그런 다음 HTML 파일로 돌아갑니다. 도구-> 시스템 빌드-> 브라우저 . 그런 다음를 누르면 CTRL-B파일이 시스템 기본 브라우저 인 모든 브라우저에서 열립니다.


파일에 다른 브라우저를 포함하려는 경우 다른 해결책이 있습니다. 귀하와 Mac 사용자의 경우 숭고한 메뉴에서 도구> 새 플러그인으로 이동하십시오. 생성 된 코드를 삭제하고 다음을지나십시오.

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)

저장. 그런 다음 사용자 키 바인딩을여십시오. (도구> 명령 팔레트> "사용자 키 바인딩")을 목록에 추가하십시오.

{ "keys": ["alt+1"], "command": "open_browser", "args": {"keyPressed": "1"}},
{ "keys": ["alt+2"], "command": "open_browser", "args": {"keyPressed": "2"}},
{ "keys": ["alt+3"], "command": "open_browser", "args": {"keyPressed": "3"}}

이제 Sublime에서 html 파일을 열고 키 바인딩 중 하나를 사용하십시오.이 파일은 즐겨 찾는 브라우저에서 해당 파일을 엽니 다.


mac 및 sublime text 3 (버전 3103)에서 내용은 다음과 같아야합니다.

{
    "shell_cmd": "open -a 'Google Chrome' '$file'"
}

Tools -> Build System -> New Build System. The type following as your OS, save as Chrome.sublime-build

Windows OS

  {
        "cmd": ["C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "$file"]
  }

MAC Os

{
   "cmd": ["open", "-a", "/Applications/Google Chrome.app", "$file"]
}

Save the file - Chrome.sublime-build in location

C:\Users\xnivirro\Downloads\Software-Installed\Sublime-2\Data\Packages\User

Sublime View in Browswer - https://github.com/adampresley/sublime-view-in-browser (Tried with Linux and it works)


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)

And then in your keybindings:

{ "keys": ["alt+1"], "command": "open_browser", "args": {"keyPressed": "1", "localHost": "http://nbrown.smartdestinations.com", "pathToFiles":"/opt/local/apache2/htdocs"}},
{ "keys": ["alt+2"], "command": "open_browser", "args": {"keyPressed": "2", "localHost": "http://nbrown.smartdestinations.com", "pathToFiles":"/opt/local/apache2/htdocs"}},
{ "keys": ["alt+3"], "command": "open_browser", "args": {"keyPressed": "3", "localHost": "http://nbrown.smartdestinations.com", "pathToFiles":"/opt/local/apache2/htdocs"}}

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.

  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.


or try this

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

참고URL : https://stackoverflow.com/questions/8023879/sublime-text-2-keyboard-shortcut-to-open-file-in-specified-browser-e-g-chrome

반응형