News

Archives

Blogs

Syndication:

My Favorite Visual Studio Tips

1. Ctrl+Shift+V

Ctrl+Shift+V will cycle through the items in the clipboard ring. This allows you to copy multiple things before even attempting to paste them and then paste them in order at a later point. Keep in mind that the clipboard ring holds up to 20 items.

2. Line Numbers

Line numbers make it much easier to discuss your code with someone else, especially during code reviews or technical demos.

To add line numbers to your code
  • Click Tools menu and select Options...
  • Expand the Text Editor tree item
  • Select the C# (or Basic) tree item
  • In the Display section, check Line numbers
NOTE: The line numbers will be displayed on the left of the text editor.

3. Snippets

Visual Studio has code snippets built in or you can create your own. You can also drag-and-drop sections of code to the Toolbar and use them as snippets.

4. Tab Groups

If you need to work with multiple windows you can group them together using tab groups. Right-click on the window tab and select New Horizontal Tab Group (or New Vertical Tab Group). You can then drag-and-drop other windows to the tab group to add or remove them.

5. Regions

Regions allow you to organize your code in a clean and concise manner. I am a firm believer in the practice of only pulling logic into a method if it will be used more than once. I accomplish this using regions to group sections of code that are related and act like a function but are only executed once. I also use regions to group sections of my objects together (i.e. Fields, Properties, Methods).

To place code within a region, simple place the #region and #endregion tags around the code. For example

public void Foo()
{
#region My Region

// Add code here...

#endregion
}

This would allow the method Foo to be collapsed to look like the following:

public void Foo()
{
My Region

}

6. Auto-complete (Ctrl+Space)

Talk about a time saver! I think once I discovered Ctrl+Space I was unable to type a full word again. Even better, intellisense will display suggestions if there is more than one possibility with what you have already typed.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Friday, December 05, 2008 1:26 PM

Feedback

# re: My Favorite Visual Studio Tips

Here are a couple more...

Ctrl + G: Skip to a line number

Ctrl + M + O: Probably my favorite - collapses all methods in a class (I Hate regions, and find just doing this works much better :) )

Snippets, but especially for property creation...e.g., Type "prop" and hit tab. 12/5/2008 2:48 PM | Sanjayu

# re: My Favorite Visual Studio Tips

Excellent additions! I too use the Ctrl+G and Ctrl+M+O shortcuts. Definitely useful to skip to a line or collapse everything down to clean up the window. 12/8/2008 7:59 AM | Jeff Paterno

# re: My Favorite Visual Studio Tips

great tips, Ctrl K-C to comment selected block of text and Ctrl K-U to unselect. Hold down alt whilst selecting region to copy rectangular section of text are two of my faves 12/8/2008 4:39 PM | ntsmith

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: