Sublime Text3中repl插件快捷键绑定无效的处理

本文详细介绍了在Sublime Text 3中成功绑定REPL插件快捷键的过程,通过修改Main.sublime-menu文件,实现了Python RUN current file功能与F5键的绑定,适用于希望提高开发效率的Sublime用户。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

sublime安装repl插件后,根据网上教程进行绑定快捷键,屡屡失败。(我的版本是Sublime Text3.3)
网上教程一般是说,Default.sublime-commands文件内为绑定模板(步骤:Preferences–>Browse Packages–>SublimeREPL文件夹–>config文件夹–>Python文件夹–>Default.sublime-commands(以文本格式打开))。
然而于我的小sublime而言没有卵用,经过尝试,我选择了同一文件夹下的Main.sublime-menu文件作为绑定模板,神奇地绑定成功。
原文件如下(文件路径“sublimeREPL/config/Python/Main.sublime-menu”)

[
     {
        "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"}
                        }
                    },
                    {"command": "python_virtualenv_repl",
                     "id": "python_virtualenv_repl",
                     "caption": "Python - virtualenv"},
                    {"command": "repl_open",
                     "caption": "Python - PDB current file",
                     "id": "repl_python_pdb",
                     "mnemonic": "D",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["python", "-i", "-u", "-m", "pdb", "$file_basename"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
                    },
                    {"command": "repl_open",
                     "caption": "Python - RUN current file",
                     "id": "repl_python_run",
                     "mnemonic": "R",
                     "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"}
                        }
                    },
                    {"command": "repl_open",
                     "caption": "Python - IPython",
                     "id": "repl_python_ipython",
                     "mnemonic": "I",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "autocomplete_server": true,
                        "cmd": {
                            "osx": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
                            "linux": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
                            "windows": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"]
                        },
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {
                            "PYTHONIOENCODING": "utf-8",
                            "SUBLIMEREPL_EDITOR": "$editor"
                        }
                    }
                    }
                ]}
            ]
        }]
    }
]

我完全是根据找不同和找相似的方法(对不起我太无知),猜想不同的caption对应不同功能的绑定。我要绑定的是“Python - RUN current file”,选择对应的花括号内的代码。我想绑定到f5键,所以开头加上代码"keys":[“f5”],最终代码为:

[
	{
	"keys": ["f5"],
	"command": "repl_open",
	"caption": "Python - RUN current file",
	"id": "repl_python_run",
	"mnemonic": "R",
	"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"}
		}
	}
]

复制以上代码,粘贴到Preferences–>Key Bindings User
我的是中文版,再次对不起
亲测有效,不明所以。如果有大佬明白,跪求赐教。或者等我弄明白了,再来更新文章。

评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值