Sublime Text3中文网

当前位置:Sublime Text3中文网 >

sublime Text3配置本机预览网址localhost

菜单 –> tools –> New Pugin

清掉内容, 添加如下代码

 import sublime, sublime_plugin
import webbrowser

url_map = {
    'E:\phpStudy\WWW' : 'http://localhost',
}

class OpenBrowserCommand(sublime_plugin.TextCommand):
    def run(self,edit):
        window = sublime.active_window()
        window.run_command('save')
        url = self.view.file_name()
        flag = False
        for path, domain in url_map.items():
            if url.startswith(path):
                url = url.replace(path, domain).replace('\\', '/')
                flag = True
                break
        if not flag:
            url = 'file://' + url
        webbrowser.open_new(url)


然后保存文件, 保存的路径类似如下:

C:\Users\XXXX\AppData\Roaming\Sublime Text 3\Packages\User\open_browser.py

XXXX 为 Windows 7 系统用户E:\phpStudy\WWW 请替换成你 Web 文档根目录所在路径


绑定快捷键

菜单 –> Preferences –> Key Bindings-User

添加如下代码

[{ "keys": ["ctrl+b"], "command": "open_browser" }]


相关阅读