Ask Your Question
7

VIM code completion under ROS

asked 2011-03-24 08:59:13 -0500

alfa_80 gravatar image

updated 2014-01-28 17:09:25 -0500

ngrennan gravatar image

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:

syntax enable
se nu
set tabstop=4
set shiftwidth=4
set expandtab
filetype on
filetype plugin on
set nocp
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#CompleteCpp


set tags+=~/.vim/tags/ros
" OmniCppComplete settings to be tweaked
let OmniCpp_NamespaceSearch=1                                                                                         
let OmniCpp_GlobalScopeSearch=1
let OmniCpp_ShowAccess=1
let OmniCpp_MayCompleteDot=1
let OmniCpp_MayCompleteArrow=1
let OmniCpp_MayCompleteScope=1
let OmniCpp_DefaultNamespaces=["std","_GLIBCXX_STD"]
" Hotkey to generate tags for you current project
map <F5> :!/usr/bin/ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<cr>

*I've uninstalled and reinstalled the autocompletion with both methods below but still does not work

edit retag flag offensive close merge delete

Comments

Could you edit your post and set <pre> </pre> tags around the .vimrc part. Thanks Felix Endres ( 2011-03-28 04:49:15 -0500 )edit
Thanks Eric for editing that.. alfa_80 ( 2011-03-28 08:07:02 -0500 )edit

3 answers

Sort by ยป oldest newest most voted
4

answered 2011-03-24 19:13:03 -0500

mjcarroll gravatar image

To use OmniCppComplete with ROS, you have to generate a set of tags for the ROS stacks. There are probably better ways of doing this, but I was successful with find and grep.

First, generate a list of files that you want to generate tags from:

find /opt/ros/diamondback/stacks | grep -E '*/include/*/.*\.(h|hpp)' > /tmp/ros.filelist

Then use ctags to generate a tags database from this list:

ctags --sort=foldcase --c++-kinds=+p --fields=+iaS --extra=+q -f /tmp/ros.tags -L /tmp/ros.filelist

Once you have done this, you can move your tags file into your ~/.vim directory

mv /tmp/ros.filelist ~/.vim/tags/ros

And edit your ~/.vimrc file accordingly

set tags+=~/.vim/tags/ros
" OmniCppComplete settings to be tweaked
let OmniCpp_NamespaceSearch=1                                                                                         
let OmniCpp_GlobalScopeSearch=1
let OmniCpp_ShowAccess=1
let OmniCpp_MayCompleteDot=1
let OmniCpp_MayCompleteArrow=1
let OmniCpp_MayCompleteScope=1
let OmniCpp_DefaultNamespaces=["std","_GLIBCXX_STD"]
" Hotkey to generate tags for you current project
map <F5> :!/usr/bin/ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<cr>

Hope this helps.

edit flag offensive delete link more

Comments

I still got this error message: "-- Omni completion (^O^N^P) Pattern not found" What is possible solution? alfa_80 ( 2011-03-24 21:03:02 -0500 )edit
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. mjcarroll ( 2011-03-25 04:31:11 -0500 )edit
Thanks mjcarroll, kindly refer to .vimrc file that I've included in the question part. alfa_80 ( 2011-03-25 05:47:02 -0500 )edit
Since my ROS files also reside in /home/user/code/dev then I do like this instead. "find /opt/ros/diamondback/stacks | grep -E '*/include/*/.*\.(h|hpp)' > /tmp/ros.filelist && find /home/user/code/dev | grep -E '*/include/*/.*\.(h|hpp)' > /tmp/ros.filelist"..is that right that way? alfa_80 ( 2011-03-25 05:53:44 -0500 )edit
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. mjcarroll ( 2011-03-25 19:06:51 -0500 )edit
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)? alfa_80 ( 2011-03-25 19:25:50 -0500 )edit
I think it's also useful if you can check the command that I've invoked. Below is the command that I've run: (1) find /opt/ros/diamondback/stacks | grep -E '*/include/*/.*\.(h|hpp)' > /tmp/ros.filelist (2) ctags --sort=foldcase --c++-kinds=+p --fields=+iaS --extra=+q -f /tmp/ros.tags -L /tmp/ros.filelist (3) mv /tmp/ros.filelist ~/.vim/tags/ros (4) find /home/user/dev/code | grep -E '*/include/*/.*\.(h|hpp)' > /tmp/ros.filelist2 (5) ctags --sort=foldcase --c++-kinds=+p --fields=+iaS --extra=+q -f /tmp/ros.tags -L /tmp/ros.filelist2 (6) mv /tmp/ros.filelist2 ~/.vim/tags/ros alfa_80 ( 2011-03-25 20:56:15 -0500 )edit
Following the guide that I posted above, point cloud and ros:: sucessfully completes. mjcarroll ( 2011-03-26 09:01:56 -0500 )edit
2

answered 2011-03-28 04:39:50 -0500

updated 2011-03-29 05:42:54 -0500

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.

map <f12> :!ctags -R --languages=c++ --c++-kinds=+p --fields=+iaS --extra=+q .<cr>
"This is to tag the include for ros packages the current project depends on
map <f11> :!ctags -R --languages=c++ --c++-kinds=+p --fields=+iaS --extra=+q . `rospack cflags-only-I`<cr>
"map <f11> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ~/local/usr/include/<cr>
" configure tags - add additional tags here or comment out not-used ones
set tags+=~/.vim/tags/stdlibtags
set tags+=~/.vim/tags/gltags
"set tags+=~/.vim/tags/sdl
set tags+=~/.vim/tags/qt4tags
" OmniCppComplete
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_MayCompleteDot = 1
let OmniCpp_MayCompleteArrow = 1
let OmniCpp_MayCompleteScope = 1
"let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]

" automatically open and close the popup menu / preview window
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
set completeopt=menuone,menu,preview ",longest 
"END Omnicompletion

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.

edit flag offensive delete link more

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? alfa_80 ( 2011-03-28 07:24:34 -0500 )edit
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 Felix Endres ( 2011-03-28 21:34:02 -0500 )edit
Sorry for my slow getting it..Do you mean I've to navigate to ~/.vim directory, then from there I start my vim say: "vim ~/code/dev/try_node.cpp"? Am I right? alfa_80 ( 2011-03-29 04:25:21 -0500 )edit
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". Felix Endres ( 2011-03-29 04:40:13 -0500 )edit
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.. alfa_80 ( 2011-03-29 05:08:29 -0500 )edit
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. Felix Endres ( 2011-03-29 05:39:26 -0500 )edit
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.. alfa_80 ( 2011-03-29 06:00:22 -0500 )edit
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" alfa_80 ( 2011-03-29 06:04:48 -0500 )edit
0

answered 2011-04-06 20:50:48 -0500

Mine is 64 bit... Anyway, I can't imagine this to be the problem.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

Follow
6 followers

Stats

Asked: 2011-03-24 08:59:13 -0500

Seen: 1,262 times

Last updated: Apr 06 '11