C++ snippet support in visual studio?
Asked Answered
T

5

12

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.

Tonetic answered 7/5, 2010 at 13:55 Comment(3)
Dupe : #213134Torry
Not a dupe. This question is specifically concerning the Visual Studio Snippets feature, not snippets in general.Philipps
Short answer: no, whatsoever. VS2010 and prior will not recognise C++ snippets, and will not load ANY snippets into a C++ file. I tried creating a C++ snippet with the great little Snippy tool which creates snippet format XML. Unfortunately, VS2010 will only allow you to use snippets that correspond to the language of the source file you're edting, so C++ snippets, while valid, are ignored in VS2010. It's really odd that Microsoft didn't include adequate C++ support in Visual Studio pre-2012 - almost as if they were wishing the language away!Skeleton
P
7

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++.

Philipps answered 7/5, 2010 at 15:48 Comment(0)
V
7

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

Vassal answered 19/6, 2012 at 18:11 Comment(0)
P
5

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.

Piggott answered 11/11, 2012 at 19:58 Comment(2)
I did not figure out how to use it for three minutes and closed it. Could you maybe enlighten me on these matters?Trilobate
You can search for snippets published by someone else, or add your own snippets, so that they are saved in your bucket and can be found anywhere using VS plugin and/or web siteSelfmastery
S
4

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.

Selfabsorption answered 7/5, 2010 at 13:59 Comment(4)
I only use VS 2008 and 2010, and I don't really need support for 2008 anymore either, but it would be nice. I just wonder why, if it was implemented in an add-on tool for VS 2005, it hasn't already been integrated into the core visual studio.Tonetic
@Jeremy, your guess is as good as mine. I haven't tried the new features of 2010 yet but development of Visual C++ seems to be pretty slow.Selfabsorption
I believe someone on the Visual Studio team blogged about how they ran out of time to add it in so they just provided it as an add on since it wasn't tested.Phytohormone
These releases are not formally supported (generally the team will look for feedback and answer questions but you can’t call the tech lines). Because of this lower bar you should use them at your own risk. blogs.msdn.com/b/jasonz/archive/2010/06/07/…Phytohormone
R
1

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]:

Rosenquist answered 24/10, 2011 at 12:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.