• sublime text3开发python并设置快捷键


    Package Control 安装方法

      1.通过快捷键 ctrl+` 或者 View > Show Console 打开控制台,然后粘贴相应的 Python 安装代码;

      2.Sublime Text 3 安装代码并回车:

    import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())

      3.重启Sublime Text 3;

      4.如果在Perferences->package settings中看到package control这一项,则安装成功。

    用Package Control安装插件的方法:

    1. 按下Ctrl+Shift+P调出命令面板
    2. 输入install 调出 Install Package 选项并回车,然后在列表中选中要安装的插件。如图:
    3. CTRL+B 运行 py文件 

    安装sublimeREPL插件:

         1.在已经安装了包管理器的前提下(如果没有安装可以看这里的”安装包管理器”部分),按ctrl+shift+p快捷键呼出一个输入框,输入Install Package,回车,在新出现的输入框里输入SublimeREPL,在下面的选择列表中选中回车就会开始安装,一般几秒钟就能装完。 
         2.直接下载解压到packages目录下:https://github.com/wuub/SublimeREPL

    运行测试:

          在刚刚的python文件的界面里点击上方菜单栏的tools->sublimeREPL->python->python run current file,这时候就像IDLE一样,会弹出一个新的窗口,而且是可交互的,可以输入:
    通过菜单栏运行
    运行结果1 
    运行结果2

    设置快捷键:

          1.Sublime Text是通过json文件进行设置的。我们打开preferences->Key Binding-Default就能看到原来的快捷键的设置,是json格式。
          2.在Data/packages/下找到刚刚下载解压的REPL/config/python/Main.sublime-menu.打开可以看见你需要的命令参数。DataPackagesSublimeREPL-masterconfigPythonMain.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"
                            }
                        }
                        }
                    ]}
                ]
            }]
        }
    ]
          3.在preferences->Key Binding-User,写入以下内容:
    {"keys": ["f9"],"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"}
                            }
    	}

    测试:


  • 相关阅读:
    asp读书笔记(二)内置对象
    网上收集的关于iframe的自适应高度代码js的
    第一遇到地震,虽然小点
    给网友写的控制页面元素高度的代码(js)
    给用户控件添加可枚举的属性
    标记(Tagging)能给网站带来的7大益处
    代码最重要的读者不再是编译器、解释器或者电脑,而是人!
    亚洲超大数据库会议(XLDB Asia 2012)
    每年15万美元!这是开发人员解决构造问题的总成本!
    华章IT图书书讯(2012年第7期)
  • 原文地址:https://www.cnblogs.com/jasonhaven/p/7355003.html
Copyright © 2020-2023  润新知