3.2 KiB
title | categories | excerpt | type | comments | commentsID | ||
---|---|---|---|---|---|---|---|
Use Vim as a Python IDE |
|
A general guide for using SpaceVim as Python IDE, including layer configuration, requiems installation and usage. | BlogPosting | true | Use Vim as a Python IDE |
Blogs >> Use Vim as a Python IDE
This is a general guide for using SpaceVim as a Python IDE, including layer configuration and usage. Each of the following sections will be covered:
- Enable language layer
- Code completion
- Syntax linting
- Import packages
- Jump to test file
- running code
- Code formatting
- REPL
Enable language layer
To add Python language support in SpaceVim, you need to enable the lang#python
layer. Press SPC f v d
to open
SpaceVim configuration file, and add the following snippet to your configuration:
[[layers]]
name = "lang#python"
For more info, you can read the lang#python layer documentation.
Code completion
lang#python
layer will load the jedi plugin automatically, unless overriden in your init.toml
.
The completion menu will be opened as you type.
Syntax linting
The checkers layer is enabled by default. This layer provides asynchronous syntax linting via neomake. It will run flake asynchronously.
To install flake8, just run following command in terminal.
pip install --user flake8
Import packages
When edit Python file, you can import the package automatically, remove unused package and format package list.
pip install --user isort
Jump to test file
SpaceVim use built-in plugin to manager the files in a project,
you can add a .project_alt.json
to the root of your project with following content:
{
"src/*.py": {"alternate": "test/{}.py"},
"test/*.py": {"alternate": "src/{}.py"}
}
with this configuration, you can jump between the source code and test file via command :A
.
running code
To run current script, you can press SPC l r
, and a split window
will open, the output of the script will be shown in this window.
It is running asynchronously, and will not block your Vim.
Code formatting
The format layer is also enabled by default, with this layer you can use key binding SPC b f
to format current buffer.
Before using this feature, please install yapf.
pip install --user yapf
REPL
Start a ipython
or python
inferior REPL process with SPC l s i
. After the REPL process being started, you can
send code to inferior process. All key bindings prefix with SPC l s
, including sending line, sending selection or even
send whole buffer.