Sublime text keybinding: Repl (python interpreter) and Terminus (cmd in sublime)

Sublime Text - WikipediaSublime text is one of the best code editor and my favourite one. Being very adapatble for your needs is the best thing. Two of the plugins that I use the most are Sublime repl and Terminus. WIthout the keybinding they lost most of their usefulness. So here are my tips to do the keybinding, that can be a bit hard to understand. This is the way to add some shortcut keys to activate the plugins. With Sublime repl, you press ctrl+b to start the code into a python interpreter inside sublime text itself, so that you do not have to open the cmd.
Sublime text editor

Sublime text is one of the best code editor and my favourite one. Being very adapatble for your needs is the best thing. Two of the plugins that I use the most are Sublime repl and Terminus. WIthout the keybinding they lost most of their usefulness. So here are my tips to do the keybinding, that can be a bit hard to understand. This is the way to add some shortcut keys to activate the plugins. With Sublime repl, you press ctrl+b to start the code into a python interpreter inside sublime text itself, so that you do not have to open the cmd.

With Terminus you can open the command line into sublime text into the same folder as root directory where you have the script. So, this saves a lot of time like Sublime repl (because for something you will need the command line, even if you have sublime repl, for example to commit to github).

Keybinding Sublime repl

If you install Sublime Repl to have a python interpreter into Sublime text you need to go into the sublime text keybinding like you see in the picture above and go copy and paste this lines into square parenthesis

    // Sublime Repl key =======================
{
        //      ctrl + b

    "keys":     ["ctrl+b"],
    "command":  "repl_open",
    "caption":  "Python - RUN current file",
    "id":       "repl_python_run",
    "mnemonic": "d",
    "args": {
            "type":         "subprocess",
            "encoding":     "utf8",
            "cmd":          ["C:/Users/giova/AppData/Local/Programs/Python/Python39/python.exe", "-u", "-i", "$file_basename"],
            "cwd":          "$file_path",
            "syntax":       "Packages/Python/Python.tmLanguage",
            "external_id":  "python",
            "extend_env": {"PYTHONIOENCODING": "utf-8"}
            }
        },

Remember to enclose the {} of the various key combination into the [] at the start and the beginning [ {“key”: ….. }].

Terminus plugin keybinding

For terminus, plugin that opens the cmd into Sublime text directly, you can use this script for the keybinding into the C:\Users\giova\AppData\Roaming\Sublime Text 3\Packages\User\Default (Windows).sublime-keymap file (your path will be similar, but not the same, of course, but do not worry, you just have to go into preferences/keybindings like you saw in the picture above).

You can use this to open the command line with alt+1

        {
        // The key press to look out for
        "keys": ["alt+1"],
        // Tell terminus to open something
        "command": "terminus_open",
        // Tell terminus what to open
        "args" : {
                // Open Command Prompt
                "cmd": "cmd.exe",
                // Provide Command Prompt with Current Working Directory
                "cwd": "${file_path:${folder}}",
                // Tell terminus to put it in the panel at the bottom of the screen
                "panel_name": "Terminus"}
    },

To be more clear, if you want both the keybindings there:

[
 
    
    // Sublime Repl key =======================
{
        //      ctrl + b

    "keys":     ["ctrl+b"],
    "command":  "repl_open",
    "caption":  "Python - RUN current file",
    "id":       "repl_python_run",
    "mnemonic": "d",
    "args": {
            "type":         "subprocess",
            "encoding":     "utf8",
            "cmd":          ["C:/Users/giova/AppData/Local/Programs/Python/Python39/python.exe", "-u", "-i", "$file_basename"],
            "cwd":          "$file_path",
            "syntax":       "Packages/Python/Python.tmLanguage",
            "external_id":  "python",
            "extend_env": {"PYTHONIOENCODING": "utf-8"}
            }
        },
        
            // This one is for terminus - cmd exe ================

        {
        // The key press to look out for
        "keys": ["alt+1"],
        // Tell terminus to open something
        "command": "terminus_open",
        // Tell terminus what to open
        "args" : {
                // Open Command Prompt
                "cmd": "cmd.exe",
                // Provide Command Prompt with Current Working Directory
                "cwd": "${file_path:${folder}}",
                // Tell terminus to put it in the panel at the bottom of the screen
                "panel_name": "Terminus"}
    },
]

Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.