Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 257
Daenyth Avatar asked Sep 29 '10 19:09

Daenyth


People also ask

How do I automatically import a Python package?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), click Editor | General | Auto Import. In the Python section, configure automatic imports: Select Show import popup to automatically display an import popup when tying the name of a class that lacks an import statement.

Can I use vim for Python?

Vim is quite a powerful text editor which can add performance to the already fast typed language Python. Vim can be highly customizable and efficient to use as it has the power of adding custom plugins and plugins managers, key mappings , and the most critical weapon of vim - Access to the terminal straight away.


1 Answers

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>
like image 52
Barthelemy Avatar answered Sep 28 '22 00:09

Barthelemy