Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim c++ generate source file based on header file

I do a lot of c++ programming in vim and I was wondering if there are any plugins or snippets out there that can generate a source file depending on the contents of the header file.

I.E: test.h

class test {
public:
  test();
};

and then going into the test.cpp file and typing "src" and expanding it (using some sort of snippet plugin like UltiSnips) it would look in the test.h file for the funcions and (in this case) make:

test::test() {
  //code
}

I got this idea from Derek Wyatt's blog and he does this using XPTemplate so I thought it would be great to do the same in UltiSnips.

like image 769
Michaelslec Avatar asked Aug 15 '13 02:08

Michaelslec


2 Answers

Use the xptemplate plugin.

Examples:
http://www.derekwyatt.org/wp-content/uploads/2009/08/my.cpp.xpt.vim http://www.derekwyatt.org/vim/working-with-vim-and-cpp/cpp-snippets

like image 173
croyd Avatar answered Nov 08 '22 18:11

croyd


lh-cpp offers a :GOTOIMPL function that analyses the prototype of a given function, and either jumps to the associated definition or generates it on-the-fly. [NB: it knows what to do with virtual, static, namespace/embedded classes, return type, modifiers, and so on (except templates yet)]

Regarding how to parse a header file and generate all associated functions, the exact same question has been asked on vim mailing list 2-3 weeks ago where another solution has been given (protodef, that you have read about).

like image 38
Luc Hermitte Avatar answered Nov 08 '22 16:11

Luc Hermitte