Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

introspective code completion with VIM? ... or other lightweight editor with this feature?

I've been all over the web trying to find a way to get VIM to have code completion similar to PyDev. It doesn't seem like it is possible!

-I have tried to use the omnicompletion suggested at this link: http://blog.dispatched.ch/2009/05/24/vim-as-python-ide/ .

-I have tried several addons to alleviate the problem, none work.

The "omnicomplete" functionality is NOT what I am looking for. It just takes all the words in the file you are working on and uses those to try and complete what I am doing. For example if I wrote:

import numpy
a_single_array = range(100)
np.a#[then I hit cntrl+n to code complete]

It would spit out "a_single_array" as a possible completion -- but that is absurd! That is not a valid completion for "numpy.a ..."

What is the issue here? All the addon would have to do is run a dir(work you want to find) from the folder you are in and then filter the output! This cannot be that difficult! (I suppose you would also have to read the file you are currently editing and filter that as well to take note of name changes... but that's pretty much it!)

Speaking of how easy it would be... if there isn't anything already made, I was thinking of writing the script myself! Any guides on how to do THAT?

like image 504
Garrett Berg Avatar asked Sep 09 '11 19:09

Garrett Berg


3 Answers

No, the omni completion functionality is EXACTLY what you are looking for.

You are using <C-n> instead of <C-x><C-o>:

  • type <C-n> & <C-p> to complete with words from the buffer (after and before the cursor respectively)
  • type <C-x><C-o> to complete method/properties names

It's specifically explained in the article you linked:

In V7, VIM introduced omni completion – given it is configured to recognize Python (if not, this feature is only a plugin away) Ctrl+x Ctrl+o opens a drop down dialog like any other IDE – even the whole Pydoc gets to be displayed in a split window.

like image 103
romainl Avatar answered Oct 07 '22 01:10

romainl


Ctrln is insert-completion.

Ctrlx Ctrlo is omni-completion.

I remap omnicompletion to CtrlSpace:

inoremap <C-Space> <C-x><C-o>

You could also try SuperTab.

like image 26
idbrii Avatar answered Oct 07 '22 00:10

idbrii


I have no idea about the various completion options for Python in Vim. But if you want to roll your own you'd be well advised to study and modify one of the existing ones, like this:

http://www.vim.org/scripts/script.php?script_id=1542

Also, if all your omnicompletion is doing is listing words in current file then you don't have it set up properly for Python-specific completion. . . . Not sure how good the specialized Python completion systems get, but they certainly does compete based on Python units external to your current file. . . .

like image 29
Herbert Sitz Avatar answered Oct 07 '22 02:10

Herbert Sitz