SublimeText 3 上でブラウザへのショートカットキーを作る
Mac OS X の SublimeText 3 上で
メニューバーの [Tools] から [New Plugin] を選択して以下を追加する。
import sublime, sublime_plugin
import webbrowserclass 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)
ファイル名をつけて保存する。
次に
メニューバーの [Tools] から [Command Palette] を選択するか、[command] + [shift] + [P] のショートカットキーで
「key bindings - user」と入力して key map を開いて以下のコードを入力
[
{ "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"}}
]
最初と最後の「[](角カッコ)」は適宜追加し保存する。
これで [option] + [1] で Firefox、[option] + [2] で Google Chrome、[option] + [3] でSafari が起動する。
ちなみに、Mac のテンキーの数字では動作しない。
参考 : Sublime Text 2 keyboard shortcut to open file in specified browser (e.g. Chrome)
http://stackoverflow.com/a/22108262