|
| 1 | +# 0802 - Visual Studio Code Tips and Tricks |
| 2 | + |
| 3 | +Visual Studio Code is one of the most popular code editors in the world, and has been receiving regular updates monthly since its original release in 2015. |
| 4 | + |
| 5 | +Wikipedia has a nice article about the history of [Visual Studio Code](https://en.wikipedia.org/wiki/Visual_Studio_Code). |
| 6 | + |
| 7 | +## Current Version and Acquision |
| 8 | + |
| 9 | +[Visual Studio Code](https://code.visualstudio.com) is available in [source code](https://github.com/microsoft/vscode) form and in binary distributions for Windows, Mac, and Linux. You can also run it in the browser, with instances available on GitHub CodeSpaces. |
| 10 | + |
| 11 | +Try opening a page of code from GitHub when signed in by just pressing the 'dot' key on your keyboard `.` You can also change the GitHub URL by replacing `github.com` with `github.dev` and open the current page in Visual Studio Code in the browser. |
| 12 | + |
| 13 | +## Code Writing Tips |
| 14 | + |
| 15 | +- `Ctrl+.` to pop open the code suggestion panel with code-fixes and suggestions |
| 16 | +- `Ctrl+<SPACE>` to open the intellisense panel with code-completion suggestions |
| 17 | +- `<TAB>` to choose a code-completion option and accept it |
| 18 | +- `<UP>` and `<DOWN>` when the code-completion window is open to select other options |
| 19 | +- `<UP>` and `<DOWN>` when the method signature completion window is open to select optional override signatures |
| 20 | +- Hold the `Ctrl` key to make these pop-ups semi-transparent |
| 21 | + |
| 22 | +- `Ctrl+X` to cut highlighted text to the clipboard |
| 23 | +- `Ctrl+C` to copy highlighted text to the clipboard |
| 24 | +- `Ctrl+V` to paste the contents of the clipboard |
| 25 | +- `Ctrl+E C` or `Ctrl+K C` to comment the current line of code |
| 26 | +- `Ctrl+E U` or `Ctrl+K U` to uncomment the current line of code |
| 27 | + |
| 28 | +- `Alt+<UP>` to move the current line of code up |
| 29 | +- `Alt+<DOWN>` to move the current line of code down |
| 30 | + |
| 31 | +When writing HTML or other markup syntax |
| 32 | + |
| 33 | +- `Shift+Alt+W` to wrap the current markup with a div element |
| 34 | + |
| 35 | +When you have JSON or XML on the clipboard, try **Edit - Paste Special - Paste as Classes** |
| 36 | + |
| 37 | +Try the **C# Interactive** window to get a REPL experience where you can experiment writing code |
| 38 | + |
| 39 | +## Code Navigation Tips |
| 40 | + |
| 41 | +- `Ctrl+F` to find text in the current file |
| 42 | +- `Ctrl+H` to find and replace text in the current file |
| 43 | +- `Ctrl+Shift+F` to find text in the current solution / project with options including regular expressions |
| 44 | +- `Ctrl+Shift+H` to find and replace text in the current solution / project with options including regular expressions |
| 45 | +- `Ctrl+P` - Open the File navigator and locate a file by name |
| 46 | +- `Ctrl+Alt+P` - Open the Command Pallete to execute a command for Visual Studio Code |
| 47 | +- `Ctrl+T` - Search your code - filenames, classes, interfaces, methods, properties, events, enums |
| 48 | +- `Ctrl+G` - Goto line number |
| 49 | +- `F12` - Goto definition of the object under cursor |
| 50 | +- `Shift+F12` - Find all references of the object under cursor |
| 51 | +- `Ctrl+F12` - Find all implementations of the interface under cursor, if not an interface, goes to definition |
| 52 | +- `Previous Mouse Button` to navigate to the previous code ___location |
| 53 | +- `Next Mouse Button` to navigate to the next code ___location |
| 54 | +- `Ctrl+M M` to collapse / expand the current block of code |
| 55 | + |
| 56 | +## Debugger Tips |
| 57 | + |
| 58 | +- `F5` to start your application and begin debugging |
| 59 | +- `Ctrl+F5` to start your application WITHOUT debugging |
| 60 | +- `F10` to start your application, begin debugging, and stop on the first line of your code |
| 61 | + |
| 62 | +### While debugging |
| 63 | + |
| 64 | +- `F11` step into the next line of your code |
| 65 | +- `F10` step OVER the current code and don't execute it |
| 66 | +- `F9` toggle a breakpoint on the current line of code (can also be set when not debugging) |
| 67 | +- `Ctrl+Shift+F9` delete all breakpoints |
| 68 | +- `Shift+F11` execute and step out of the current method |
| 69 | +- `Strl+Alt+P` attach to currently running process |
| 70 | + |
| 71 | +Tricks to make debugging easier: |
| 72 | + |
| 73 | +- Right-click on a breakpoint and add a condition to force the breakpoint to only stop when a condition is met |
| 74 | +- Use Locals, Watch, and Immediate windows to get insight into the current variables in scope and execute arbitrary code while working in debug mode |
| 75 | +- Configure your own data for the locals and watch windows by adding the [`DebuggerDisplay` attribute](https://learn.microsoft.com/visualstudio/debugger/using-the-debuggerdisplay-attribute) |
| 76 | +- Use the Call Stack window to navigate back and forth across the calling methods |
| 77 | + |
| 78 | +More advanced debugging capabilities available: |
| 79 | + |
| 80 | +- Debug on a remote machine with the [remote debugger](https://learn.microsoft.com/visualstudio/debugger/remote-debugging). This requires installing some tools on the target machine |
| 81 | +- Debug inside a Docker container |
| 82 | +- Debug inside Windows Subsystem for Linux |
| 83 | + |
| 84 | +## Make Visual Studio yours |
| 85 | + |
| 86 | +- Get your favorite themes from the [marketplace](https://marketplace.visualstudio.com/search?target=VSCode&category=Themes&sortBy=Installs) |
| 87 | +- Use sites like [VSCode Themes](https://vscodethemes.com/) to preview popular themes |
| 88 | +- Configure and use snippets to use code patterns again and again quickly. Select **Insert Snippet** from the command pallete to review the avaialble snippets and use **Configure User Snippets** to create a collection of snippets for yourself |
| 89 | + |
| 90 | +## Extensions |
| 91 | + |
| 92 | +- [GitHub Copilot](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot) - get suggestions to help write code based on your comments and other code open in Visual Studio (paid service with a free trial available) |
| 93 | +- [C#](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) |
| 94 | +- [C# Dev Kit][(https://visualstudio.microsoft.com/services/live-share/](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit)) to add in Visual Studio 2022 features like Solution Explorer, improved Debugging, and Test running |
0 commit comments