Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 Code snippet

i have managed to make a code snippet and its all good, the question is i dont want to use ctrl+k ctrl +S then click on the snippet , instead i want to use a combination of keys to just use the snippet right away , or at least pressing ctrl+k ctrl + S then another combination ?

is that possible ?

thanks in advance...

like image 314
Stacker Avatar asked Mar 06 '26 05:03

Stacker


2 Answers

If you say you're pressing Ctrl+K, Ctrl+S is because the snippet you added was a Surround With snippet, isn't it?

I suggest you installing ReSharper for this purpose. You can easily add all kind of snippets (called templates in ReSharper), and of course, Surround-With snippets.

After adding a template, you can give it the number you want.

Then all you have to do is press: Ctrl+Alt+J and you will see the following:

ReSharper templates example

And all you have to do is press the number of the snippet you want.

For example, if you want to surround some code with an if, you press: Ctrl+Alt+J, 1.

Note:
In this moment, I don't really remember if Ctrl+Alt+J is the keyboard shortcut by default, because I have changed many of them, but you can check it in ReSharper > Edit > Surround With Template...

like image 87
Oscar Mederos Avatar answered Mar 07 '26 22:03

Oscar Mederos


Easier than typing a key-combination is just typing the name+[Tab]+[Tab]. Visual Studio is pretty good at remembering the last ones used to make it even easier.

"f+[tab]+[tab]" creates a for loop snippet.

like image 35
John Arlen Avatar answered Mar 07 '26 23:03

John Arlen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!