Top Shortcut Keys and Hacks for Visual Studio Code (VSCode)
Tags: vscode, webdev, javascript, beginners
Published: 2023-06-02 13:56:37

<p data-pm-slice="1 1 []">Visual Studio Code (VSCode) has become one of developers' most popular code editors due to its powerful features, extensibility, and cross-platform compatibility.</p>
Mastering the essential shortcut keys and leveraging clever hacks in VSCode is essential to enhance your productivity further and streamline your coding workflow.

This article will explore the top shortcut keys and hacks to help you work more efficiently and save valuable time using VSCode.
<h2>Essential Shortcut Keys:</h2>
<strong>Opening and closing VSCode: Quickly launch or close the editor</strong> - Launching and closing Visual Studio Code (VSCode) efficiently can save valuable time and streamline your workflow.

Open the terminal or command prompt and navigate to the folder you want to open. For example:

<code>cd /path/to/my-project</code>

Type the following command and press Enter:

<code>code .</code>

This command will open the "my-project" folder in VSCode.

Remember to replace "/path/to/my-project" with the path to your desired folder.

Using these methods to open and close VSCode, you can quickly start coding and efficiently manage your coding sessions.
<ul>
 	<li>Basic navigation: Efficiently move around your codebase - Visual Studio Code (VSCode) provides a variety of keyboard shortcuts that allow you to move quickly within your code. Here are some essential shortcut keys for basic navigation in VSCode:</li>
</ul>
<ul>
 	<li><strong>Moving the Cursor</strong>:

Up: Arrow Up

Down: Arrow Down

Left: Arrow Left

Right: Arrow Right</li>
</ul>
<ul>
 	<li><strong>Word-level Navigation</strong>:

Move to the beginning of a word: Ctrl + Arrow Left (Windows/Linux), Option + Arrow Left (Mac)

Move to the end of a word: Ctrl + Arrow Right (Windows/Linux), Option + Arrow Right (Mac)</li>
</ul>
<ul>
 	<li><strong>Line-level Navigation</strong>:
<ul>
 	<li>Move to the start of the line: Home</li>
 	<li>Move to the end of the line: End</li>
 	<li>Move to the beginning of the file: Ctrl + Home (Windows/Linux), Command + Home (Mac)</li>
 	<li>Move to the end of the file: Ctrl + End (Windows/Linux), Command + End (Mac)</li>
</ul>
<strong>Page-level Navigation</strong>:

Scroll up one page: Page Up

Scroll down one page: Page Down</li>
 	<li><strong>Jumping between Sections</strong>:
<ul>
 	<li>Go to the beginning of the file: Ctrl + Home (Windows/Linux), Command + Home (Mac)</li>
 	<li>Go to the end of the file: Ctrl + End (Windows/Linux), Command + End (Mac)</li>
 	<li>Go to a specific line: Ctrl + G (Windows/Linux), Command + G (Mac), then enter the line number and press Enter</li>
 	<li>Go to a specific file: Ctrl + P (Windows/Linux), Command + P (Mac), then start typing the file name and select from the list</li>
</ul>
</li>
</ul>
<ul>
 	<li><strong>File and Tab Navigation</strong>:

Switch between open tabs: Ctrl + Tab (Windows/Linux), Command + Option + Right Arrow (Mac)

Move to the next open tab: Ctrl + Page Down (Windows/Linux), Control + Tab (Mac)

Move to the previous open tab: Ctrl + Page Up (Windows/Linux), Control + Shift + Tab (Mac)

Close the current tab: Ctrl + W (Windows/Linux), Command + W (Mac)</li>
</ul>
<ul>
 	<li><strong>Splitting and Managing Views</strong>:

Split editor horizontally: Ctrl + \

Split editor vertically: Ctrl + Shift + \

Switch between editor groups: Ctrl + 1/2/3/... (Windows/Linux), Command + 1/2/3/... (Mac)</li>
</ul>
<ul>
 	<li>These shortcut keys will help you navigate your codebase efficiently and save time while moving through your code. By mastering these navigation shortcuts, you can swiftly jump between lines, files, and sections, enhancing your overall coding experience in Visual Studio Code.</li>
</ul>
<h2>Productivity Hacks:</h2>
<ul>
 	<li>Customizing Keybindings:</li>
</ul>
Customizing keybindings in Visual Studio Code (VSCode) allows you to tailor the editor to your specific workflow and preferences. You can create shortcuts or modify existing ones to make your coding experience more efficient.

