VS Arduino
>> >> Great Visual Studio snippets
https://www.visualmicro.com/forums/YaBB.pl?num=1433276510

Message started by Fex on Jun 2nd, 2015 at 8:21pm

Title: Great Visual Studio snippets
Post by Fex on Jun 2nd, 2015 at 8:21pm
Hi there -


Got some awesome Visual Studio snippets to share? Post them here. The rules are simple, pick a unique snippet name and post the entire content in a code block. This makes installation easy because you can simply copy the entire content in a file in this folder:

Documents\Visual Studio 2013\Code Snippets\Visual C++\My Code Snippets

For those who don't know what these are:


Quote:
A code snippet is a block of reusable code that you can insert where you need it in your code. Snippets can be simple or more complex—for example, blocks such as try-finally and if-else are commonly used, but you could also use snippets to insert entire classes or methods.


To use a snippet, simply type in the shortcut and press TAB. If the snippet has arguments, cycle through them with TAB and insert the snippet with ENTER.

Here's a few that I made last night:

type "slb", tab and insert a Serial.begin()

Code (xml):

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>slb</Title>
      <Shortcut>slb</Shortcut>
      <Description>Code snippet inserts a Serial.begin()</Description>
      <Author>Fex</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>baudRate</ID>
          <ToolTip>Baud Rate</ToolTip>
          <Default>9600</Default>
        </Literal>
      </Declarations>
      <Code Language="cpp">
        <![CDATA[Serial.begin($baudRate$);$end$]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>


type "sla", tab and insert a Serial.available()

Code (xml):

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>sla</Title>
      <Shortcut>sla</Shortcut>
      <Description>Code snippet that inserts a Serial.available()</Description>
      <Author>Fex</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="cpp">
        <![CDATA[Serial.available();$end$]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>


type "slpl", tab and insert a Serial.println()

Code (xml):

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>slpl</Title>
      <Shortcut>slpl</Shortcut>
      <Description>Code snippet that inserts a Serial.println</Description>
      <Author>Fex</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>string</ID>
          <ToolTip>String</ToolTip>
          <Default>""</Default>
        </Literal>
      </Declarations>
      <Code Language="cpp">
        <![CDATA[Serial.println($string$);$end$]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>


If you don't use snippets yet also take a look at some of the build-in snippets. For example, you can type "if", tab to insert a full if-statement with parenthesis and accolades.

I'm looking forward to your snippets.

Title: Re: Great Visual Studio snippets
Post by Visual Micro on Jun 2nd, 2015 at 8:31pm
That's great. I had been meaning to add some facility and documentation but this is a great idea thanks.

VS Arduino » Powered by YaBB 2.6.12!
YaBB Forum Software © 2000-2024. All Rights Reserved.