Can Visual Studio Automatically Expand Text with a Code Snippet? - visual-studio

In Delphi if I type "if" and space it automatically inserts the code snippet with an if statement block defined. I know in Visual Studio I can insert a snippet, but I have to either right-click and select "insert snippet", or hit CTRL-K followed by CTRL-X.
Is there a way to configure Visual Studio to automatically insert the snippet like Delphi does?

Press tab tab.

Related

How to wrap selected code in brackets/parentheses in Visual Studio 2022

In VS Code and JetBrains IDEs, when you select (highlight) a snippet of code and press an opening key for brackets ({ or [) or parentheses ((), it wraps the selected text. Visual Studio, however, deletes the selected snippet, or better, replaces it by the pressed character. Is there a way to configure it to the more intelligent behaviour of VS Code and JetBrains? I browsed "Text Editor" settings but didn't find any that seemed to do this:

Can Visual Studio block select like VS Code?

When I use block select via VS Code, I can select the following all.
Name
Country
Birthday
But with Visual Studio, I can only select rectangle area like:
Name
Coun
Birt
or (added to reply comment)
Name{get
Country{
Birthday
How to make Visual Studio work like VS Code?
Add:
I mean, with VS Code I can use shift+ctrl+right to select jagged whole words in multi-line, but Visual Studio only select a rectangle area.
Hope you looking for an "Expand selection" in VS Code alternative for Visual Studio.
As in Microsoft documentation, you can use "Shift + Alt + =" this will select the block where the cursor point and if you press multiple time then it expand to a higher level as well.
more info

Visual Studio surround with current line if nothing selected

I'm using the Surround With feature in Visual Studio with some custom code snippets. Is there a way to configure visual studio (or a custom surround snippet) to treat the entire line like it is selected, if there is currently no selection?
The same functionality is provided when you do a keyboard shortcut such as Ctrl+C, Ctrl+V etc. If you have no selected text, it performs the action on the entire line.
If someone still wants to answer this as far as doing this with Visual Studio's native functions, they can - However it was pointed out to me in a comment that resharper does this automatically. Which is something I did not realize. Seem's I'll be moving all my VisualStudio surround snippets over to Resharper Surround templates!

Visual studio 2010, how to use code snippets in a method call

I moved from Visual Studio 2008 to Visual Studio 2010.
My code snippets work good in Visual Studio 2010 on the start of a line, but not when adding parameters to a methodcall. This did work in Visual Studio 2008.
So when i type this : "DoSomeMethod([nowiwantmycodennippets!]", the code snippets are not in the intellisense list.
Does anyone know if this is a setting, or just not working anymore, and if it can be fixed?
This appears to be bug. If you type your snippet name (i.e. noiwantmycodesnippets) and press ESC to dismiss the completion list (if open), then you can press Tab to insert your code snippet. So it's just a matter of the code snippets missing from the completion list.
You can use the Control+K, Control+X key chord to show the code snippets' list also. But this isn't as nice as using it through the completion list.
Are you using ReSharper? If so, Resharper Intellisense overwrites the VS default one, so that i.e. code snippets do no appear in the completions. Try turning off ReSharper Intellisense in the ReSharper Options (Environment->Intellisense->General, choose Visual Studio).
If ReSharper Intellisense is a must, you'll have to create a ReSharper "Live Template" which opens up for "code snippets" behaviour, only ReSharper is way more advanced -- see for example this one http://www.brianlow.com/index.php/2009/04/06/resharper-live-templates-for-nunit/.
On my machine I just type "public void Test(" and than ctrl+space and type the name of my snippet. Works like a charm. I've got the C# keyboard shortcuts, I think.

Shortcut in Visual Studio 2010 to generate all possible Case's in Switch

I can't find key binding to expand all possible cases in switch,
eg. have switch with enum argument, in Borland C++ i doing this with TAB key
while switch code is selected.
I want to do this in Visual Studio 2010.
Can anyone help me?
It C++ it's not possible to do this. The IDE just doesn't have support for that operation.
In C# you can do this with the switch code snippet:
Type "switch" in the IDE which will select the snippet in intellisense
Hit Tab to insert the snippet which will move the cursor inside the parens
Type the expression to switch on and hit Enter
This will expand out the known cases into the IDE.
I had the same issue and it was duo to resharper installation which does it differently.
after entering the switch and the parameter place the curser in the switch body and then you need to click on the lamp icon on the left or clicking Alt+Enter.

Resources