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:

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:

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.

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.

Social

Links

Browse content by

Copyright notice

Disclaimer

All opinions expressed in this site are my own personal opinions and are not endorsed by, nor do they represent the opinions of my previous, current and future employers or any of its affiliates, partners or customers.