Supercharge Your Coding in Visual Studio
Tags: csharp
Published: 2021-08-12 20:04:36

#Keyboard Shortcuts
##Hold Down Alt when Selecting Text
Let’s say you have a list of variables and you decide to change the scope from public to protected. You could use find and replace on the selected text, or you could just copy/paste over each modifier. Another option is block selecting. Holding down the Alt key while selecting allows you to include multiple lines to the position of the cursor rather than the entire line. The result is that when you type, cut or paste, it applies to every line selected. You could select all the public modifiers and simply type or paste protected to edit them all at once.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gvmwbttnay9944knol3.png "Block Selection Image")

##Ctrl + X and Ctrl + V with nothing selected
Cut and paste? What is so special about these? In Visual Studio. If you have nothing selected, the cut command will cut the entire line and paste will insert the entire line above the cursor. When moving lines around, this method is very fast.
##Ctrl + K + C (comment) and Ctrl + K + U (uncomment) with nothing selected
These commands will comment and uncomment the entire line when no text is selected. When text is selected, they will comment and uncomment the selection. The uncomment shortcut will uncomment even if no text is selected as long as the cursor is within commented code.
###Better Commenting
As nice as the default comment shortcuts are, you still have to use both hands. That can get tedious if you are doing a lot. Here is an easier combo to make it even faster.
Go to Tools>Options, then find the Environment>Keyboard node.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i9tsnv9rz77spucehgzo.png "Better comments step 1 image")

In the “Show commands containing box” enter “comment” (no quotes).
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbc4fg5rkglhx92pfkk8.png "Better comments step 2 image")
 
Select the Edit.ToggleLineComment shortcut and click in the “Press shortcut key” input field. 
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g8gnpg7it2wxj46yhfia.png "Better comments step 3 image")

Press Left Ctrl + Left Windows, then click “Assign”
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3wm5cmcsus7af2p8vzc1.png "Better comments step 4 image")

Repeat the process for Edit.UncommentSelection using Left Alt + Left Windows

Setting these shortcuts allows you to keep one hand on the mouse or arrow keys to navigate the code and the other to comment and uncomment quickly.
#Visual Studio has a Back Button?!
Ever feel you are a bit like Alice and falling down the rabbit hole when navigating code? Visual Studio has a back button that tracks a history of where your cursor has been. Just click to go back through and retrace your steps. You can also click the down arrow to see the history list.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nb8iib5uiqx87s9w7euq.png "Visual Studio back button image")

#Tedious Code
Repetitive code, such as mapping database tables to object models, can be a real downer to a good programming groove. Here’s how to use simple Excel formulas to write hundreds of lines of code in seconds.
Get a list of the variable names or database fields without any extra punctuation. Then, paste the list into column A of your blank Excel sheet.
Excel string formulas are fairly straightforward. The basic syntax is =”string literal” & A1 & “string literal”. The quotes indicate literal text. Use ”” to escape a double quote in the string. Let’s say your variable name is Id and is located in the A1 cell of your sheet and you want to create a public string accessor property for it. The formula would be `=”public string ” & TRIM(A1)  & “{ get; set; }”` Now, you just use the Excel fill handle and pull it down your list to "write" that line of code for each variable.
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pxb2w98pzt0fabiit1p2.png "Excel coding step 1 image")
![alt text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/owjuvdjvogfoug4gkuoi.png "Excel coding step 2 image")