Alex Rivera | Logout

How do I get auto-suggestions for array options when typing in Vim?

Asked 2011-06-18T15:05:32.143
11

enter image description here

Let's say I type

a = [1, 2]

in a .py file in vim and when I type "a." and hit TAB, I would like to get suggestion menu that is related to lists.

Edit 1 in response to Robin's comment: I think it's possible in vim, because there is a plugin that checks if a given python code is a valid code (I don't know what the plugin is called). Take a look:

enter image description here

Edit
Report

1 Answer

7

Recent versions of vim come with an omnicompletion script called pythoncomplete.

Open up a python file, and type

:set completefunc?

to check what the current completion function is. If you get back

completefunc=

then no completionfunction is currently set. You can set pythoncomplete to be the completion function by typing

:set completefunc=pythoncomplete#Complete

and you can set this to be the default for python files using (in your vimrc)

autocmd FileType python set completefunc=pythoncomplete#Complete

Now when you're in vim, you can use omnicomplete using Ctrl+X Ctrl+O and you should get a popup menu as shown below:

list completion

You can also bind this to the tab key in insert mode with (in your vimrc):

inoremap <Tab> <C-x><C-o>

To find out more about interacting with the dropdown menu that appears, try

:help ins-completion
answered 2011-06-18T15:22:13.507

Your Answer