Welcome to MSDN Blogs Sign in | Join | Help

It's another year for tips and tricks presentations (and I guess that means I finally blogged again :)).  I just wanted to post a link of the ppt deck I gave this year both at Tech Ed and the Tweener event on the weekend which includes new tips in the VS 2008 SP and a few of my favorite add-in's.

 Here's the ppt.

A long time ago (about 3 years now) a bug was opened on the Microsoft Feedback site regarding how Visual Studio removes tabs in statements (which prevents using Tabs or spaces for aligning fields and locals in declaration statements).  This wasn't true in VS 2003, but started happening in VS2005 with the new formatting engine.

For example, the following statements:

int               index                =    5;
string            text                 =    "blah";
string            reallyLongVarName    =    "foo";
LongTypeName      bar                  =    new LongTypeName(5, 7, 3);

Would become:

int index = 5;
string text = "blah";
string reallyLongVarName = "foo";
LongTypeName bar = new LongTypeName(5, 7, 3);

We weren't able to add full alignment options (individually control how symbols are aligned in the editor) in VS2008, but recently addressed the scenario of aligning in declaration statements.  The design was iterated on with a few customers from the Microsoft Connect site (thanks!).

 

Here's what you'll see in VS 2008:

A new option was added to Tools | Options | Text Editor | C# | Formatting | Spacing | Set other spacing options.

The option is a check-box and says: “Ignore spaces in declaration statements”.

The option applies for :

  • Constants and Fields
  • Local variables

The option will apply for every location that a field or local variable is valid, including:

  • Block
  • For-statement
  • Foreach-statement
  • Using-statement

If the option is on, we will retain the users spacing around attributes, modifiers, type, identifier, and the binary operator, however we will continue to format spacing within the right-hand-side expression.

type                                                     identifier         =        expression;

attribute        field-modifier         type        identifier         =        expression;

Spacing between multiple statements will continue to be removed.

For example, the following:

int     index   =   5;      string      text    =       "blah";

Would become:

int        index    =     5; string         text      =         "blah";

 

We will continue to not format around comments.

This is in the builds after Beta 2.

Let us know what you think!

 

Happy coding,

Karen

At Tech Ed 2007, I gave another tips and tricks talk for working with the C# IDE.  Here's the list of tips that I presented (it's a cleaner version of Tips.cs that I used during the talk).

Tips for Understanding Code

1) [VS 2008] Target Multiple Versions of the Framework

  • Use .NET 3.0 to target Vista
  • Use .NET 3.5 to get started with LINQ
  • Project | Properties | Application Tab

2) C# Development Settings

  • Share your settings
  • Tools | Import and Export Settings

3) Add New Item

  • [VS 2008] Categorical
  • Filter-as-you-type

4) Class Designer

  • Visual, high-level view of relationships in code
  • Use it to explore the framework

5) Active File Drop-down (Ctrl + Alt + Down Arrow)

  • Jump to active files

6) Collapse to Definition (Ctrl+M, 0)

  • Header-like view of code

7) Go to Definition (F12)

  • Quickly navigate to the definition

8) GTD Navigation Stack (Ctrl+Shift+7, Ctrl+Shift+8)

  • Virtual callstack

9) Find All References (Shift+F12)

  • Number of references
  • Cyclical

10) Iterate through List Window (F8)

  • Works on any list

11) Find Combo Box (Ctrl + /)

  • Go to line (Ctrl+G)
  • Go to file in project (Ctrl+Shift+G)
  • Help (keyword+F1)
  • Mini-command window (>)

Tips for Writing and Modifying Code

12) Rename

  • Entry points for rename (use solution explorer for file rename)
  • [VS 2008] Support for C# 3.0

13) Code Snippets

14) Invoke Smart Tag (Ctrl + .)

  • Never take your hand off the keyboard

15) Add Using

  • Automatically adds using directives

16) Generate Method Stub

  • Consume first, declare later

17) Snippets for Code Generation

18) [VS 2008] IntelliSense for Object Initalizers

  • Filter as you initialize
  • Ctrl+J for all members

19) [VS 2008] IntelliSense for Query Expressions

  • Full understanding

20) [VS 2008] Quick Info for C# 3.0 Understanding

  • Extension methods
  • Var

21) IntelliSense Customization

  • [VS 2008] CTRL for transparency
  • Tools | Options | Text Editor | C# | IntelliSense

22) [VS 2008] Customize Formatting Style

  • C# 3.0 Support
  • Tools | Options | Text Editor | C# | Formatting

