Tuesday, February 8, 2011

Why vim not search STL headers?

In vim it is common to open a header in place, which is really a handy feature for browsing a directory hierarchy.

But you might find this functionality seems to fail with C++ STL headers : when the cursor is blinking under "#include <iostream>", say, and your hitting 'gf' will not respond by entering that header but engender a grouch like following instead:

"E447: Can't find file iostream in path".

In actuality it is quite easy to resolve this problem by riffling through vim manual.

Treatment:

open the rc file of vim, for instance, /etc/vimrc, add following setting :

set path = **,/usr/include/c++/**

provided your c++ STL headers are hoarded in /usr/include/c++.

reopen the source code you were previously browsing around and try "gf" again, it should work now! It is really that piece of cake!  Really extensible is vim!

remove empty line by sed or in vim

In vim, following the same trick for general sustitution:
:%s/^[\ \t]*\n//g 

By sed on the command line:
cat orgfile | sed /^$/d