Use Vim as a Python IDE

I love vim and often use it to write Python code. Here are some useful plugins and tools for building a delightful vim python environment, escpecially for Vim8:

我喜欢vim,经常用它来编写Python代码。以下是一些有用的插件和工具,用于构建令人愉快的vim-python环境,尤其是vim8:

As you can see, tmux is also one of my favourite tools in terminal.

如您所见,tmux也是我在终端中最喜欢的工具之一。


Syntax Checking

If you use Vim8, w0rp/ale is a better option than syntastic, for it utilizes the async feature in Vim8, you will never get stuck due to the syntax checking. It’s similar to flycheck in emacs, which allows you to lint while you type.

如果您使用Vim8, w0rp/ale是比syntastic更好的选择,因为它利用了Vim8中的异步特性,您永远不会因为语法检查而被卡住。它类似于emacs中的flycheck,允许您在键入时进行lint。

(taken from ale)


Code Formatter

google/yapf can be used to format python code. Make a key mapping as bellow, then you can format your python code via <LocalLeader> =.

可以使用google/yapf格式化python代码。将键映射设置为bellow,然后可以通过' = '格式化python代码。

autocmd FileType python nnoremap <LocalLeader>= :0,$!yapf<CR>

You can also take a look at Chiel92/vim-autoformat.


Sort Import

timothycrosley/isort helps you sort imports alphabetically, and automatically separated into sections. For example, use <LocalLeader>i to run isort on your current python file:

timothycrosley/isort帮助您按字母顺序对导入进行排序,并自动将其分成几个部分。例如,使用' i '在当前python文件上运行isort:

autocmd FileType python nnoremap <LocalLeader>i :!isort %<CR><CR>

Or you can use its vim plugin: fisadev/vim-isort.

Update: ALE now has a command ALEFix for autofixing. Concerning code formatter and sort import, you could do that by merely configuring ALE properly. I’d love to put these in ftplugin/python.vim:

ALE现在有一个命令' ALEFix '用于自动修复。关于code formatter和sort import,您可以通过正确配置ALE来实现这一点。我想把这些放到ftplugin/python.vim:

let b:ale_linters = ['flake8']
let b:ale_fixers = [
\ 'remove_trailing_lines',
\ 'isort',
\ 'ale#fixers#generic_python#BreakUpLongLines',
\ 'yapf',
\] nnoremap <buffer> <silent> <LocalLeader>= :ALEFix<CR>

If you want to fix files automatically on save:

如果你想修复文件自动保存:

let g:ale_fix_on_save = 1

Now you have the support of syntax checking and autofixing with one ALE! As a matter of fact, ALE also has a plan to support auto-completion via LSP. Keep watching this amazing project if you are interested.

现在,您已经支持语法检查和自动修复与一个ALE!事实上,ALE还计划通过LSP支持自动完成。如果你感兴趣,请继续观看这个精彩的项目。


Auto Completion

Valloric/YouCompleteMe is a good way to provide code auto completion. It has several completion engines, aside from Python, C, C++, Rust, Go and Javascript are also supported. Whereas a bunch of people also think YCM is too huge and need to be compiled, then jedi-vim is an alternative. They all use jedi as their backend.

(from jedi-vim)

What’s more, I know many people use Shougo/deoplete.nvim. Thanks to the async API, some more hopeful completion plugins are borned:

maralla/completor.vim is an code completion framework for Vim8, and support NeoVim too.

roxma/nvim-completion-manager also provides experimental support for Vim8.

roxma/nvim-completion-manager 还为Vim8提供了实验支持。

prabirshrestha/asyncomplete.vim is a fork of nvim-completion-manager in pure vim script with python dependency removed.

prabirshrestha/asyncomplete.vim是纯vim脚本中的一个nvim- completemanager分支,去掉了python依赖项。



(from NCM)

Update: Unfortunately, NCM is not maintained any more.

