Since I have only 5 fingers on each hand, I prefer using Vim to develop in C++ for OpenOffice.org. I have found some tricks that help me working that I would like to share in this post. I am sorry for those coding on windows, but I don't know how all this could be transposed to window... cygwin could certainly be useful in this case.

tags

First things first, a ctags database for the whole OpenOffice.org code is mandatory: it helps to find identifiers in all this code without knowing exactly where it is defined. If this ctags base is correctly generated, it could also provide autocompletion when typing C++ code in Vim. Here is how I generate my ctags database after cd'ing into the OOo sources directory and having sourced the OOo environment:

omnicppoptions="--c++-kinds=+p --fields=+iaS --extra=+q"
ctags -h "+.hdl.hrc" --langmap=c:+.hdl.hrc.src $omnicppoptions -R --exclude=unxlngi6\.pro   
    --exclude=binfilter --exclude=solver --totals=yes --sort=foldcase *

The binfilter and solver are excluded from the indexing process to avoid having types defined twice or more as binfilter is mostly a copy of other code of OOo and the solver is the place where all the build results are delivered. Excluding the unxlngi6.pro directories avoids having duplicate types, but hides some header files generated by the build. The unxlngi6.pro exclude has to be changed according to the INPATH environment variable.

Define the tags variable in .vimrc to be able to locate the tags file wen editing a source file. Here is my definition taken from the OOo wiki:

set tags=./tags,./../tags,./../../tags,./../../../tags,./../../../../tags,./../../../../../tags,tags,../tags,../../tags,../../../tags,../../../../tags,../../../../../tags,~/tags

Now, finding a type in Vim is quite easy: I am using most of the time the vim command :ts TheTypeToFind. Using the :ta command or Ctrl-] is also possible, but the first result is not necessarily the interesting one.

Installing the OmniCppComplete plugin for Vim is also a good idea. It can be found here: http://www.vim.org/scripts/script.php?script_id=1520.

Building from Vim

There are some details about that point on the wiki page http://wiki.services.openoffice.org/wiki/Editor_Vim but I have changed it a little to make it work properly for me. Here is the part of my .vimrc for this:

set makeef=$TMPDIR/vim##.err

" Call appropriate makeprg with Ctrl+K
map  :call Make()

if $SOLARENV == ""
    " Normal makeprg, not in OpenOffice.org/StarOffice environment
    function Make()
        make
    endfun
else
    " Define the make tool.  Doesn't works with Vim: report to the OOo wiki
    set makeprg=build.pl\ debug=true

    function Make()
        let my_local_path = expand("%:h")
        if (my_local_path == "")
            let my_local_path = "."
        endif
        if filereadable( my_local_path . "/makefile.mk" )
            exec 'lcd ' . my_local_path
            call SetMakeprg()
            make
        else
            echo "No makefile.mk in " . my_local_path
        endif
    endfun
endif

" previous and next compiler error (quickfix)
map  :cp
map  :cn

To automatically deliver the build results before returning to the code, some lines needs to be added to the .vimrc file:

if has("autocmd")
    if $SOLARENV != ""
        autocmd QuickFixCmdPost make !deliver.pl 2>&1 | grep delivered
    endif
endif

Other useful commands

The next points aren't useful only for OpenOffice.org development, but also any other one. I am giving them unsorted here:

  • I often run a shell and want have the output in a buffer. Here is a Vim tip which helps for this: http://vim.wikia.com/wiki/Display_shell_commands%27_output_on_Vim_window.
  • Reading huge methods or files is often hard as its structure is hard to see. Vim has a really good folding support for C++: just run the following command or add it to the .vimrc file: set foldmethod=syntax. To open a folded part of code, place the cursor on the fold and type zo. To close it, simply type zc in the code to fold.
  • By navigating in the sources using lgrep or the tags, I often come to have a lot of opened buffers. Buffers can be closed using the bd command, the close command only closes the Vim window.
  • To indent properly some parts of the code, there is an easy way: apply the indent shell command to the current selection. I often run it like this: :'<,'>!indent -prs -i4 -nut. To avoid repeating the indent options every time, they could be set in the ~/.indent.pro. Of course, indent has much more options, but read the man page to get them all.
  • Sometime I open a Vim window like the locations window, but it opens at the bottom of the screen and I want it as a vertical split on the left. In order to do this, I simply use the Ctrl-w + H (note the uppercase H). This command and all its J, K and L friends are helping a lot to rearrange the windows.