Creating custom shortcuts
<ul>
 	<li>Open VSCode and go to "File" &gt; "Preferences" &gt; "Keyboard Shortcuts" or use the shortcut Ctrl + K Ctrl + S (Windows/Linux) or Command + K Command + S (Mac).</li>
</ul>
<ul>
 	<li>The keyboard shortcuts file will open, showing the default keybindings on the left and your custom keybindings on the right.</li>
</ul>
<ul>
 	<li>To create a custom shortcut, add a new entry in the "keybindings.json" file by specifying the command and the desired key combination.
<ul>
 	<li>
<pre><code class="language-javascript">{
    "key": "ctrl+shift+1",
    "command": "extension.myCustomCommand",
    "when": "editorTextFocus"
}</code></pre>
</li>
</ul>
</li>
</ul>
In this example, pressing Ctrl + Shift + 1 will execute the "extension.myCustomCommand" command.

Modifying existing shortcuts:
<ul>
 	<li>Open the keyboard shortcuts file as mentioned above.</li>
 	<li>Find the command you want to modify by searching or browsing the default keybindings.</li>
 	<li>Click the pencil icon next to the keybinding you want to change and enter your desired key combination.</li>
</ul>
If you want to change the keybinding for "Comment Line" from Ctrl + / to Ctrl + Shift + /, modify the entry like this:
<pre><code class="language-bash">{
    "key": "ctrl+shift+/",
    "command": "editor.action.commentLine",
    "when": "editorTextFocus"
}</code></pre>
Now, Ctrl + Shift + / will comment or uncomment a line of code.
<ul>
 	<li>Snippets:</li>
</ul>
Snippets are predefined code templates that can be quickly inserted into your code. They help accelerate repetitive code insertion and improve your productivity.

Creating and using snippets:
<ul>
 	<li>Open VSCode and go to "File" &gt; "Preferences" &gt; "User Snippets" or use the shortcut Ctrl + K Ctrl + S (Windows/Linux) or Command + K Command + S (Mac).</li>
 	<li>Select the programming language you want to create a snippet or choose "New Global Snippets File" for snippets applicable across all languages.</li>
 	<li>Add your snippets using a specific syntax in the JSON file that opens.

&nbsp;</li>
</ul>
<ol>
 	<li>To create a snippet for a basic HTML structure:
<pre><code class="language-xml">"HTML Basic Structure": {
    "prefix": "html",
    "body": [
        "&lt;!DOCTYPE html&gt;",
        "&lt;html&gt;",
        "  &lt;head&gt;",
        "    &lt;title&gt;$1&lt;/title&gt;",
        "  &lt;/head&gt;",
        "  &lt;body&gt;",
        "    $2",
        "  &lt;/body&gt;",
        "&lt;/html&gt;"
    ],
    "description": "Basic HTML structure"
}</code></pre>
</li>
</ol>
When you type "html" and press Enter or Tab, the snippet will be inserted, and you can navigate through the placeholders ($1, $2) and customize them.

Shortcut for inserting snippets:
<ul>
 	<li>Type the prefix of the snippet you want to insert and press Tab.</li>
 	<li>Alternatively, press Ctrl + Space to trigger IntelliSense and choose the desired snippet from the dropdown.</li>
</ul>
<ul>
 	<li>Integrated Terminal</li>
</ul>
The integrated terminal in VSCode allows you to run commands and scripts without leaving the editor, enhancing your productivity.

Opening and managing the integrated terminal:
<ul>
 	<li>Open the integrated terminal using the shortcut Ctrl + <strong>(Windows/Linux) or Command +</strong> (Mac).</li>
 	<li>To split the terminal vertically or horizontally, press Ctrl + Shift + 5 (Windows/Linux) or Command + Option + 5 (Mac) or right-click inside the terminal and select "Split Terminal" from the context menu.</li>
 	<li>You can switch between multiple terminal instances using the shortcut Ctrl + <strong>(Windows/Linux) or Command +</strong> (Mac), followed by the number corresponding to the terminal instance.</li>
</ul>
<ul>
 	<li>Running commands and scripts:</li>
</ul>
<ul>
 	<li>
<ul>
 	<li>
<ul>
 	<li>Type your desired command or script directly into the terminal and press Enter to execute it.</li>
 	<li>You can also use the up and down arrow keys to navigate your command history.</li>
 	<li>If you frequently run specific commands or scripts, you can create tasks in the VSCode's task runner and execute them from the integrated terminal.</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
 	<li><strong>Extensions and Plugins</strong>
