Using Code Snippets in Visual Studio

Right now when I want to use cw snippet (code snippet for Console.WriteLn ). I type cw , Tab , Tab .

Is this the right (fastest!) Way to do this? If there was some way to just press the tab key once or any other key, I would be happy to know about it.

+7
c # visual-studio code-snippets
source share
5 answers

This is the fastest way. Please note that the first tab is just to get rid of the IntelliSense tooltip. The second tab is the one that actually does the job. In other words, you can do cw + esc/tab/enter + tab or even c + esc + w + tab . Or you can even type cw , move to another place, click immediately after cw, then tab , and it will be automatically completed.

This can be annoying if you are doing something like var cw tab .

Edit: After you used "cw", you can do it a little faster by simply typing c + tab + tab . Since you last used "cw", c will select "cw" from IntelliSense, the first tab will insert it, and the second tab will end automatically.

+5
source share

AFAIK there is no faster way to do this (but there is slower :)):

http://msdn.microsoft.com/en-us/library/z4c5cc9b(VS.80).aspx

+1
source share

With ReSharper it is cw , tab

0
source share

Just as Nelson mentioned, the 1st tab is just an escape in this case. But I know a way to shorten 1 keystroke. Save the following as "c.snippet" and put it in your directory ".. \ <myDocs> \ <VS20XX> \ Code Snippets \ Visual C # \ My Code Snippets":

 <?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>c</Title> <Shortcut>c</Shortcut> <Description>Code snippet for Console.WriteLine</Description> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> <Literal Editable="false"> <ID>SystemConsole</ID> <Function>SimpleTypeName(global::System.Console)</Function> </Literal> </Declarations> <Code Language="csharp"><![CDATA[$SystemConsole$.WriteLine($end$);]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets> 

Now you just need to type c , tab , tab !!

0
source share

There is a faster way:

The fastest way is q + Tab . I use it to register.

3 steps:

  • Create a new fragment file for q or use c + w (and skip this step)
    • C: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ VC # \ Snippets \ 1031 \ Visual C #
  • Go to Settings -> Text Editors -> C # -> IntelliSense and disable completion after 1 character
  • Enjoy it!

Hope this works for you. Definitely works for me with VS 2010 for C #.

0
source share

All Articles