4

Does anyone know if there's a way in Visual Studio 2010 with ReSharper 6.1 to comment out the selected lines of code with their closing brackets - or simply to comment out both the highlighted opening bracket and it's corresponding closing bracket? Here's an example of what I mean:

if(something) {
  do(this);
}

I am looking for a hot-key so that when if(something) { is selected, it will comment out if(something) { and }, preferably fixing the tabs once commented like so:

// if(something) {
do(this);
//}
Grinn
  • 5,370
  • 38
  • 51
  • Theoretically you could write a replace pattern (ReSharper->Tools->Pattern Catalog). But (at least in ReSharper 5.1.3) comment signs (*//*) in *Replace pattern* text field are ignored. – brgerner Jul 03 '12 at 08:56
  • 1
    I don't think this is possible with search and replace patterns - with a ReSharper plug-in maybe. – Jura Gorohovsky Jul 04 '12 at 20:09
  • Don't have an answer, but I think it is a great idea. Would also come in handy for try blocks sometimes. Please make sure you suggest it to Jetbrains. – Jan Schiefer Nov 03 '12 at 06:57

1 Answers1

0

This isn't entirely what you're after, but it's pretty close:

Highlight the code inside the if statement by placing the cursor at one brace and hitting Ctrl + Shift + ].

Now hit Ctrl + Shift + Alt + Left Arrow. This will move the code 'left', i.e. outside of the if statement.

You don't need to comment the if statement out after this because it's empty.

Note that you can also move code 'right' to put it back in the if statement later.

Josh Gallagher
  • 5,211
  • 2
  • 33
  • 60
  • Not bad. This doesn't exactly work in JS. You can keep hitting `Ctrl` + `Alt` + `Right Arrow` to get the whole thing selected, and then `Ctrl` + `Shift` + `Alt` + `Up Arrow` to move the code outside of the if... but it's a little kludgey. – Grinn Dec 06 '12 at 16:21