VS Code features you need to know
There are a lot of features available in VS Code but there are some that are gonna improve your speed
Snippets
While writing programs we repeat a lot of code, there is a way to tackle that by storing our own boiler plate codes.
- Open Command pallet and type Configure User Snippets
- Select your Programming Language
- Use the Example code to make your own snippet.
$<num> is used to change the cursor location, it can be used to write variable names and other strings that are program specific.
Macros
When you repeat a list of processes regularly there may be a way to automate it in VS Code. You need to install an extension named Macros to create your list of processes and assign it a shortcut.
"macros":{"resetWorkspace":["workbench.action.closeAllEditors","-workbench.files.action.collapseExplorerFolders","-terminal.removeView"]}
I Use this code in settings.json in VS Code to reset my workspace.
Shortcuts
VS Code has a lot of shortcuts to mostly reduce the use of mouse, with this you can make your custom shortcuts and assign them to different tasks.
- Open shortcuts.json from Command Pallet
- At the bottom right there is Define Keybinding option which allows you to create your own shortcut.
{"key": "cmd+n","command": "workbench.action.terminal.new","when": "terminalFocus"}
I use this shortcut to create a new terminal window when terminal is in focus.
To assign a macro that is create to a shortcut, you can use macros.<macros name> in the command key.
Extensions
They are programs created by developers to work with VS Code and solve a cause. Access them with ⌘ + ⇧ + X on Mac or ⌃ + ⇧ + X on Windows.
You can Explore the different extensions in the catalog and install them.
Logging
Instead of using print
to debug the code, which makes a huge mess when the code is deployed. We can use VS Code default logger.
You can access it by right clicking on the row number mentioned at the line of code. You can add an expression by using flower brackets {a+b}
or directly add the name
.
The log expressions are not shipped to the final code.
Debug
First thing that comes to mind to debug a code is to write print statements, but VS code has a debugger that can allow you to stop the code at a particular point during the execution and can resume it.
To explore more you can explore the topics in VS Code.