VIM code completion under ROS

I was following this link: http://www.ros.org/wiki/IDEs to get my code completion working. On top of the plugin rosvim.vim installed, I also have OmniCppComplete. I don't get the code completion working under ROS, how should I do that? By the way, code completion for any other codes excluding ROS-related codes are just working out of the box.

Any ideas..

EDIT:

How should I tailor my ~/.vimrc file. Anyway. I've tried to add yours with the existing one like below:

Comments

Yeah, Omni completion is not very straightforward to set up. I can't speak to that particular error, but if you have a vanilla Ubuntu and ROS install, my scripts above will work. I would check over your ~/.vimrc file again and make sure you aren't doing anything "bad" elsewhere in the file.

Obviously, you would have to repeat the process for each of the directories that you keep your ROS files in. In my case, I also keep (personal) ROS stacks in ~/devel/ros, so I have an additional step to make sure that the */include/*.h files from that directory as well.

Did you mean at the end I will have two files (one for /opt/ros/diamondback/stacks and another one for /home/user/code/dev ) of ros.filelist in ~/.vim/tags/ros directory? Is my edited version of ~/.vimrc file correct (please refer to the question part, the bottom part in the "EDIT" section)?

The following .vimrc snippet is mostly from here. Visit the link to see how to create stl, qt, sdl and qt4 tags (or deactivate the "set"-lines).

The only ros-specific part is `rospack cflags-only-I` in the third line, which lists all the include directories of the ros package in which you are editing files for the ctags command (this assumes the current working dir of vim is your projects directory, see below, which btw also allows you to use :mak). With this, hitting F11 will generate completion tags for your current file's project.

In contrast to the solution of mjcarroll this creates a tagfile in your project's directory, which is specific to the dependencies of your project. Therefore you need to create the tags (F11) for each of the packages in which you are editing files. On the other hand vim should be faster looking up its tag database.

Vim's present working dir (:pwd) needs to be the root directory of your package (i.e., the output of rospack find <yourpackage>) because calling "rospack cflags-only-I" without package name argument will use the current dir as package name. This is the case if you start vim in that directory or use :cd to change there. Alternatively you could somehow (I do not know how, though) find out the package name of the project your file belongs to, to give it to the rospack call.

Comments

What do you mean by "this assumes the current working dir of vim is your projects directory, which btw also allows you to use :mak"? Is it also possible for my ros directory to be maintained in /home/user/code/dev instead of /home/user? This is because I do not want to keep my ros-related stuff the same directory as ~/.vim. Another thing is what is the use of :mak?

Edited the post to answer to your 1. question. :mak calls "make" from vim in the current dir. The output can be examined in the quickfix window (:copen). To jump to errors, double click or enter on err msg in the compiler output. Make the dir quest. a new post, hard to answer in comment w/ 300 chars

With "root directory of your package" I mean the dir you get if you type "ropack find X", where X is the name of the pkg in which you are editing files. I.e., for a current standard ros installation the root pkg dir of "tf" is "/opt/ros/diamondback/stacks/geometry/tf".

I've tried to try for tf, editing tf.cpp..so, I navigate to the root package & run the command like this as "/opt/ros/diamondback/stacks/geometry/tf$ vim src/tf.cpp ". In editing mode I've tried to edit std::, but i doesn't work..What command was probably missing? I probably need to press F5 or something like that..

Could the problem be, that you do not have write access to "/opt/ros/diamondback/stacks/geometry/tf"? Vim will try to store a file "tags" in the present working directory. Also, for completion of std:: (which is non-ros) follow the steps described in the above link.

I've run "sudo su" already..I've also tried tf::but still does not work. For f11 you mentioned is it to be run every time we want to edit our file? I've change from f11 to f5 because f11 is for minimize/maximize terminal window on my machine..

I think "sudo su" is useless, instead i just run "/opt/ros/diamondback/stacks/geometry/tf$ sudo vim src/tf.cpp". After pressing f5 I got an error message "/bin/bash: rospack: command not found
ctags: "tags" doesn't look like a tag file; I refuse to overwrite it.
shell returned 1"