Visual Studio 2005 Tip #5 Using the Back/Forward mouse buttons to navigate

If you own a Microsoft Explorer mouse, or one that has the back/forward buttons you can navigate back and forth through your code.

For example if you need to see a defintion, right click and select “Go To Definition” from the popup menu.

You are taken to the definition.

Now how many times do you need to go back to where you we’re working?

Simply click the back button on your mouse! Viola! You are now back to where you were before!

If you need to go forward again and look at the defintion, click the the forward button on yor mouse

OK so that’s all great if you like using the mouse. So how would you do it with the keyboard?

Tip #5b: Using the Keyboard to navigate to a definition and back.

Have the cursor over the item you want to get the defintion for and click the F12 key. Sweet! But now how to we get back? Press Ctrl + - (minus key). If you want to back to the definition again press Ctrl + - (minus key) again! There you have it!

NOTE: These key strokes assume you have selected the Visual Studio.net keyboard layout.  I have not tested this with any of the other layouts.

Visual Studio 2005 Tip #4: Column Selecting Text

There are times when you need to select text in column mode instead of the tradtional row selection. Think of it like selecting a range of columns and rows in Excel.

For example, lets say I want to highlight all the strings from this section of constants because you want to put into a store procedure as input parameters.
The image “http://static.flickr.com/21/98461267_8d67f24660.jpg?v=0” cannot be displayed, because it contains errors.

Move the cursor to the beginning column you want to start highlighting from. Hold down the ALT key and then press and hold down the left mouse button. Then Highlight the code you want with the mouse or arrow keys. Once you have the code you need, simply copy ( + C), cut ( + X), paste ( + V) or delete.
The image “http://static.flickr.com/32/98461269_a31ccc6621.jpg?v=0” cannot be displayed, because it contains errors.
Now the clipboard has stored only the text that is highlighted above. The only thing now is remove the quotes and the semi-colons in when posting it in your stored procedure!

ALT + Left Mouse button = Column Text Selection

This feature also works in Visual Studio 2003. (It may work in 2001 but I have not used it in several years to remember)

technorati tags: ,

Visual Studio 2005 Tips #3: Using Surround with …

Another nice feature that will save on time and re-indenting your code is the Surrounds with snippets.  It works the same way as Code Snippets but the difference is that you highlight a section of code that you want to surround your code with.

This example I am going to surround a section of my code with a try catch.  The keyboard short cut is Ctrl + K and the S.

A popup combo box will appear asking you what type.  You can selec the you want to surround with.  Since I am going to use a try catch, I can hit the “T” key and then hit enter.

My code is now surrounded by a try/catch with the Exception object available for me to assign a variable to.

Visual Studio 2005 Tip#2:Writing your own Code Snippets

Now that you’ve seen the power of using Code Snippets, the only thing cooler is creating your very own code snippets!

The best tool that I’ve seen to help you create your own is one from Microsoft. It’s actually an open source project that if want to contribute to, you can.

You can download it from the MSDN website.

Visual Studio 2005 Tips #1: Code Snippets

One of the new features of Visual Studio 2005 is the ability to use Code Snippets.

At times coding can be very repeative and the 9 out of 10 times its the same thing that I am typing.  By using the snippets feature I can reduce this.

So How do you insert a Code Snippet?
The fastest way is from the keyboard Press the Ctrl key + K and then X.

A popup window will appear for you do select the available snippets.  There are several to choose from and you can even create your own!  For this tip I am going to do a Property snippet. Press ‘P’ on your keyboard or scroll through the list and select it.
Flickr Photo

Your code will now have the snippet template of the property item in place.  Very cool!  However the best is yet to come!  Notice that the private data member type is highlighted. 

Flickr Photo

Go ahead and change it to the type you need.  I am going to change mine to a string.
Flickr Photo

To change the name of the private data member simply hit the tab key.  Now the highlighted box is around the private data member name.  Type in the name you would normally give your private data members.
Flickr Photo

One really nice feature is the set and get values have been modified automatically to the same name as the private data member.

Finally tab one more time and enter your property Name.

Flickr Photo
Once you like what you see hit the enter key.  However if you want to change any of the values you made you can simply hit the tab key again and it cycle through them all. (You can’t do this after hit the enter key though)

To me this is one of my favorite features and I find myself constantly doing these key strokes when I am in Visual Studio 2003. One more reason to port everything over to .net 2.0!