Map keybind to specific snippet - SQL Management Studio / Visual Studio - visual-studio-2010

I review a lot of code and I want to put brackets around certain text elements that lacks them. So far I've been been doing the following:
1) Highlighting the text element I want to put brackets around (only one highlight at a time)
2) Hit ctrl-k + ctrl-s to invoke the "Surrond With..." shortcut (see Edit->IntelliSense->Surround With...
3) Find my "insert bracket" code snippet and then hitting enter
I want to keybind a specific snippet to do this in one go (just like when you are commenting out a block using the keybind ctrl-k + ctrl-c. Is this possible?
This question is smiliar to Assign code snippet to keyboard shortcut in Visual Studio but its not marked as answered. Can anyone help confirm that its not possible or whether another work-around is possible.

Related

Change variable name in multiple lines in visual studio

So, I have some code for a Rect variable mageSection:
And I'd like to copy the same code for a different variable warriorSection. To achieve this:
So I'd like to know if there is a visual studio shortcut for allow you to change variable name in multiple line in visual studio without refactoring the whole variable name.i.e. I don't have to manually change those names from mageSection to warriorSectionfor these 4 lines.
It is a question about shortcut in visual studio rather than writing functions, as I'd like to know the shortcut for this. Many thanks!
Copy and paste the section of code.
Now select the pasted code and hit Ctrl-H to bring up the Quick Replace dialog.
In the top box, type "mageSection".
In the bottom box, type "warriorSection".
Hit Enter and it will find the first occurrence and replace it.
Hit Enter three more times...done.
If I'm understanding your question correctly you should be able to hold down alt while clicking into multiple lines and change them all at once. Then hit ESC to exit multiline editing.

Does Visual Studio or Resharper have an auto-completion overwrite feature similar to Eclipse?

Sometimes I'll have classes/methods/variables with similar naming. For example, GetABar() and GetAFooWithABar() (assuming for the sake of example that these aren't horrible names to begin with).
I get into situations where I want to change one of the calls from the former to the latter, and when I start typing in the middle of the name, I'll get an auto-complete suggestion. If I select the suggestion, the following results:
GetAFooWithABarABar()
In Eclipse, there's a handy feature called completion overwrite which you can set as a default, or select on the fly by holding down Ctrl when you select the suggested term. Does Visual Studio or Resharper have a similar feature?
In ReSharper, you get a different result if you complete with Enter or Tab. If you hit Enter, it will insert the text, as you describe above. But if you hit Tab, it will replace the text to the right of the text caret, and should give you the result you're after.

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...
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:
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...
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.
In your code snippet file, you can set up a shortcut element. Your code snippets are located under(depending on language):
"\Documents\Visual Studio 2010\Code
Snippets\Visual C#\My Code Snippets"
Under the CodeSnippet\Header\Shortcut section in the code snippet file, type a unique short relevant series of characters.
<CodeSnippet>
<Header>
<Shortcut>spi</Shortcut>
</Header>
Typing these characters followed by tab in the code window will insert your code snippet.

Save searches in Visual Studio

Is there a way to save a search information in Visual Studio. For example if I'm constantly searching for "This string", match case, match whole word, look in 'Current Project'. Can I store this somehow as a saved search?
This is easy to do with a macro. Start with Tools + Macros + Record. Do a search, setting all the options you want, click Stop Recording. View + Other Windows + Macro Explorer. Rename the "TemporaryMacro" to something more suitable. Tools + Customize + Keyboard and assign a keystroke to the macro.
You now have a single keystroke to execute the search.
I found that if you do the following in VS2012:
1) Copy and paste the file types list back into the "Look at these file types" search box
2) Click and unclick the "Use Regular Expressions" checkbox
3) Press "Find Next" before "Find All"
4) Close visual studio and reopen the solution
For the actual search string I think if you make sure your cursor is positioned on a blank line, it will also reuse the last search string, otherwise it will pick the string under the cursor.
Then (at least VS2012) will remember the last search options. You may or may not also need to click your heels and perform some voodoo magic that i was doing at the time on the side (that part is a secret, sorry)

