Since I have only 5 fingers on each hand, I prefer using Vim to develop in C++ for 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.


First things first, a ctags database for the whole 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 directories avoids having duplicate types, but hides some header files generated by the build. The 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:

Building from Vim

There are some details about that point on the wiki page 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 environment
    function Make()
    " Define the make tool.  Doesn't works with Vim: report to the OOo wiki
    set\ debug=true

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

" 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 ! 2>&1 | grep delivered

Other useful commands

The next points aren't useful only for 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:
  • 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 ~/ 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.