Skip to content

Commit e6ce659

Browse files
authored
Move run selection from editing docs to Python language docs (#6178)
1 parent 903d9f2 commit e6ce659

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

docs/languages/python.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ The Python extension then provides shortcuts to run Python code using the curren
3737

3838
![Using the run python file in terminal button](images/python/run-python-file-in-terminal-button.png)
3939

40-
You can also use the **Terminal: Create New Terminal** command to create a terminal in which VS Code automatically activates the currently selected interpreter. See [Environments](#environments) below. The **Python: Start REPL** activates a terminal with the currently selected interpreter and then runs the Python REPL.
40+
You can also run individual lines or a selection of code with the **Python: Run Selection/Line in Python Terminal** command (`kbstyle(Shift+Enter)`). If there isn't a selection, the line where your cursor is on focus will be run in the Python Terminal. An identical **Run Selection/Line in Python Terminal** command is also available on the context menu for a selection in the editor. The same terminal will be used every time you run a selection or a line in the terminal/REPL, until that terminal is closed.
41+
42+
The Python extension automatically removes indents based on the first non-empty line of the selection, shifting all other lines left when needed.
43+
44+
The command opens the Python Terminal if necessary; you can also open the interactive REPL environment directly using the **Python: Start REPL** command, which activates a terminal with the currently selected interpreter and then runs the Python REPL.
4145

4246
For a more specific walkthrough and other ways of running code, see the [run code tutorial](/docs/python/python-tutorial.md#run-hello-world).
4347

@@ -93,7 +97,7 @@ The Status Bar also indicates if no interpreter is selected:
9397

9498
![Status bar showing no selected Python interpreter](images/python/no-interpreter-selected-statusbar.png)
9599

96-
The selected environment is used for IntelliSense, auto-completions, linting, formatting, and any other language-related feature. It is also activated when you run or debug Python in a terminal.
100+
The selected environment is used for IntelliSense, auto-completions, linting, formatting, and any other language-related feature. It is also activated when you run or debug Python in a terminal, or when you create a new terminal with the **Terminal: Create New Terminal** command.
97101

98102
To change the current interpreter, which includes switching to conda or virtual environments, select the interpreter name on the Status Bar or use the **Python: Select Interpreter** command.
99103

docs/python/editing.md

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,6 @@ The import suggestions list is ordered with import statements for packages (or m
106106

107107
Just like with auto imports, only top-levels symbols are suggested by default. You can customize this behavior through the `python.analysis.packageIndexDepths` setting.
108108

109-
## Run Selection/Line in Terminal (REPL)
110-
111-
The **Python: Run Selection/Line in Python Terminal** command (`kbstyle(Shift+Enter)`) is a simple way to take whatever code is selected, or the code on the current line if there is no selection, and run it in the Python Terminal. An identical **Run Selection/Line in Python Terminal** command is also available on the context menu for a selection in the editor.
112-
113-
VS Code automatically removes indents based on the first non-empty line of the selection, shifting all other lines left when needed.
114-
115-
Source code that runs in the terminal/REPL is cumulative until the current instance of the terminal is closed.
116-
117-
The command opens the Python Terminal if necessary; you can also open the interactive REPL environment directly using the **Python: Start REPL** command. (Initial startup might take a few moments especially if the first statement you run is an `import`.)
118-
119-
On first use of the **Python: Run Selection/Line in Python Terminal** command, VS Code may send the text to the REPL before that environment is ready, in which case the selection or line isn't run. If you come across this behavior, try the command again when the REPL has finished loading.
120-
121109
## Formatting
122110

123111
Formatting makes code easier to read by human beings. It applies specific rules and conventions for line spacing, indents, spacing around operators, and so on. You can view an example on the [autopep8](https://pypi.org/project/autopep8/) page. Keep in mind, formatting doesn't affect the functionality of the code itself.
@@ -156,10 +144,10 @@ In the second example, the top-level element `{based_on_style: chromium, indent_
156144

157145
If formatting fails, check the following possible causes:
158146

159-
| Cause | Solution |
147+
| Problem | Solution |
160148
| --- | --- |
161-
| The path to the python interpreter is incorrect. | Make sure you selected a valid interpreter path by running the **Python: Select Interpreter** command. |
162-
| The formatter is not installed in the current environment. |Open a command prompt, navigate to the location where your selected interpreter is, and run `pip install` for the formatter.
149+
| The formatter is not installed in the current environment. |Open a command prompt, navigate to the location where your selected interpreter is, and run `pip install` for the formatter.|
150+
| The formatter is installed in an environment but a notification is displayed saying it still needs to be installed. | You might have the wrong Python interpreter selected in your workspace. Make sure you selected a valid interpreter path by running the **Python: Select Interpreter** command. |
163151
| The path to the formatter is incorrect. | Check the value of the appropriate `python.formatting.<formatter>Path` setting. |
164152
| Custom arguments for the formatter are incorrect. | Check that the appropriate `python.formatting.<formatter>Path` setting does not contain arguments, and that `python.formatting.<formatter>Args` contains a list of individual top-level argument elements such as `"python.formatting.yapfArgs": ["--style", "{based_on_style: chromium, indent_width: 2}"]`. |
165153
| Pop up with warning message `Black does not support the "Format Select" command.` | `black` does not support formatting sections of code, it can be prevented with the following settings `"[python]": {"editor.formatOnPaste": false, "editor.formatOnSaveMode": "file"}`.|
@@ -198,7 +186,7 @@ To customize which references need to be updated, you can toggle the checkboxes
198186

199187
The Python extension supports extensions such as [isort](https://marketplace.visualstudio.com/items?itemName=ms-python.isort) and [Ruff](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) that implement the **Sort Imports** functionality. This command consolidates specific imports from the same module into a single `import` statement, and organizes `import` statements in alphabetical order.
200188

201-
You can invoke this by opening the Command Palette (`kb(workbench.action.showCommands)`) and running **Organize Imports**.
189+
You can invoke this by installing an extension that supports sorting imports, then opening the Command Palette (`kb(workbench.action.showCommands)`) and running **Organize Imports**.
202190

203191
> **Tip**: you can assign a keyboard shortcut to the `editor.action.organizeImports` command.
204192

0 commit comments

Comments
 (0)