Hidden Features of Visual Studio (2005-2010)?

Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
Visual Studio is such a massively big product that even after years of working with it I sometimes stumble upon a new/better way to do things or things I didn't even know were possible.
For instance-
Crtl + R, Ctrl + W to show white spaces. Essential for editing Python build scripts.
Under "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\Text Editor"
Create a String called Guides with the value "RGB(255,0,0), 80" to have a red line at column 80 in the text editor.
What other hidden features have you stumbled upon?
Make a selection with ALT pressed - selects a square of text instead of whole lines.
Tracepoints!
Put a breakpoint on a line of code. Bring up the Breakpoints Window and right click on the new breakpoint. Select 'When Hit...'. By ticking the 'Print a message' check box Visual Studio will print out a message to the Debug Output every time the line of code is executed, rather than (or as well as) breaking on it. You can also get it to execute a macro as it passes the line.
You can drag code to the ToolBox. Try it!
Click an identifier (class name, variable, etc) then hit F12 for "Go To Definition". I'm always amazed how many people I watch code use the slower right-click -> "Go To Definition" method.
EDIT: Then you can use Ctrl+- to jump back to where you were.
CTRL+SHIFT+V will cycle through your clipboard, Visual Studio keeps a history of copies.
Sara Ford covers lots of lovely tips: http://blogs.msdn.com/saraford/archive/tags/Visual+Studio+2008+Tip+of+the+Day/default.aspx
But some of my favourites are Code Snippets, Ctrl + . to add a using <Namespace> or generate a method stub.
I can't live without that.
Check out a great list in the Visual Studio 2008 C# Keybinding poster: http://www.microsoft.com/downloadS/details.aspx?familyid=E5F902A8-5BB5-4CC6-907E-472809749973&displaylang=en
CTRL-K, CTRL-D
Reformat Document!
This is under the VB keybindings, not sure about C#
How many times do you debug an array in a quickwatch or a watch window and only have visual studio show you the first element? Add ",N" to the end of the definition to make studio show you the next N items as well. IE "this->m_myArray" becomes "this->m_array,5".
Incremental search: While having a source document open hit (CTRL + I) and type the word you are searching for you can hit (CTRL + I) again to see words matching your input.
You can use the following codes in the watch window.
#err - display last error
#err,hr - display last error as an HRESULT
#exception - display current exception
Ctrl-K, Ctrl-C to comment a block of text with // at the start
Ctrl-K, Ctrl-U to uncomment a block of text with // at the start
Can't live without it! :)
Stopping the debugger from stepping into trivial functions.
When you’re stepping through code in the debugger, you can spend a lot of time stepping in and out of functions you’re not particularly interested in, with names such as GetID(), or std::vector<>(), to pick a C++ example. You can use the registry to make the debugger ignore these.
For Visual Studio 2005, you have to go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio \8.0\NativeDE\StepOver and add string values containing regular expressions for each function or set of functions you wish to exclude; e.g.
std::vector.*::.*
TextBox::GetID
You can also override these for individual exceptions. For instance, suppose you did want to step into the vector class’s destructor:
std::vector.*::\~.*=StepInto
You can find details for other versions of Visual Studio at http://blogs.msdn.com/andypennell/archive/2004/02/06/69004.aspx
Ctrl-F10: run to cursor during debugging. Took me ages to find this, and I use it all the time;
Ctrl-E, Ctrl-D: apply standard formatting (which you can define).
TAB key feature.
If you know snippet key name, write and click double Tab. for example:
Write
foreach
and then click tab key twice to
foreach (object var in collection_to_loop)
{
}
2. If you write any event, write here
Button btn = new Button();
btn.Click +=
and then click tab key twice to
private void Form1_Load(object sender, EventArgs e)
{
Button btn = new Button();
btn.Click += new EventHandler(btn_Click);
}
void btn_Click(object sender, EventArgs e)
{
throw new Exception("The method or operation is not implemented.");
}
btn_Click function write automatically
in XAML Editor, Write any event. for example:
MouseLeftButtonDown then click tab
MouseLeftButtonDown="" then click tab again
MouseLeftButtonDown="Button_MouseLeftButtonDown" in the code section Button_MouseLeftButtonDown method created.
Sara Ford has this market cornered.
http://blogs.msdn.com/saraford/default.aspx
More Visual Studio tips and tricks than you can shake a stick at.
Some others:
The Visual Studio 2005 and 2008 3-month trial editions are fully-functional, and can be used indefinitely (forever) by setting the system clock back prior to opening VS. Then, when VS is opened, set the system clock forward again so your datetimes aren't screwed up.
But that's really piracy and I can't recommend it, especially when anybody with a .edu address can get a fully-functional Pro version of VS2008 through Microsoft Dreamspark.
You can use Visual Studio to open 3rd-party executables, and browse embedded resources (dialogs, string tables, images, etc) stored within.
Debugging visualizers are not exactly a "hidden" feature but they are somewhat neglected, and super-useful, since in addition to using the provided visualizers you can roll your own for specific data sets.
Debugger's "Set Instruction Pointer" or "Set Next Statement" command.
Conditional breakpoints (as KiwiBastard noted).
You can use Quickwatch etc. to evaluate not only the value of a variable, but runtime expressions around that variable.
T4 (Text Template Transformation Toolkit). T4 is a code generator built right into Visual Studio
Custom IntelliSense dropdown height, for example displaying 50 items instead of the default which is IMO ridiculously small (8).
(To do that, just resize the dropdown next time you see it, and Visual Studio will remember the size you selected next time it opens a dropdown.)
Discovered today:
Ctrl + .
Brings up the context menu for refactoring (then one that's accessible via the underlined last letter of a class/method/property you've just renamed - mouse over for menu or "Ctrl" + ".")
A lot of people don't know or use the debugger to it's fullest - I.E. just use it to stop code, but right click on the red circle and there are a lot more options such as break on condition, run code on break.
Also you can change variable values at runtime using the debugger which is a great feature - saves rerunning code to fix a silly logic error etc.
Line transpose, Shift-Alt-T
Swaps two line (current and next) and moves cursor to the next line. I'm lovin it. I've even written a macro which changed again position by one line, executed line transpose and changed line position again so it all looking like I swapping current line with previous (Reverse line transpose).
Word transpose, Shift-Ctrl-T
When developing C++, Ctrl-F7 compiles the current file only.
Document Outline in the FormsDesigner (CTRL + ALT + T)
Fast control renaming, ordering and more!
To auto-sync current file with Solution Explorer. So don't have to look where the file lives in the project structure
Tools -> Options -> Projects and Solutions -> "Track Active Item in Solution Explorer"
Edit: If this gets too annoying for you then you can use Dan Vanderboom's macro to invoke this feature on demand through a keystroke.
(Note: Taken from the comment below by Jerry).
I'm not sure if it's "hidden", but not many people know about it -- pseudoregisters. Comes very handy when debugging, I've #ERR, hr in my watch window all the time.
Ctrl-Minus, Ctrl-Plus, navigates back and forward where you've been recently (only open files, though).
I don't use it often, but I do love:
ctrl-alt + mouse select
To select in a rectangular block, to 'block' boundaries.
As noted in comments,
alt + mouse select
Does just a plain rectangular block.
Here's something I learned (for C#):
You can move the cursor to the opening curly brace from the closing curly brace by pressing Control + ].
I learned this on an SO topic that's a dupe of this one:
“Hidden Secrets” of the Visual Studio .NET debugger?
CTRL + Shift + U -> Uppercase highlighted section.
CTRL + U -> Lowercase the highlighted section
Great for getting my SQL Statements looking just right when putting them into string queries.
Also useful for code you've found online where EVERYTHING IS IN CAPS.
Middle Mouse Button Click on the editor tab closes the tab.
To display any chunk of data as an n-byte "array", use the following syntax in Visual Studio's QuickWatch window:
variable, n
For example, to view a variable named foo as a 256-byte array, enter the following expression in the QuickWatch window:
foo, 256
This is particularly useful when viewing strings that aren't null-terminated or data that's only accessible via a pointer. You can use Visual Studio's Memory window to achieve a similar result, but using the QuickWatch window is often more convenient for a quick check.

Resources