Visual Studio is consistently one of the highest trending IDEs on the market. It has powerful features to increase code productivity. Because of this, Synergex brought traditional Synergy coding into Visual Studio. But how do you use it? I would like to focus on some of the hotkeys and organizational features available inside Visual Studio that will help developers navigate their code.
- Easy commenting: While testing code, there are times when you want to disable large sections of code so that you can run alternative code to see the differences. In Visual Studio, you can highlight the code you want to comment out and press CTRL K + C to comment out the lines. You can press this key combination multiple times to add a ‘;’ to the front of each line or CTRL K + U to remove a comment character from each line. The toolbar also contains buttons to comment and uncomment lines:
- Multiple line edits: One of my favorite features in Visual Studio that I’m surprised hasn’t made its way into other Microsoft products is the ability to edit multiple lines at once. If you press ALT + SHIFT and (while still holding them) push the UP or DOWN arrow keys, you can expand the cursor to multiple lines. This means that when you press a key, it will edit all of those lines with that key stroke. For example, let’s say you have multiple WRITES statements in your code:
writes(chnout, rec_1) writes(chnout, " ") writes(chnout, rec_2)
Now you want to add an error list to handle record locking on each line. Well, you can use ALT + SHIFT to add the identical error list to each line, which beats copying and pasting to each line.
writes(chnout, rec_1) [$ERR_LOCKED=errloc] writes(chnout, " ") [$ERR_LOCKED=errloc] writes(chnout, rec_2) [$ERR_LOCKED=errloc]
- Simple duplication: Speaking of copy and paste, how annoying is it to click, then hold SHIFT, then END, then CRTL C, then click, and then CTRL V? That’s tedious. It was tedious to write it out. If you want to copy the line you are on, you can duplicate the line of code with CTRL D.
Collapsing and expanding code
You may have noticed that when you create a main routine, subroutine, or function, a “-“ appears to the left of the editor. This allows you to collapse that code section to make it easier to edit large pieces of code.
- Collapsible labels: You will also notice that internal subroutines/labels are not naturally collapsible. But what if you wanted to make a label collapsible because you have so many of them? You would surround the code with .REGION/.ENDREGION along with a title for the region. (I usually stick with the name of the label.) For example:
.region "erroloc" errloc, repeat begin ... .endregion
With .REGION/.ENDREGION in place, you will now get the “-“ around that section that you can collapse.
- Hotkeys: A number of hotkeys can be used to collapse and expand these sections:
Toggle outlining expansion – CTRL M + M
Toggle all outlining – CRTL M + L
Stop outlining – CRTL M + P
Stop hiding current – CRTL M + U
Collapse to definitions – CTRL M + O
There are also a few features that can be used to navigate your code that I find extremely helpful:
- If you are on a BEGIN or END in code and want to go to the matching END or BEGIN, while the cursor is on the BEGIN or END, press CRTL ] to move the cursor to its pairing statement.
- If you are on a variable or subroutine and want to jump to where it is defined in the code, you can either press F12 or right-click and select “Go to definition.”
- With this jumping around, you can also push CTRL – to go back to where you were or CTRL + to go forward.
To round off this list, there are a number of function keys that are useful during a debugging session in Visual Studio:
- To step into the line of code you are on, so you can see the code run through a subroutine, class, etc., use F11. To step over and go to the next line of the currently executing source code, press F10.
- While coding or debugging, pressing F9 will toggle adding or removing a breakpoint on the current line.
Those are my 10 tips for navigating through Visual Studio and making use of its code editing and hotkey features. You can also find our video about Visual Studio hotkeys here. Keep in mind that most of these keys can be changed or customized inside Visual Studio by selecting Options from the Tools drop-down menu. Hope you found some of these helpful.
If you haven’t moved your Synergy development environment to Visual Studio yet, what are you waiting for? Check out our solution for modernizing your development environment and accessing a superior debugging and build experience. You can also reach out to your account executive to discuss how we can help you move to Visual Studio or train your developers to get the most out of their new environment.