23) Customize your Context Menu

  • Tools | Customize

24) [VS 2008] Debugging Query Expressions

  • IEnumerable Results View

25) [VS 2008] Organize Usings

  • Remove
  • Sort
  • Tools | Options | Text Editor | C# | Advanced

Thanks to Charlie, who pointed me to Windows Live Writer, I now have a super easy way to update my blog and include images and attachments.  This means that it's a perfect opportunity to post the cool keybinding pamphlets the C# team made with our most frequently used bindings!

I recently gave the C# IDE Tips and Tricks talk at Tech Ed Europe in Barcelona, and many people have asked me for them.  By popular demand, you can download them through the attached file C#Keybindings.pdf.

I'm giving a talk on Visual C# - Productivity Tips and Tricks for the Visual C# IDE at Tech Ed 06.  Since I mention many, many keybindings in the talk, here are descriptions for some of the common ones for reference.  The talk was based off of one that my coworker Anson gave at PDC so you can find descriptions on most of the tips and tricks there.

 

Visual C# Development Settings Default KeyBindings

Editing

Edit.CollapseToDefinitions

CTRL + M, O

Collapses existing regions to provide a high-level view of the types and members in the source file.

Edit.CommentSelection

CTRL + K, C or CTRL + E, C

Inserts // at the beginning of the current line or every line of the current selection.

Edit.FormatDocument

CTRL + K, D or CTRL + E, D

Formats the current document according to the indentation and code formatting settings specified on the Formatting pane under Tools | Options | Text Editor | C#.

Edit.FormatSelection

CTRL + K, F or CTRL + E, F

Formats the current selection according to the indentation and code formatting settings specified on the Formatting pane under Tools | Options | Text Editor | C#.

Edit.InsertSnippet

CTRL + K,  X

Displays the Code Snippet Picker. The selected code snippet will be inserted at the cursor position.

Edit.StopOutlining

CTRL + M,  P

Removes all outlining information from the whole document.

Edit.SurroundWith

CTRL + K, S

Displays the Code Snippet Picker.  The selected code snippet will be wrapped around the selected text.

Edit.ToggleAllOutlining

CTRL + M, L

Toggles all previously collapsed outlining regions between collapsed and expanded states.

Expand Code Snippet

[TAB]

Expand Code Snippet

Edit.ToggleOutliningExpansion

CTRL + M, M

Toggles the currently selected collapsed region between the collapsed and expanded state.

Edit.UncommentSelection

CTRL + K, U or CTRL + E, U

Removes the // at the beginning of the current line or every line of the current selection.

Edit.CycleClipboardRing

CTRL + SHIFT + V

Pastes text from the Clipboard ring to the cursor location in the file. Subsequent use of the shortcut key iterates through the items in the Clipboard ring.

Edit.Replace

CTRL + H

Displays the replace options in the Quick tab of the Find and Replace dialog box.

Edit.ReplaceInFiles

CTRL + SHIFT + H

Displays the replace options on the In Files tab of the Find and Replace dialog box.

View.ShowSmartTag

CTRL + . or SHIFT + ALT + F10

Displays the available options on the smart tag menu.

Edit.InvokeSnippetFromShortcut

TAB

Inserts the expanded code snippet from the shortcut name.

 

 

File

File.NewProject

CTRL + SHIFT + N

Displays the New Project dialog box.

File.OpenProject

CTRL + SHIFT + O

Displays the Open Project dialog box, where existing projects can be added to the solution.

Project.AddClass

SHIFT + ALT + C

Displays the Add New Item dialog box and selects Class template as default.

Project.AddExistingItem

SHIFT + ALT + A

Displays the Add Existing Item dialog box, where existing files can be added to the current project.

Project.AddNewItem

CTRL + SHIFT + A

Displays the Add New Item dialog box, where a new file can be added to the current project.

Window.ShowEzMDIFileList

CTRL + ALT + DOWN ARROW

Displays a pop-up listing of all open documents.

Edit.OpenFile

CTRL + O

Displays the Open File dialog box where a file can be selected to be opened.  This does not add the file to the project.

 

 

IntelliSense

Edit.CompleteWord

CTRL + SPACE or CTRL + K, W

Completes the current word in the completion list.

Edit.ListMembers

CTRL + J or CTRL + K, L

Invokes the IntelliSense completion list.

Edit.QuickInfo

CTRL + K, I

Displays the complete declaration for the specified identifier in your code in a Quick Info tool tip.

