Is there a plugin for vim to auto-import python libraries? [closed]

心不动则不痛 提交于 2019-12-18 10:55:10

问题


In eclipse you can hit Ctrl+Shift+o to automatically import all the libraries you reference in your code. Is there any similar plugin for vim to have this feature with python?


回答1:


There is ropevim. It is available on pypi as well

The autoimport (adds missing imports) and organizeimport (reorder imports) features work well, but it is a little invasive at times (it will create a .ropeproject folder in your project). Rope code completion is also quite good so I use standard code completion with tab, and when it's not enough, I use ctrl-space to use ropevim autocompletion.

Here are some of my mappings with ropevim:

" Rope AutoImport and OrganizeImport
nnoremap <C-S-o> :RopeOrganizeImports<CR>0<CR><CR>
nnoremap <C-S-i> :RopeAutoImport<CR>

" Rope AutoComplete
let ropevim_vim_completion = 1
let ropevim_extended_complete = 1
let g:ropevim_autoimport_modules = ["os.*","traceback","django.*","lxml.etree","lxml.*"]
imap <c-space> <C-R>=RopeCodeAssistInsertMode()<CR>

" Rope Menu
menu Python.Create\ Package :RopeCreatePackage<CR>
menu Python.Create\ Module :RopeCreateModule<CR>



回答2:


There is a command line tool called mr.igor that you could install. There are instructions for hooking it up to vim on the pypi page:

http://pypi.python.org/pypi/mr.igor




回答3:


I'm using https://github.com/mgedmin/python-imports.vim together with gutentags. Good enough for me (and better than nothing).



来源:https://stackoverflow.com/questions/3825073/is-there-a-plugin-for-vim-to-auto-import-python-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!