Use Vim as a Python IDE

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 lint
  • Import packages
  • Jump to test file
  • running code
  • Code formatting
  • REPL
  • Debug <!– vim-markdown-toc –> ### Enable language layer

To add python language support in SpaceVim, you need to enable lang#python layer. Just press SPC f v d to openSpaceVim configuration file, and add following configuration:

[[layers]]
name = "lang#python"
[[layers]]
  name = "lang#python"
[[layers]] name = "lang#python"

Enter fullscreen mode Exit fullscreen mode

for more info, you can read the lang#python layer documentation.

Code completion

Base on which completion engine is used, lang#python layer load the jedi plugin automatically.The completion menu will be opened as you type.

Syntax lint

  1. neomake – Asynchronous linting and make framework for Neovim/Vim

I am maintainer of javac maker in neomake, the javac maker support maven project, gradle project or eclipse project.also you can set the classpath.

Import packages

When edit python file, you can import the package automatically, remove unused package and format package list.

pip install --user isort
pip install --user isort
pip install --user isort

Enter fullscreen mode Exit fullscreen mode

Jump to test file

SpaceVim use vim-project to manager the files in a project, you can add a .projections.json to the root of your project with following content:

{
"src/*.py": {"alternate": "test/{dirname}/{basename}Test.py"},
"test/**/Test*.py": {"alternate": "src/{}.py"}
}
{
  "src/*.py": {"alternate": "test/{dirname}/{basename}Test.py"},
  "test/**/Test*.py": {"alternate": "src/{}.py"}
}
{ "src/*.py": {"alternate": "test/{dirname}/{basename}Test.py"}, "test/**/Test*.py": {"alternate": "src/{}.py"} }

Enter fullscreen mode Exit fullscreen mode

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 windowswill be openen, the output of the script will be shown in this windows.It is running asynchronously, and will not block your vim.

Code formatting

  1. neoformat – A (Neo)vim plugin for formatting code.

For formatting java code, you also nEed have uncrustify or astyle in your PATH.BTW, the google’s java formatter also works well with neoformat.

REPL

you need to install jdk9 which provide a build-in tools jshell, and SpaceVim use the jshell as default inferior REPL process:

Debug

原文链接:Use Vim as a Python IDE

© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享
Making the absolute best of ourselves is not an easy task. It is a pleasurable pursuit...but it requires patience, persistence, and perseverance.
做最好的自己并不容易,这是很美好的愿望,需要耐心、坚持和毅力
评论 抢沙发

请登录后发表评论

    暂无评论内容