views:

572

answers:

2

I have plenty of experience with Eclipse, and now I'm trying out Visual Studio 2010. I find its formatting somewhat counter-intuitive. Here are some things I'm trying to figure out:

  1. Is there a way to select all text and format/indent it properly, like SHIFT+A SHIFT+I in Eclipse?

  2. Why is it that when I type a line like if (n == 0) {, as soon as I type the opening brace, the text cursor is moved to the beginning of the line? Is this some productivity speedup I'm failing to see?

  3. When I hit ENTER after the aforementioned line, I'd like the closing brace to be put in place automatically for me. How can I do this?

I've looked for hotkey documentation, and it's helped a bit, but this still feels clunky to me.

A: 

To format a document in visual studio the key combination is: ctrl-k ctrl-d

John Boker
I try that, and it says "The key combination (Ctrl+K, Ctrl+D) is bound to command (Format Document) which is not currently available."
Rosarch
+1  A: 

The formatting commands are by default bound to Ctrl+K Ctrl+??. Ctrl+K as the first keystoke, followed by another key stroke that determines the specific formatting option.

Look at the Advanced submenu of the Edit menu. It will show you that

  • "format selection" is Ctrl+k Ctrl+f
  • "comment selection" is Ctrl+k Ctrl+c
John Knoeller
Wait, what? I have a default install of VS2010 and mine are: CTRL-E, CTRL-D to format the whole document, CTRL-E, CTRL-F to format selection, CTRL-E, CTRL-C to comment, and CTRL-E, CTRL-U to uncomment. They are the same in VS2008 as well?
Matt Olenik
Oh, !@#%. I think it depends on some questions you are answer the first time you run the app. I forgot about that... <sigh>
John Knoeller
The first time I ran it, I chose C#, and it says "The key combination (Ctrl+E, Ctrl+D) is not a command."
Rosarch
@Rosharch: I chose C++
John Knoeller
So... how can I change those initial settings? And I'll be spending more time with C# than C, so I'd rather leave it on that as the default.
Rosarch
_Customize_ on the _Tools_ menu lets you change the key bindings however you want. I think you can even setup differnt bindings for C# than what you use for C++ if you want.
John Knoeller