【问题标题】:Can't run py files by using hot key in sublimetext3无法在 sublimetext3 中使用热键运行 py 文件
【发布时间】:2019-08-07 11:44:12
【问题描述】:

我已经将我的 sublime3 更新到最新版本,然后我不能使用热键来运行我的 py 文件。这是我的热键配置:

[
{
    "caption": "Tmpl: Create python",
    "command": "sublime_tmpl",
    "keys": ["ctrl+alt+p"], "args": {"type": "python"}
},
{
    "keys":["f1"],
    "caption": "SublimeREPL: Python",
    "command": "run_existing_window_command", "args":
    {
        "id": "repl_python",
        "file": "config/Python/Main.sublime-menu"
    }
},
{
    "keys":["f2"],
    "caption": "SublimeREPL: Python - RUN current file",
    "command": "run_existing_window_command", "args":
    {
        "id": "repl_python_run",
        "file": "config/Python/Main.sublime-menu"
    }
},

]

当我按下 F2F1 时,什么也没有发生。

【问题讨论】:

    标签: python-3.x sublimetext3 sublimerepl


    【解决方案1】:

    Sublime Text 3 build 3200 似乎破坏了run_existing_window_command 命令。正如this answer 中提到的那样,解决方案是调用 SublimeREPL 菜单项正在使用的命令。

    如果你导航到你的 Sublime Text 3 包目录(Windows 默认为AppData/Roaming/Sublime Text 3/),你可以看到你已经安装的包。在这个目录中,如果你打开SublimeREPL/config/Python/Main.sublime-menu,你会看到一个大的 ole json 文件,看起来像这样:

    [
         {
            "id": "tools",
            "children":
            [{
                "caption": "SublimeREPL",
                "mnemonic": "R",
                "id": "SublimeREPL",
                "children":
                [
                    {"caption": "Python",
                    "id": "Python",
    
                     "children":[
                        {"command": "repl_open",
                         "caption": "Python",
                         "id": "repl_python",
                         "mnemonic": "P",
                         "args": {
                            "type": "subprocess",
                            "encoding": "utf8",
                            "cmd": ["python", "-i", "-u"],
                            "cwd": "$file_path",
                            "syntax": "Packages/Python/Python.tmLanguage",
                            "external_id": "python",
                            "extend_env": {"PYTHONIOENCODING": "utf-8"}
                            }
                        }
       <---snip--->
                    ]}
                ]
            }]
        }
    ]
    

    请注意,最里面的 children 键是带有 commands 和 args 的字典列表。我们将把它们复制到sublime-keymap 文件中并替换已经存在的commandargs。例如,您打开 python REPL 的快捷方式现在如下所示:

    "keys": ["f1"],
    "command": "repl_open",
    "args": {
        "type": "subprocess",
        "encoding": "utf8",
        "cmd": ["python", "-u", "$file_basename"],
        "cwd": "$file_path",
        "syntax": "Packages/Python/Python.tmLanguage",
        "external_id": "python",
        "extend_env": {"PYTHONIOENCODING": "utf-8"}
    }
    

    点击F1 现在应该像以前一样工作了。

    【讨论】:

    • 非常感谢我的朋友。
    猜你喜欢
    • 1970-01-01
    • 2019-06-26
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多