Sublime TEXT3 configuration to run Python shortcuts in an interactive environment

Source: Internet
Author: User
Tags sublime text

Installing plugins

It feels good to write code under sublime Text3, but there are some problems when writing python.
Open the Python file with sublime Text3, or write the Python code under sublime Text3, use the shortcut key ctrl+b to run, and the results will appear below the current window. Like what

Print ("Hello world! ")

However, if you use a function such as input that requires interaction, Ctrl+b runs with an error

Print ("Hello world! "  = input ("pleaseinput a string:")print(x)

Run results

This problem can be solved by installing a plugin SUBLIMEREPL
On the premise that the guarantee manager is already installed (if no installation can be seen here in the "Installation Package Manager" section), press ctrl+shift+p shortcut key to call out an input box, enter the install packages, return, Enter SUBLIMEREPL in the new input box, and select Enter in the list below to start the installation, typically a few seconds to complete.
In the interface of the just Python file, click the Tools->sublimerepl->python->python run current file in the top menu bar, and it will pop up a new window like idle. and is interactive and can be entered

set shortcut keys

But every time you have to choose Tools->sublimerepl->python->python Run current file such a long list of people is definitely a headache, thinking about whether you can set shortcut keys to run. Since I used the idle to write Python, I intend to run it as a F5.

We know that the Sublime text is set through a JSON file. We open Preferences->key Binding-default can see the original shortcut key settings, is in JSON format.

You can override the default setting by opening Preferences->key Binding-user, overriding the related properties of the shortcut keys you need to set in the format above.
But the format is not easy to read, you can refer to unofficial documents

You can call this macro quickly by setting "command" to "Run_macro_file" and "args" as the file name of the recorded macro. But the attempt failed, probably because

Note that the macro buffer would remember only the latest recorded macro. ALSO, macros only record commands sent to the Buffer:window-level commands, such creating a new file, would be ignored.

Macros cannot create new windows or the like.

After a long time, on the Internet to find relevant content, research solutions
  1. Open C:\Users\xxx (your name) \appdata\roaming\sublime Text 3\packages\sublimerepl\config\python, and adjust the specific path according to your situation. AppData may be a hidden folder, you need to set the hidden folder to be visible before you can find it. open Main.sublime-menu, see inside is also JSON format. Look at it and find that it corresponds to just a few options under tools->sublimerepl->python->. The caption corresponds to the displayed name.

  2. Open the Preferences->key binding-user that you just mentioned and write the following:

    [    { "Keys": ["f5"],"caption":"Sublimerepl:python",                       "Command":"Run_existing_window_command","args":                      {                           "ID":"Repl_python_run",                           "file":"Config/python/main.sublime-menu"                      }     },]

    As you can see, the existing window command that called the ID is repl_python_run. Repl_python_run is relative to the contents of the previous Main.sublime-menu, which is the ID of the Tools->sublimerepl->python->python run current file.

    This completes the configuration of sublime Text3 similar to the idle press F5 key to run Python files in an interactive environment

Sublime TEXT3 configuration to run Python shortcuts in an interactive environment

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.