Comment Opening and Closing Brackets (with ReSharper?) - visual-studio-2010

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);
//}

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.

Related

How to change the color of the dropdown that appears with ctrl + shift + p in VSCode

I was trying to edit some themes on my Vscode but got stuck at this point since I don't know what this section is referred as, that we pop up by ctrl + shift + p
"workbench.colorCustomizations": {
"editor.background": "#101a29",
"sideBar.foreground": "#CAC9C9",
"sideBarSectionHeader.foreground": "#CAC9C9",
"editorGroupHeader.tabsBorder": "#c93e71",
"editor.selectionBackground": "#ff6d6d32",
"editor.wordHighlightBackground": "#ff6d6d32"
},
I've did these many changes so far.
Primarily that is the quickInput so
"quickInput.background": "#f00"
will work. If you don't style the quickInput then the more generic editorWidget will also work but will also style other things, like the Find Widget.
"editorWidget.foreground": "#000",
"editorWidget.background": "#a8c0a8",

Visual Studio "Toggle Line Comment" Not Adding // To Already Commented Out Code

I want to comment out a block of Scss code with single line comments (multiline comment will not work b/c I need it to not be processed). In most editors you can select a block of code, and then use a shortcut to simply add // to the beginning of every line. The problem is that in Visual Studio 19 (version 16.7.7), the "Toggle Line Comment" (ctrl+k, ctrl+/) tries to be smart and does not add an extra // to the beginning of a line that already begins with a comment. That's a problem b/c when I toggle the comments off, it then removes comments that were originally there.
This seems really silly that it works this way. Is there some setting or way to change this behavior?
You can use the following command with my Visual Commander extension to add "//" to every selected line:
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
EnvDTE.TextDocument doc = DTE.ActiveDocument.Object("TextDocument") as EnvDTE.TextDocument;
EnvDTE.EditPoint p = doc.CreateEditPoint();
for (int i = ts.TopLine; i <= ts.BottomLine; ++i)
{
p.MoveToLineAndOffset(i, 1);
p.Insert("//");
}
}
The shortcut you need is Ctrl+Shift+/
It comments selected lines by adding // before the first character. Toggles back if pressed again.

How to set caret to the correct position?

When i do this:
void test(){|}
The caret is between {}, and then i press enter and this happen:
void test(){
|}
This is the problem, when i create a method, the caret is always before }, so i have to press enter again and again, just to put the caret in the right place.
What i want is exactly what happen with if():
if(){|}
And after press enter:
if(){
|
}
How can i make sure that the position of the caret, for any method, looks like the position of the caret in if() method?
I'm using codeblocks 16.01.
Thank you.

Why Does VS 2010 'Comment' Keyboard Shortcut Change in C++?

For me, Visual Studio's Ctrl + K, Ctrl + C keyboard shortcut is used to comment-out the selected lines. When editing C++, this sometimes uses block comments (/* */) and sometimes uses line comments (//). Why does it change? How does it decide which to use when?
A couple other discussions on the topic:
Visual studio feature - commenting code Ctrl K - Ctrl C
visual studio C++ toggle comment ? comment while not whole line is selected?
Based on my own tinkerings, and what was said in those articles...
It's based on the start/end of the selection. It seems to use double slashes // whenever you start your selection at the beginning of the line AND end it at the end of a line.
It will use /* */ notation whenever the selection occurs midway through lines.
IE:
If I have the code
int main () {
return 0;
}
and highlight only int main, it will convert it to /*int main*/.
If I highlight the entire code section, starting after the indent tab, it will convert it to
/*int main () {
return 0;
}*/
But if I highlight the section starting before the indent tab, it converts it to
//int main () {
// return 0;
//}
Summary of links under Zhais' answer. Because following links is hard!
Selecting entire lines (including leading whitespace) will use //
Selecting at least one partial line
If a // comment is included, will use //
Otherwise, will use /* */

AutoHotKey For Loop

I am trying to get a script like this in AHK but I don't know how to write it in AHK:
string arrow
if (leftArrowKeyPressed) {
arrow = "left"
}
if (rightArrowKeyPressed) {
arrow = "right"
}
if (arrow = "left") {
for (int number = 1000; number < 10000; number++) {
simulateKeyPresses(number)
simulateKeyPresses(mousebutton0)
}
}
I did something similar to this. It uses the While command. Your code might look something like the following:
~left::
While GetKeyState("left", "P") {
Send {NUMBER}
Send {MOUSE_BUTTON}
}
Line 1: '~left::' tells the following lines of code to activate when the left button is pressed. The '~' tells the program to still allow the 'left' arrow key to work. If you wanted this code to run and simultaneously block the 'left' arrow from working, remove the '~'.
Line 2: 'While GetKeyState("left", "P")' is self-explanatory. It's a 'while' loop that runs as long as you are holding the 'left' arrow key.
Line 3 and line 4 are for your code to go. Note that 'NUMBER' can be replace by any number 0-9, and 'MOUSE_BUTTON' can be replaced by either the left mouse button (LButton) or the right mouse button (RButton).
I hoped this helped get you started. Also, as formentioned, the AHK Help manual is very informative. You can search 'AutoHotKey Help' on your computer for your off-line version, or visit this link for the online version. These manuals include documentation of just about anything you could ever hope for, as well as a useful example of code at the bottom of each page.

Resources