"Extract Variable" in Visual Studio without ReSharper - visual-studio-2010

I don't have ReSharper at my current gig, and I miss the "Extract Variable" refactoring. I understand that it's possible to write your own refactoring "snippet" in VS. Does anybody have one that does this?

In Visual Studio 2017, if you select something, on right-click you will find a menu option "Quick Actions and Refactorings", with shortcut ctrl+..
This seems to be somewhat similar to ReSharper's ALT+Enter.
This allows you to extract a variable, as in this example where the text was selected and then ctrl+. was pressed:

Have a look at this post, but it does not seem to be a documented feature:
Snippets For Refactoring
Browse to your "Program Files\Microsoft Visual Studio 8\VC#\Snippets\language id\Refactoring" directory and you'll find the snippets used to perform the refactoring techniques in the Refactor menu. (...) If you're going to try modifying these snippets then (...)
Another way would be a write a macro using the EnvDTE programming model. Not easy, but should be feasible.

Related

Refactor on save in Visual Studio 2019

I love Prettier for VS Code. I want to do similar things in Visual Studio (2019).
It now has 'Wrap, indent, and align parameters or arguments' for example (https://learn.microsoft.com/en-us/visualstudio/ide/reference/wrap-align-indent-parameters?view=vs-2019); and I'd like to do this automatically whenever I save the file.
Does anyone know if this is possible? Or if there's a free extension that can do this?
Mads Kristensen (a Microsoft employee who makes scads of Visual Studio extensions and teaches you to too!) made a JsPrettier extension for "classic" Visual Studio (ie, not VS Code):
https://github.com/madskristensen/JavaScriptPrettier
It does not format on save if you set that up in its settings.
If it's literally Prettier in Visual Studio that you're after, this isn't a bad option.
I don't know of a free plugin but you can get quite a long way towards this with some muscle memory and the built in autoformat command.
CTRL+E, CTRL+D, CTRL+S
will do code indentation and formatting, and save the file.
If you have Resharper (sorry), there's a configurable code cleanup tool which will do what you want and CTRL+E, CTRL+F, CTRL+S will do the cleanup and save.
The Format document on Save VS extension does exactly what you want, with one exception. It automatically runs Visual Studio's code cleanup command on save.
Visual Studio's code cleanup commands covers many code style preferences and can be configured with a .editorconfig file. Unfortunately one thing that is not supported by VS yet (not counting Resharper) is line wrap preferences. There is an open ticket for this: dotnet/roslyn#33872
If and when Roslyn supports line wrap preferences (presumably as a new .editorconfig preference), then Visual Studio code cleanup will enforce it and the extension will apply it on save.

Visual Studio code completion like ctrl+k in netbeans?

My question is there code completion for Visual studio like in Netbeans where you cycle the buffer with ctrl+k, when you type something?
There's now a nice extension called Simple Autocomplete which adds one command simpleAutocomplete.next that you can map to a shortcut of your choice.
No, there isn't a similar feature in Visual Studio.
The traditional Visual Studio autocomplete is using intellisense.
When you start typing, intellisense may bring up a drop down with suggestions. In that case you can tab to complete using the current suggestion or use the arrow keys to choose another.
Ctrl-Space (or Alt-Right arrow) will bring up this intellisense menu if it's not up.
I find it does a pretty good job overall.
Some extensions like Resharper or Visual Assist offer their own code completion or other similar features (like Suggestion List for Visual Assist).
I know it's been ages since I asked this question but I found the next best thing to do this. What I would suggest is to use VsVim extension and to use Vim's anyword completion; however, in order for this work, what must be resolved is the keyboard shortcuts that conflict:
Go to "Tools options" in Visual Studio.
Then go to VsVim category(alternatively you can search "VsVim" and
should bring the options) and click keyboard.
As far as I know vim deals with this type of completion with these keys
CTRL+P and CTRL+N so what we do is to let Visual Studio give up
these keybindings and let VsVim deal with it by Selecting from the drop
down of the keys(CTRL+P and CTRL+N) and let it be "Handled by VsVim".
I hope this has helped someone out.

Find usage in Visual C++ with Visual Assist

I am using VS 2010, does Visual C++ with Visual Assist provide refactor functions on finding usage of variables? I right click the variable and the find usage function is always grey out.
Find All References in the context menu is the IDE version of the command.
To use Find References from Visual Assist, try one of:
open the "Refactoring (VA)" sub-menu of the context menu
use the default shortcut Shift+Alt+F
open the Quick Refactoring Menu with Shift+Alt+Q ("refactoring" is used loosely in this instance.)
It works for me right clicking on a variable and selecting Refactor (VA) - Find References.

Highlight all references to X?

The Eclipse IDE has a neat little feature that I really miss in Visual Studio.
If I place the cursor on a variable or method name, the IDE will automatically highlight all references to it in the current document within the relevant scope.
I can't seem to find an option to turn on similar behaviour in VS2008 or Resharper 4. I know VS has a Find Usages function, but I'd like to do it automatically on the fly.
Does anyone know of a free addin which will add this functionality?
If you're using ReSharper, you can highlight the usages in the file with Shift-Alt-F11. Place your cursor on the variable you want to find usages of, and press the Shift-Alt-F11 combination.
There is an add-in for Visual Studio that will do something similar called RockScroll.
When you double click on something, it will highlight all occurrences of the item you double clicked. It also changes the vertical scrollbar to a "syntax highlighted thumbnail view" showing an overview of where the item occurs in the file.
I know you mentioned ReSharper, but CodeRush has a nice references window that you can dock and let it search for things on-the-fly or on demand. As a bonus, you can select each usage and it will show you the context surrounding the usage. It also works for methods.
I mentioned CodeRush since they have an express edition, which looks like it includes that feature, but I haven't tried that edition.
Visual Studio 2010 has sorta implemented this, but the feature is somewhat lacking. There is a non-configurable delay between placing the cursor and highlighting.
The RockScroll Addin is not available for Visual Studio 2010 and above.
As a replacement, the free "Highlight all occurrences of selected word" plugin will highlight all occurences of the selected string after a doubleclick. There is no delay as with the native vs2010 highlighter.
It is string-based, which means it works inside comments and string literals.
Microsoft published a tool that sort of does what you want.
Some of my favourite features:
Enhanced Scrollbar
Auto Brace Completion
Ctrl + Click Go To Definition
Open Containing Folder
and the list goes on.
For Visual Studio 2010 and for Visual Studio 2012

Customizing Visual Studio's Intellisense

A recent project had me working with C# again, and I noticed something I hadn't before -- C#'s Intellisense shows possible exceptions that can be thrown when calling a method
Since I work mostly with VB.NET applications, it'd be really nice to have this feature in those applications as well, but it's unfortunately absent from VB's Intellisense
Is there any quick and easy way I can customize Visual Studio's Intellisense to show exceptions (as well as other members from the XML comments)? Or am I looking at a full modification using the SDK?
Update: 29-Sep-2008 1:49 PM -- I figure this will be more complicated than simply changing a configuration setting. Since the comments are XML-based, I was hoping for an XSLT file somewhere buried in the Visual Studio directory, but nothing has turned up so far. Looks like I'm going to have to dig into the Visual Studio SDK.
Try going to Tool -> Options...
Then Text Editor -> Basic
and make sure both options "Auto list members" and "hide advanced members" are unchecked.
Also check "Parameter information".
I cannot validate this information because my current Visual Studio installation is C# standalone.
Regards,
Luís

Resources