Original link: https://spacevim.org/cn/layers/lang/python/
- Module Introduction
- Functional characteristics
- dependent on installation and enabling modules
- Enable module
- Grammar check
- Code formatting
- Format Imports
- Shortcut keys
- Jump to Definition
- Code generation
- Interactive programming
- Run the current script
- Organize Imports
Module Introduction
This module provides support for Python development in Spacevim, including code completion, syntax checking, code formatting, interactive programming, and debugging features.
Functional characteristics
- Code completion
- Document Lookup
- Grammar check
- Code formatting
- Interactive programming
- Code debugging
Dependent installation and Enable module enable module
You can enable the module by adding the following configuration to the configuration file:
[[layers]] name = "lang#python"
Grammar check
checkersThe module provides code-checking functionality, plus the need to install flake8 packages:
pip install --user flake8
Code formatting
The default code formatting shortcut keys are SPC b f , and need to be installed yapf . If you need to save the file automatically format the Python file, you need to set it format-on-save to true .
pip install --user yapf
Format Imports
If you need to remove unused imports more easily, you need to install Autoflake:
pip install --user autoflake
You can quickly sort the imports by installing Isort:
pip install --user isort
Shortcut keys jump to Definition
| Mode |
Key |
Description |
| Normal |
g d |
Jumps to the definition of the cursor function |
Code generation
| Mode |
shortcut Keys |
Key Description |
| Normal |
SPC l g d |
Generate DocString |
Interactive programming
Start python or ipython interactive process, shortcut keys are: SPC l s i . If an executable command exists ipython ,
The command is used as the default interactive command, otherwise the default command is used python . You can modify executable commands by setting up a virtual environment.
Transfer code to the REPL process execution:
| shortcut Keys |
Description |
SPC l s b |
Send entire file contents to REPL |
SPC l s l |
Send current line contents to REPL |
SPC l s s |
Send the selected content to REPL |
Run the current script
When editing a Python file, you can SPC l r quickly and asynchronously run the current file by using the shortcut key, and the results will be displayed in a separate execution window.
Organize Imports
| shortcut Keys |
Key Description |
SPC l i r |
Use Autoflake to remove unused guide packs |
SPC l i s |
Using Isort to sort the guide pack |
Spacevim Language Module Python