<ul>
 	<li>Extensions and plugins are powerful tools that extend the functionality of VSCode, allowing you to boost your productivity by adding new features and capabilities.</li>
</ul>
Installing and managing extensions:
<ol>
 	<li>Click on the "Extensions" icon in the left sidebar of VSCode or use the shortcut Ctrl + Shift + X (Windows/Linux) or Command + Shift + X (Mac) to open the extensions marketplace.</li>
 	<li>Search for the desired extension and click on the "Install" button.</li>
 	<li>Once installed, the extension will appear in the list of installed extensions, where you can enable, disable, or uninstall it as needed.</li>
</ol>
</li>
</ul>
<ul>
 	<li><strong>Popular extensions for productivity</strong>
<ul>
 	<li><a class="attrlink" href="https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens" target="_blank" rel="noopener noreferrer nofollow">GitLens</a> provides enhanced Git functionality, allowing you to explore Git repositories, view blame annotations, and more.</li>
 	<li><a class="attrlink" href="https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer-2" target="_blank" rel="noopener noreferrer nofollow">Bracket Pair Colorizer</a>" helps you visualize matching brackets with colour highlighting, making navigating and understanding your code structure easier.</li>
 	<li>"<a class="attrlink" href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer" target="_blank" rel="noopener noreferrer nofollow">Live Server</a>" enables a live-reloading local development server, making previewing and testing web applications convenient.</li>
 	<li>ESLint" or "Prettier" assists in formatting and linting, ensuring consistent code style and identifying potential errors.</li>
</ul>
</li>
</ul>
<ul>
 	<li>By customizing keybindings, utilizing snippets, leveraging the integrated terminal, and exploring extensions, you can significantly enhance your productivity in VSCode.</li>
</ul>
<ul>
 	<li>Experiment with these productivity hacks and discover the ones that best suit your workflow, enabling you to code more efficiently and effectively.</li>
</ul>
<h2>Advanced Hacks</h2>
<ul>
 	<li>Debugging Shortcuts on VSCode</li>
</ul>
Debugging is an essential part of the development process, and Visual Studio Code (VSCode) provides powerful features to help you debug your code effectively. Here are some useful shortcuts for debugging in VSCode:

Debugging code
<ul>
 	<li>
<ul>
 	<li>Start debugging: F5</li>
 	<li>This shortcut starts debugging your code. It launches the debugger and begins executing your program.</li>
 	<li>Stop debugging: Shift + F5.</li>
 	<li>Pressing Shift + F5 stops the debugger and terminates the debugging session. It halts the execution of your program.</li>
 	<li>Restart debugging: Ctrl + Shift + F5</li>
 	<li>Use this shortcut to restart the debugging session. It stops the debugger and starts it again from the beginning.</li>
</ul>
</li>
</ul>
<ul>
 	<li>Breakpoints and stepping through code
<ul>
 	<li>Toggle breakpoint: F9</li>
 	<li>Place the cursor on the line where you want to set a breakpoint and press F9. It adds or removes a breakpoint at that line. Breakpoints pause the execution of your program at that specific line, allowing you to inspect variables and step through the code.</li>
 	<li>Step over: F10</li>
 	<li>Pressing F10 allows you to execute the current line of code and move to the next line. If the current line contains a function call, it will not step into that function but instead execute it as a single step.</li>
 	<li>Step into: F11</li>
 	<li>Use F11 to step into a function call. If the current line contains a function call, pressing F11 will take you inside that function, allowing you to debug it line by line.</li>
 	<li>Step out: Shift + F11</li>
 	<li>When you are inside a function while debugging, Shift + F11 allows you to step out of that function and return to the caller function.</li>
</ul>
</li>
</ul>
<ol>
 	<li>Additionally, you can use the following shortcuts while debugging to control program flow:
<ul>
 	<li>Continue: F5</li>
 	<li>Pressing F5 resumes the execution of your program from the current breakpoint until it reaches the next breakpoint or completes.</li>
 	<li>Restart: Ctrl + Shift + F5</li>
 	<li>Use Ctrl + Shift + F5 to restart the debugging session from the beginning, discarding any previous state.</li>
 	<li>Stop: Shift + F5</li>
 	<li>Pressing Shift + F5 stops the debugger and terminates the debugging session.</li>
