sublime3自定義快捷鍵運行python,支持input()函數


總則:作為一款輕量級產品,sublime在看代碼時是非常爽的,但是通過<tool--build>運行時會出現input()函數無法讀取數據的問題.以下方法解決了input()問題,並為運行.py文件和交互環境自定義快捷鍵.

  1. 安裝SublimeREPL插件;
  2. 安裝完成之后,點擊<Tools--SublimeREPL--Python--Python-RUN current file>就可以運行.py文件(如果沒有可運行的文件會報錯);點擊<Tools--SublimeREPL--Python--Python>就可以打開Python交互環境;但是這樣明顯違背我們追求便捷的本意,所以接下來要為上面的兩個命令添加快捷鍵;
  3. 打開<Preferences--Brower Packages>,在彈出的文件夾中打開\SublimeREPL\config\Python文件夾,打開Default.sublime-commands文件,這里可以看得到步驟2中的兩個命令的模塊;
    [
     {  //這個為運行Python交互環境的模塊 "caption": "SublimeREPL: Python",
            "command": "run_existing_window_command", "args":
            {
                "id": "repl_python",
                "file": "config/Python/Main.sublime-menu" } },
    
    
        {
            "caption": "SublimeREPL: Python - PDB current file",
            "command": "run_existing_window_command", "args":
            {
                "id": "repl_python_pdb",
                "file": "config/Python/Main.sublime-menu"
            }
        },
    
        
     { // 這個是運行.py文件的模塊 "caption": "SublimeREPL: Python - RUN current file",
            "command": "run_existing_window_command", "args":
            {
                "id": "repl_python_run",
                "file": "config/Python/Main.sublime-menu" } },
    
    
        {
            "command": "python_virtualenv_repl",
            "caption": "SublimeREPL: Python - virtualenv"
        },
    
        
        {
            "caption": "SublimeREPL: Python - IPython",
            "command": "run_existing_window_command", "args":
            {
                "id": "repl_python_ipython",
                "file": "config/Python/Main.sublime-menu"
            }
        }
    ]

     

  4. 打開<Preferences--Key Bindings>,將3中兩個模塊的內容復制到User一欄,並添加自定義快捷鍵.如代碼所示
    [       
        {        
         "keys": ["f5"],//這一行是自己設的快捷鍵,其它為復制的棕色字體部分  
                
            "caption": "SublimeREPL: Python",
            "command": "run_existing_window_command", "args":
            {
                "id": "repl_python",
                "file": "config/Python/Main.sublime-menu"
            }
        }  ,
    
        {
            "keys": ["f4"],//這一行是自己設的快捷鍵,其他為復制的棕色字體部分  "caption": "SublimeREPL: Python - RUN current file",
            "command": "run_existing_window_command", "args":
            {
                "id": "repl_python_run",
                "file": "config/Python/Main.sublime-menu"
            }
        }
    
    ]   

    到這里就搞定了,關閉打開的文件,測試下,怎么樣,F4和F5是不是已經可以用了呢.再次強調,沒有可執行的.py文件的話F5運行會報錯.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM