You are not logged in.

#1 2007-11-15 22:48:28

syan
Member
Registered: 2006-05-20
Posts: 20

vim and omnicppcomplete - member variable woes

Hi all,

So I just started using the omnicppcomplete and supertab plugins with Vim, and this seems to be working more or less.  There's at least one thing that I think is not acting correctly though, and I'm wondering if I need to adjust some settings, or if this is a bug in the omnicomplete plugin or if it's just the way the plugin works.  So hopefully someone can help me out.

Here's what is happening:  I have a class PeopleList and it has a vector of Person objects called cPeople (i.e. vector<Person> cPeople;) and a function addPerson().  I also have a Person class that has a bunch of member variables, like name, gender, etc.  So I do PeopleList vPeople;  Now if I type vP and tab the little menu shows up and I can choose vPeople instead of typing it out the rest of the way.  And when I add the period after vPeople, the menu shows up again and I can choose either addPerson() or cPeople.  This is the way I expected it to work.  My question is, why is it that if I choose cPeople, I can't get the member variables of a Person object to show up?  Neither of these work:

vPeople.cPeople. or vPeople.cPeople[i].   When I reach the period after cPeople, I get the "OmniCompletion (^O^N^P) Pattern not found" message at the bottom of my screen.  If I do this:  vPeople.cPeople[i].gen and hit tab, gender will show up in a menu, but I can do vPeople.cPeople[i].i and tab and I'll get iostream, include, in, initializeAvailable, etc, etc...  So it doesn't seem like it's working in the correct context.

If anyone knows why this isn't working the way I want, please try to explain.  This seems like a really nice plugin, but if it doesn't work right, it's probably not worth using.

Here is my .vimrc:

set nocp incsearch
set cinoptions=0,p0,t0
set cinwords=if,else,while,do,for,switch,case
set formatoptions=tcqr
set invnumber
set noexpandtab
set softtabstop=4
set tabstop=8
set shiftwidth=4
"set foldmethod=indent
set cindent
set nowrap
let Tlist_Auto_Open = 1
let Tlist_Exit_OnlyWindow = 1
nnoremap <silent> <F8> :TlistToggle<CR>

filetype plugin on

!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q
"!--languages=c++

set completeopt=menuone,longest

syntax on

Offline

#2 2007-11-15 23:01:32

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: vim and omnicppcomplete - member variable woes

Ah omni-completion. What a pain.
The dynamic language plugins work well out of the box (self plug, hah!), but languages like C and C++ are harder to parse.

Such is the case here. This is actually the reason I gave up on c/c++ omni completion (but still use it for python, obviously).

For the record, though - do you actually have the ctags command in your vimrc? If so... get rid of it. That's a bad place to put that.

Offline

#3 2007-11-15 23:06:06

syan
Member
Registered: 2006-05-20
Posts: 20

Re: vim and omnicppcomplete - member variable woes

Thanks for the quick response.   :)

I do have the ctags command in there, although I just changed it to

map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q <CR><CR>

I tried to figure out how to put the options in the ~/.ctags file and just have !ctags -R in my .vimrc, but I was having no luck with that.  What's a better way than what I'm doing?

Considering that you gave up on the c/c++ omni completion, is this a good indication that I'm doomed?  lol

Offline

#4 2007-11-16 08:48:53

syan
Member
Registered: 2006-05-20
Posts: 20

Re: vim and omnicppcomplete - member variable woes

Well, after searching the net for a while and visiting #vim, I found this link:

http://groups.google.co.uk/group/comp.e … 4303540a4e

This hasn't totally solved my problems, but now I can get the member functions from stuff in the STL (vector, priority_queue, etc.) to show up in the menu where appropriate.  Using my previous examples, vPeople.cPeople. now triggers the menu with the proper member functions when I type the period at the end.

The thing I haven't managed to figure out yet is how to get it so that I can get the menu to come up with the proper member variables/functions for an element of my vector.  In other words, vPeople.cPeople[i]. just brings up the same menu of member functions for the vector object, instead of the member functions and variables of the ith element of the cPeople vector.