更新:**不幸的是,[NCM](https://github.com/roxma/nvim-comple-manager/issues/12# issuecom-382334422)不再维护了。

Update again: ncm2, the successor of NCM, comes out! coc.nvim is also promising.


Quick Run

If use Vim8, you can execute python file asynchronously by skywind3000/asyncrun.vim and output automatically the result to the quickfix window like this:

如果使用Vim8,您可以通过skywind3000/asyncrun.vim异步执行python文件,并将结果自动输出到quickfix窗口,如下所示:

" Quick run via <F5>
nnoremap <F5> :call <SID>compile_and_run()<CR> function! s:compile_and_run()
exec 'w'
if &filetype == 'c'
exec "AsyncRun! gcc % -o %<; time ./%<"
elseif &filetype == 'cpp'
exec "AsyncRun! g++ -std=c++11 % -o %<; time ./%<"
elseif &filetype == 'java'
exec "AsyncRun! javac %; time java %<"
elseif &filetype == 'sh'
exec "AsyncRun! time bash %"
elseif &filetype == 'python'
exec "AsyncRun! time python %"
endif
endfunction " Deprecated:
" augroup SPACEVIM_ASYNCRUN
" autocmd!
" " Automatically open the quickfix window
" autocmd User AsyncRunStart call asyncrun#quickfix_toggle(15, 1)
" augroup END
"
" asyncrun now has an option for opening quickfix automatically
let g:asyncrun_open = 15

For neovim, neomake/neomake is worthy of trying. Here is the description from neomake’s README:

对于neovim, neomake/neomake值得一试。以下是neomake的自述:

It is intended to replace the built-in :make command and provides functionality similar to plugins like syntastic and dispatch.vim. It is primarily used to run code linters and compilers from within Vim, but can be used to run any program.

Another approach is to use TMUX. The idea is simple: it can split your terminal screen into two. Basically, you will have one side of your terminal using Vim and the other side will be where you run your scripts.

PS: 另一种方法是使用TMUX。这个想法很简单:它可以把你的终端屏幕一分为二。基本上,终端的一端使用Vim,另一端运行脚本。


Enhance the default python syntax highlighting

python-mode/python-mode provides a more precise python syntax highlighting than the defaults. For example, you can add a highlighting for pythonSelf .

python-mode/python-mode提供了比默认值更精确的python语法高亮显示。例如,您可以为“pythonSelf”添加高亮显示。

hi pythonSelf  ctermfg=68  guifg=#5f87d7 cterm=bold gui=bold

For more customized python syntax highlightings, please see space-vim-dark theme and syntax/python.vim in python-mode/python-mode . You can also put them after color command.

更多定制的python语法高亮显示,请参见[space-vim-dark主题](https://github.com/liuchengxu/spacevim-dark/blob/aea40e6518a569911a63e9c41104d27e/colors/spacevim-dark.vim #L318-L337)和syntax/python。vim in python-mode/python-mode。你也可以把它们放在颜色命令之后.

Actually, python-mode contains tons of stuff to develop python applications in Vim, e.g., static analysis, completion, documentation, and more. (But personally, I prefer to obtain the functionalities by some other better plugins.)

实际上,python模式包含了大量在Vim中开发python应用程序的内容,例如静态分析、完成、文档等等。(但就我个人而言,我更喜欢通过一些更好的插件来获得这些功能。)


Python text objects

vim-pythonsense provides text objects and motions for Python classes, methods, functions, and doc strings.

vim-pythonsense为Python类、方法、函数和doc字符串提供文本对象和运动。


LSP

The concept of Language Server Protocol has been around for quite a while, many languages already have a decent LSP support. So far LSP is the only way to bring in various features similar to IDE for the text editors in a standard way. To do that, you need to install the correspoding language server and a LSP client to interact with it.

*Language Server Protocol的概念已经存在很长一段时间了,许多语言已经有了不错的LSP支持。到目前为止,LSP是以标准方式为文本编辑器引入各种类似IDE的特性的惟一方法。为此,您需要安装correspoding语言服务器和一个LSP客户机来与之交互。*

Vim LSP client Implementation Support
LanguageClient-neovim Rust vim/neovim
ale VimL vim/neovim
vim-lsp VimL vim/neovim
neovim’s built-in LSP support Lua neovim only

LCN implements the LSP client in Rust, so it obviously has an outstanding performance compared to others written in vimscript or lua. Most LSP clients are usable now, but far from perfect:

LCN在Rust中实现了LSP客户机,因此与其他使用vimscript或lua编写的客户机相比,LCN显然具有出色的性能。大多数LSP客户端现在都是可用的,但还远远不够完美:

  • simple and crude UI
  • poor performance

Still a long way to go

Use Vim as a Python IDE的更多相关文章

  1. Ubuntu下将vim配置为Python IDE(转)

    工欲善其事,必先利其器. 配置好了Django的环境,该把vim好好配置一下当做python的IDE来用. 在Windows下用惯了各种现成的工具,转到Linux下,一下没了头绪……好歹google出 ...

  2. Vim as a Python IDE

    参考视频:http://v.youku.com/v_show/id_XNDY4NTM4NzY0.html 好的,在我们默认的centos6的操作系统中使用的python2,我们一般会再去安装一个pyt ...

  3. 两个命令把 Vim 打造成 Python IDE

    运行下面两个命令,即可把 Vim(含插件)配置成 Python IDE.目前支持 MAC 和 Ubuntu. Shell   curl -O https://raw.githubusercontent ...

  4. centos6.5下Python IDE开发环境搭建

    自由不是想做什么就做什么,而是想不做什么就不做什么.        ---摘抄于2016/11/30晚 之前学习了一段时间的Python,但所有部署都在windows上.正赶上最近在学习liux,以后 ...

  5. vim as python IDE

    参照Martin Brochhaus大神的视频,今天我也尝试了一下配置vim python IDE以后使用过程中只需要https://github.com/wyj1239630590/vim-as-a ...

  6. 10 款最好的 Python IDE

    Python 非常易学,强大的编程语言.Python 包括高效高级的数据结构,提供简单且高效的面向对象编程. Python 的学习过程少不了 IDE 或者代码编辑器,或者集成的开发编辑器(IDE).这 ...

  7. 【转】手把手教你把Vim改装成一个IDE编程环境(图文)

    手把手教你把Vim改装成一个IDE编程环境(图文) By: 吴垠 Date: 2007-09-07 Version: 0.5 Email: lazy.fox.wu#gmail.com Homepage ...

  8. python IDE

    提供给开发者 10 款最好的 Python IDE http://www.oschina.net/news/57468/best-python-ide-for-developers vim windo ...

  9. Vim配置及说明——IDE编程环境

    Vim配置及说明——IDE编程环境 Vim配置及说明——IDE编程环境 1.基本及字体 2.插件管理 3.主题风格 4.窗口设置 5.目录树导航 6.标签导航 7.taglist 8.多文档编辑 9. ...

随机推荐

  1. Keepalived+Nginx实现负载均衡高可用

    一.负载均衡高可用 Nginx作为负载均衡器,所有请求都到了Nginx,可见Nginx处于非常重点的位置,如果Nginx服务器宕机后端web服务将无法提供服务,影响严重. 为了避免负载均衡服务器的宕机 ...

  2. (转)NHibernate各种数据库配置写法

    本文转载自:http://blog.csdn.net/hsg77/article/details/23463733 //NHibernate各种数据库连接参数文件配置方法说明 //配置文件Config ...

  3. 引用 WCF 服务后,没有生成任何 .datasource?

    如题WCF服务生成成功,在添加服务引用的时候也不报错,但是添加完成之后不能正常调用服务借口. 在重新引用服务的时候,或者是是更新引用服务的时候,点“高级”按钮,在服务引用设置对话框中,将“重新使用引用 ...

  4. canvas渐变

    代码: 1 /** 2 * Created by Administrator on 2016/1/29. 3 */ 4 function draw(id){ 5 var canvas = docume ...

  5. throw和throws的区别和联系

    突然发现今天诗兴大发,看来又得写点内容了. throw和throws对于Java程序员而言它们真的不是很陌生.但对于我这样的选手而言一提到它们的区别和联系就蒙圈了... 为了以后不蒙圈,今天就研究一下 ...

  6. 腾讯Web前端开发框架JX(Javascript eXtension tools)

    转自:Web前端开发-Web前端工程师 » 腾讯Web前端开发框架JX(Javascript eXtension tools) JX – Javascript eXtension tools 一个类似 ...

  7. qq图片选择效果的处理

    QQ中图片鼠标一选择,整个图片就像加了个阴影一样,这个效果一般人都不会注意,突然没事测试了一下,原来qq是把原来每个像素的颜色变成了相反的颜色. 电脑中的三原色为0-255,中间值为128,以中间值为 ...

  8. android 定位的几种方式介绍

    [地理位置] android 定位的几种方式介绍 开发中对于地图及地理位置的定位是我们经常要用地,地图功能的使用使得我们应用功能更加完善,下面 www.androidkaifa.com 总结了一下网络 ...

  9. HTML5实用知识点

    本文讲解HTML5实用知识点 新增的表单type Canvas使用 SVG使用 Audio使用 Video使用 网页缓存 文件缓存 后台worker Server-Sent Events 定位 拖放功 ...

  10. 包学会之浅入浅出Vue.js:开学篇

    2016年,乃至接下来整个2017年,如果你要问前端技术框架什么最火,那无疑就是前端三巨头:React.Angular.Vue.没错,什么jQuery,seaJs,gulp等都逐渐脱离了热点.面试的时 ...