Change the installation directory of sublime's package and the use of Sublime REPL. Sublime runs node

Keywords: Attribute Python sublime Windows

Change the package installation path

By default, the sublime installation package is in the C: Users user_name AppData Roaming Sublime Text 3 directory. To change, just create a new Data folder in the sublime installation directory, restart sublime, and then install the packages under Data.
This is under the Data file after restart:

Install sublimerepl

Installation can be done with install package. The following is illustrated with the use of Python. In DataPackagesSublimeREPLconfigPython, there is a Default.sublime-commands file, which reads as follows:

[
    {
        "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"
        }
    },
    {
        "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"
        }
    }
]

You can see commands like running Python, running the current file, debugging the current file, and so on.
You can click Tools - > sublime REPL - > Python -, and then click the corresponding command to run.

This is a bit troublesome, you can set your own shortcut keys. Click on the Preferences - > Key Binding settings in the main interface. The default shortcut key is on the left side of the pop-up interface, and the custom shortcut key can be added on the right side, initially empty. On the right, put the following:

[
    {
        "keys": ["ctrl+f12"],
        "caption": "SublimeREPL: Python",
        "command": "run_existing_window_command", "args":
        {
            "id": "repl_python",
            "file": "config/Python/Main.sublime-menu"
        }
    },
    {
        "keys": ["ctrl+f5"],
        "caption": "SublimeREPL: Python - PDB current file",
        "command": "run_existing_window_command", "args":
        {
            "id": "repl_python_pdb",
            "file": "config/Python/Main.sublime-menu"
        }
    },
    {
        "keys": ["f5"],
        "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"
        }
    }
]

You can see that I added three shortcuts. Then press f5 to run the current file; press ctrl+f5 to debug the current file; press ctrl+f12 to run python. Of course, shortcuts can be arbitrary as long as they do not conflict with existing ones.

Note: You need to install python in advance and set the corresponding environment variables.

Run node

First, click Tools - > Build System to see if there is an option for node. If not, click New Build System and enter the following code in the pop-up interface:

{
    "cmd": ["node", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "working_dir": "${project_path:${folder}}",
    "selector": "source.js",
    "shell": true,
    "encoding": "utf-8",
    "windows": {
        "cmd": ["node", "$file"]
    }
}

Save it as nodejs.sublime-build. For js files, press ctrl+b to run (sublime automatically identifies the current file as a js file based on the suffix name and calls node to run, not python).

1. Note: You need to install node s in advance and set environment variables.
2. Note: The above applies to 64-bit windows. For 32-bit windows, some netizens said: If the system is not 64-bit, the cmd in the above code should be changed to

"cmd": ["taskkill /f /im node.exe >nul 2>nul & node", "$file"],

Posted by JustinM01 on Fri, 21 Dec 2018 17:57:05 -0800