4.6 KiB
title | categories | description | type | image | comments | commentsID | ||
---|---|---|---|---|---|---|---|---|
Use Vim as a Python IDE |
|
A general guide for using SpaceVim as Python IDE, including layer configuration, requiems installation and usage. | article | https://user-images.githubusercontent.com/13142418/197381840-821cc059-0aad-42fd-bc39-d5fa16a824f7.png | true | Use Vim as a Python IDE |
Blogs >> Use Vim as a Python IDE
This tutorial introduces you to SpaceVim as a Python environment,
by using the lang#python
layer, you make SpaceVim into a great lightweight Python IDE.
Each of the following sections will be covered:
- Enable language layer
- Select a Python interpreter
- Code completion
- Syntax linting
- Code formatting
- Import packages
- Jump between alternate files
- Code running
- REPL
This tutorial is not intended to teach you Python itself.
If you have any problems, feel free to join the chatting room for general discussion.
Enable language layer
The python language support in SpaceVim is provided by lang#python
layer, and it is not enabled by default.
You need to enable it in SpaceVim configuration file. Press SPC f v d
to open the SpaceVim configuration file,
and add following snippet to your configuration file.
[[layers]]
name = "lang#python"
For more info, you can read the lang#python layer documentation.
Select a Python interpreter
Python is an interpreted language, and in order to run Python code and get semantic information,
you need to tell SpaceVim which interpreter to use. This can be set with python_interpreter
layer
option. For example:
[[layers]]
name = 'lang#python'
python_interpreter = 'D:\scoop\shims\python.exe'
This option will be applied to neomake's python maker and python code runner.
Code completion
Code autocompletion is provided by autocomplete
layer, which is loaded by default.
The language completion source is included in lang#python
layer.
This layer includes deoplete-jedi
for neovim.
Syntax linting
Code Linting is provided by checkers
layer, which is also enabled by default.
There are two syntax linters enabled by default,
python and pylint, both of them run asynchronously.
To install pylint, just run following command in terminal.
pip install --user pylint
Code formatting
Code formatting is provided by format
layer, this layer is also enabled by default.
And the key binding to format current buffer is SPC b f
. The default formatter for python code is yapf.
So, before using this feature, please install yapf.
pip install --user yapf
Import packages
When edit Python file, you can import the package automatically, remove unused package and format package list.
pip install --user isort
Jump between alternate files
The alternate files manager provides a command :A
, with this command,
you can jump between alternate files within a project.
The alternate file structure can be definded in a .project_alt.json
file in the root of your project.
For example:
{
"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
.
Code running
Code running is provided by builtin code runner. 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.
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.