C++ Snippets

UPDATE: Go to http://github.com/derekwyatt/vim-config to get the current version of this stuff.

I’m not entirely sure where the “snippet” concept came from but it certainly appears to have been made famous by TextMate. And in the great sprit of ripping stuff off, people have gone nuts in Vim community making snippet plugins:

I’ve used four snippet template systems…

  • snippetsEmu was the first.
  • snipMate came next and improved upon snippetsEmu in a big way
  • xptemplate is what I’m using now – it’s still the best.
  • UltiSnips is a new contender that I’ve tried but it’s a bit fragile at the moment. It has some serious potential but it’s not quite there.

Some of the snippets that are included in the xptemplate plugin file you can can download below.

  • (test) Creates an entire C++ implementation file for CPPUNIT that lets you get right into coding up your test immediately.
  • (tf) Test function definition that works with the automatic registration code defined in General C++ Settings.
  • (try) Try/Catch blocks.
  • (tsp) Typedef to a std::tr1::shared_ptr.
  • (header) Creates a header file for a given class, includes the namespace (if your directory to the file is like include/name/space/goes/here), include guards, and the whole deal.
  • (src) Creates a source file with a companion to the header file. Pulls in definitions using Protodef, and also requires FSwitch.
  • … and more …

Download the snippets file here.

Download FSwitch here.

Download Protodef here.

7 comments on this post.
  1. Benny Bürger:

    Hi,

    thanks for all of your great vim-tutorials. They are really interesting and enjoyable.
    One question to your snipplet file.
    Where is XPTcontainer() defined. I looked in all of your configuration files you uploaded, but couldn’t find this function.

    Tia,
    Benny

  2. Holger:

    Hi Derek,

    I am the main author of UltiSnips and I am a bit disappointed in your evaluation of it. Could you describe more precisely what you miss in UltiSnips and have you tried one of the recent checkouts (we advanced a lot since 1.1)? I would be greatful if you tried it again; I think you will find it extremely powerful.

    Holger

  3. Derek Wyatt:

    Heya Holger,

    If memory serves correctly, my main complaint was that UltiSnips was sluggish. I would hit the key and then have to wait, and every time I hit Tab (assuming that was the key; I can’t remember) it was sluggish again. It just _felt_ bad. And since xptemplate didn’t feel bad and it wasn’t lacking any features that I wanted, there was no reason to use UltiSnips.

  4. Holger:

    Thanks for your answer! Maybe you might want to give UltiSnips another go. I for one prefer it to xptemplate, mainly because of the python interpolation which offers nifty features. But obviously I am biased. We would also much appreciate a bug report about sluggish behavior – so far, I have no one ever heard complaining about that.

  5. itti:

    Hey Derek,

    thanks for your vim articles. Unfortunately the xpt snippet file doesn’t seem to work with any recent xpt version. The function XPTcontainer() does not exist for example.

  6. Derek Wyatt:

    Yeah it’s way out of date. I’ve finally put my config up at github and will be changing my website to point there instead. http://github.com/derekwyatt/vim-config

  7. itti:

    Oh nice! Thank you again! ;)

Leave a comment