Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ snippet support in visual studio?

I'm writing code in native C++ (not C++/CLR). I know that there is no built-in support for C++ with regards to the snippet manager and snipper picker interfaces, however I found a utility called "snippy" which supposedly can generate C++ snippets. Here is a c++ snippet that the program generated:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>MySnippet</Title>
      <Shortcut>MySnippet</Shortcut>
      <Description>Just a test snippet</Description>
      <Author>Me</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Declarations>
        <Literal Editable="true">
          <ID>literal1</ID>
          <ToolTip>just a placeholder</ToolTip>
          <Default>
          </Default>
          <Function>
          </Function>
        </Literal>
      </Declarations>
      <Code Language="cpp"><![CDATA[cout << "$literal1$" << std::endl;]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

If there is support in visual C++, even in a limited capacity, for C++ snippets, how do I add them to my environment, and what are the limitations? All I need is support for basic expansion snippets that I can invoke by typing a shortcut and hitting tab, and which supports basic literals that I can tab through (basically, if it supports the above snippet, I'm good). If this can't be done, are there any free add-ons or extensions to visual studio that support snippets for C++? I'm using both visual studio 2010 and 2008, but I mostly write code in 2010 right now.

like image 282
Jeremy Bell Avatar asked May 07 '10 13:05

Jeremy Bell


5 Answers

Visual Studio 2012 now includes snippet functionality for C++.

like image 152
Matthew Manela Avatar answered Sep 27 '22 17:09

Matthew Manela


You want to download and install the Microsoft Visual Studio 2005 IDE Enhancements, which provides code snippet functionality for C++. The snippet support for C++ is not as robust as it is for the other languages, in my experience.

Source is here.

like image 31
Nick Meyer Avatar answered Sep 29 '22 17:09

Nick Meyer


I'm using macros for codesnippet functionality. It's only a compromise but better then nothing

for example pressing ++n -> adds comment line // myname [DATE]:

like image 22
nobs Avatar answered Sep 28 '22 17:09

nobs


Visual Assist has a snippets feature that is not quite the same as the IDE Snippets feature. It has its pros and cons, but does work in C++.

like image 36
sean e Avatar answered Sep 26 '22 17:09

sean e


A lot of plugins available for VS2010. I suggest snip2code, new, free and pretty useful. I need a way to handle my code snippets quickly and search browsing the web... it does the job very well.

like image 28
TheHob78 Avatar answered Sep 30 '22 17:09

TheHob78