</ul>
</li>
</ol>
These shortcuts will streamline your debugging process in VSCode, allowing you to set breakpoints, navigate through your code, and analyze program execution efficiently.
<ul>
 	<li><strong>Version Control Shortcuts on VSCode</strong></li>
</ul>
Version control is a crucial aspect of software development, and Visual Studio Code (VSCode) provides seamless integration with Git, making it easier to manage and track changes in your codebase. Here are some useful shortcuts for version control in VSCode

Git integration:
<ul>
 	<li>
<ul>
 	<li>Open the Source Control view: Ctrl + Shift + G</li>
 	<li>Pressing Ctrl + Shift + G opens the Source Control view in VSCode. This view provides a visual representation of your Git repository, showing modified files, branches, and other Git-related information.</li>
 	<li>Stage changes: Ctrl + Enter</li>
 	<li>With a file selected in the Source Control view, pressing Ctrl + Enter stages the changes in that file. Staging prepares the changes to be committed in the next Git commit.</li>
 	<li>Commit changes: Ctrl + Enter</li>
 	<li>After staging your changes, pressing Ctrl + Enter allows you to commit those changes. It opens a commit message input box where you can enter a meaningful commit message.</li>
 	<li>Push changes: Ctrl + Shift + Enter</li>
 	<li>Once you have committed your changes, pressing Ctrl + Shift + Enter pushes those commits to the remote repository.</li>
</ul>
</li>
</ul>
<ul>
 	<li><strong>Common version control commands</strong>
<ul>
 	<li>Open the Command Palette: Ctrl + Shift + P</li>
 	<li>Use Ctrl + Shift + P to open the Command Palette in VSCode. You can access various version control commands by typing their names, such as "Git: Pull" or "Git: Fetch."</li>
 	<li>Switch branches: Ctrl + Shift + P, then type "Git: Checkout to..."</li>
 	<li>Press Ctrl + Shift + P to open the Command Palette, then type "Git: Checkout to..." and select the desired branch to switch to it quickly.</li>
 	<li>View Git blame annotations: Ctrl + Shift + P, then type "Git: Blame"</li>
 	<li>Use Ctrl + Shift + P to open the Command Palette, then type "Git: Blame" to view Git blame annotations. Blame annotations show who last modified each line of code in a file.</li>
 	<li>View Git history: Ctrl + Shift + P, then type "Git: View History"</li>
 	<li>Press Ctrl + Shift + P to open the Command Palette, then type "Git: View History" to access the Git history view. This view displays the commit history of the current branch, allowing you to navigate through the commits and inspect changes.</li>
</ul>
</li>
</ul>
These shortcuts will simplify your Git workflow in VSCode, enabling you to perform version control operations efficiently, switch branches, view commit history and collaborate easily.

By mastering these shortcut keys and leveraging clever hacks in VSCode, you can significantly enhance your productivity and streamline your coding workflow.

Remember to practice and gradually incorporate these shortcuts and hacks into your daily coding routine to maximize their effectiveness. With time, you'll become a more efficient developer and accomplish more using Visual Studio Code in less time.

If you discover this, publish thrilling, discover extra thrilling posts like this on <a class="attrlink" href="http://blog.learnhub.africa/" target="_blank" rel="noopener noreferrer nofollow">Learnhub Blog</a>; we write a lot of tech-related topics from <a class="attrlink" href="https://blog.learnhub.africa/category/cloud-computing/" target="_blank" rel="noopener noreferrer nofollow">Cloud computing</a> to <a class="attrlink" href="https://blog.learnhub.africa/category/frontend/" target="_blank" rel="noopener noreferrer nofollow">Frontend Dev</a>, <a class="attrlink" href="https://blog.learnhub.africa/category/security/" target="_blank" rel="noopener noreferrer nofollow">Cybersecurity</a>, <a class="attrlink" href="https://blog.learnhub.africa/category/data-science/" target="_blank" rel="noopener noreferrer nofollow">AI</a> and <a class="attrlink" href="https://blog.learnhub.africa/category/blockchain/" target="_blank" rel="noopener noreferrer nofollow">Blockchain</a>. Take a look at <a class="attrlink" href="https://blog.learnhub.africa/2023/02/16/how-to-build-offline-web-applications/" target="_blank" rel="noopener noreferrer nofollow">How to Build Offline Web Applications. </a>

So, start exploring these shortcuts and hacks today and unlock the full potential of Visual Studio Code!