I'm going to keep trying to figure this out.  One of the guys in #vim gave me a few suggestions to look into, but I'm not sure if I'll be able to solve this or not.  I really know very little about vim and ctags and pretty much everything else involved in this.  :P  If anyone has any ideas how to solve this new part of the problem, I'd love to hear them.

Offline

#5 2007-11-16 18:07:26

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: vim and omnicppcomplete - member variable woes

syan wrote:

Considering that you gave up on the c/c++ omni completion, is this a good indication that I'm doomed?  lol

Well, more or less I just changed my thinking. When doing C, context sensitive completion isn't as important, as most things are top level functions. You can get decent functionality by using the 'complete' option and C-p/C-n

syan wrote:

The thing I haven't managed to figure out yet is how to get it so that I can get the menu to come up with the proper member variables/functions for an element of my vector.  In other words, vPeople.cPeople[i]. just brings up the same menu of member functions for the vector object, instead of the member functions and variables of the ith element of the cPeople vector.

This is a little annoying. It can't guess the return value of [] because it doesn't understand operators. Try this:

vPeople.cPeople.operator[](i).

Still, I think it's a very important skill to _not_ rely on code completion. Sure, it's helpful and all, but it can also be a hindrance, especially when learning something. Still, I wish I could get c++ completion working like the python stuff, with help text at the bottom... /me sighs

Offline

#6 2007-11-16 21:11:19

syan
Member
Registered: 2006-05-20
Posts: 20

Re: vim and omnicppcomplete - member variable woes

I just tried

vPeople.cPeople.operator[](i)

and that didn't work for me.  Was worth a try though.  I also just sent an email to the author of the plugin, so hopefully he can offer some advice.

What do you mean by the "complete" option?  I did :h omnicppcomplete and couldn't figure out which one you were talking about.

Also, when you mentioned the dynamic language plugins in your first post, what plugins were you referring to?

I'm also wondering what you meant by, "like the python stuff, with help text at the bottom."   Is that another plugin and what sort of help text appears?

Offline

#7 2007-11-17 08:47:28

Xilon
Member
Registered: 2007-01-01
Posts: 243

Re: vim and omnicppcomplete - member variable woes

He's the author of the python omnicomplete plugin. It's also one of the dynamic language plugins

Offline

#8 2007-11-18 19:43:18

syan
Member
Registered: 2006-05-20
Posts: 20

Re: vim and omnicppcomplete - member variable woes

Thanks, Xilon, I didn't realize that.  :)

Offline

#9 2007-11-19 19:20:24

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: vim and omnicppcomplete - member variable woes

syan wrote:

What do you mean by the "complete" option?  I did :h omnicppcomplete and couldn't figure out which one you were talking about.

Try :h 'complete

It's an older option - predates omnicompletion. It works well for things like C and PHP which have simpler scoping rules. I, for instance, use:

set complete=.,t,i,b,w,k

which works quite well with C.

syan wrote:

I'm also wondering what you meant by, "like the python stuff, with help text at the bottom." Is that another plugin and what sort of help text appears?

:h 'completeopt

See the "preview" setting. The C omnifunc shows the struct definition, IIRC, whereas the python plugin shows the help() entry for the member:

vNnp5

(Sorry, win32, heh)

EDIT: default C omnicompletion with 'preview' opt

http://img.phraktured.net/screenshots/s … 024044.png

Offline

#10 2007-11-19 19:26:35

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: vim and omnicppcomplete - member variable woes

Xilon wrote:

He's the author of the python omnicomplete plugin. It's also one of the dynamic language plugins

OT: I've been debating extending the framework I have setup to work with 'bracey' languages. I think I can manage simplistic parsing rules which would cover C, C++, and java in one go. It's a pipe dream of mine, but I think it can be done.

Offline

Board footer

Powered by FluxBB