Edit.ParameterInfo

CTRL + SHIFT + SPACE or CTRL K, P

Displays the name, number and type of parameters required for the specified method.

 

 

Navigation

Edit.FindAllReferences

SHIFT + F12 or CTRL + K, R

Displays a list of all references for the symbol selected.

Edit.GoToBrace

CTRL + ]

Moves the cursor location to the matching brace in the source file.

Edit.GoToDefinition

F12

Navigates to the declaration for the selected symbol in code.

Edit.GoToNextLocation

F8

Moves the cursor to the next item, such as a task in the Task List window or a search match in the Find Results window. Subsequent invocations will move to the next item in the list.

Edit.IncrementalSearch

CTRL + I

Activates incremental search. If incremental search is on, but no input is passed, the previous search query is used. If search input has been found, next invocation searches for the next occurrence of the input text.

View.ClassViewGoToSearchCombo

CTRL + K, CTRL + V

Brings focus to the Class View search box.

View.ForwardBrowseContext

CTRL + SHIFT + 7

Moves to the next item called in code in the current file.  Uses the Go To Definition navigation stack.

View.NavigateBackward

CTRL + MINUS SIGN (-)

Moves to the previously browsed line of code.

View.NavigateForward

CTRL + SHIFT + MINUS SIGN (-)

Moves to the next browsed line of code.

View.PopBrowseContext

CTRL + SHIFT + 8

Moves to the previous item called in code in the current file. Uses the Go To Definition navigation stack.

Edit.FindInFiles

CTRL + SHIFT + F

Displays the In Files tab of the Find and Replace dialog box.

Edit.FindSymbol

ALT + F12

Displays the Find Symbol pane of the Find and Replace dialog box.

View.ViewCode

F7

Displays the selected item in Code view of the editor.

View.ViewDesigner

SHIFT + F7

Switches to Design view for the current document. Available only in Source view.

View.ViewMarkup

SHIFT + F7

Switches to Source view for the current document. Available only in Design view.

Window.MoveToNavigationBar

CTRL + F2

Moves the cursor to the drop-down bar located at the top of the code editor when the editor is in Code view or Server Code view.

Edit.Find

CTRL + F

Displays the Quick tab of the Find and Replace dialog box.

Edit.GoTo

CTRL + G

Displays the Go To Line dialog box.

Edit.GoToFindCombo

CTRL + /

Puts the cursor in the Find/Command box on the Standard toolbar.

 

 

Refactoring

Refactor.EncapsulateField

CTRL + R, E

Displays the Encapsulate Field dialog box, which allows creation of a property from an existing field and updates all references to use the new property.

Refactor.ExtractInterface

CTRL + R, I

Displays the Extract Interface dialog box, which allows creation of a new interface with members derived from an existing class, struct, or interface.

Refactor.ExtractMethod

CTRL + R, M

Displays the Extract Method dialog box, which allows creation of a new method from the selected code.

Refactor.PromoteLocalVariabletoParameter

CTRL + R, P

Moves a variable from a local usage to a method, indexer, or constructor parameter and updates all call sites appropriately.

Refactor.RemoveParameters

CTRL + R, V

Displays the Remove Parameters dialog box, which allows removal of parameters from methods, indexers, or delegates by changing the declaration at any locations where the member is called.

Refactor.Rename

CTRL + R, R or F2

Displays the Rename dialog box, which allows renaming all references for an identifier.

Refactor.ReorderParameters

CTRL + R, O

Displays the Reorder Parameters dialog box, which allows changes to the order of the parameters for methods, indexers, and delegates.

 

 

Window

View.ClassView

CTRL + W, C

Displays the Class View window.

View.CodeDefinitionWindow

CTRL + W, D

Displays the Code Definition window.

View.CommandWindow

CTRL + W, A

Displays the Command window, where commands can be invoked to manipulate the integrated development environment (IDE).

View.ErrorList

CTRL + W, E

Displays the Error List window.

View.ObjectBrowser

CTRL + W, J

Displays the Object Browser.

View.Output

CTRL + W, O

Displays the Output window, where status messages can be viewed at run time.

View.PropertiesWindow

CTRL + W, P

Displays the Properties window, which lists the design-time properties and events for the currently selected item.

View.SolutionExplorer

CTRL + W, S

Displays Solution Explorer, which lists the projects and files in the current solution.

View.TaskList

CTRL + W, T

Displays the Task List window, which displays custom tasks, comments, shortcuts, warnings an