Visual Studio Code Shortcut Cheat Sheet
VS Code Shortcuts and Essential Extensions
Visual Studio Code, or VS Code, is revered due to its powerful features, simplicity, and extensibility. It's not just an ordinary text editor but an all-in-one tool that makes your coding experience smoother and more efficient.
We'll focus on highlighting crucial keyboard shortcuts for both Windows and macOS users, followed by an introduction of both essential and nuanced extensions that can improve your development workflow.
VS Code Shortcuts for Windows and Mac
The list below aims to save you time, increase your productivity, and reduce reliance on manual approaches.
General Shortcuts
Action | Windows Shortcut | Mac Shortcut |
---|---|---|
Open Command Palette | Ctrl + Shift + P | Shift + Command + P |
Open File | Ctrl + O | Command + O |
Open Folder | Ctrl + K, Ctrl + O | Command + K, Command + O |
Open New File | Ctrl + N | Command + N |
Open New Window | Ctrl + Shift + N | Shift + Command + N |
Go to File | Ctrl + P | Command + P |
Open Recent File/Folder | Ctrl + R | Command + R |
Save | Ctrl + S | Command + S |
Save As... | Ctrl + Shift + S | Shift + Command + S |
Save All | Ctrl + K, S | Option + Command + S |
Close Editor | Ctrl + W/Ctrl + F4 | Command + W |
Open Settings | Ctrl + , | Command + , |
Open Keyboard Shortcuts | Ctrl + K, Ctrl + S | Command + K, Command + S |
Go to Symbol | Ctrl + Shift + O | Shift + Command + O |
Go to Definition | F12 | F12 |
Peek Definition | Alt + F12 | Option + F12 |
Show References | Shift + F12 | Shift + F12 |
Go to Line | Ctrl + G | Command + G |
Go to Bracket | Ctrl + Shift + \ | Shift + Command + \ |
Go to Next/Previous Error or Warning | F8/Shift + F8 | F8/Shift + F8 |
Select Line | Ctrl + L | Command + L |
Select Current Line | Ctrl + L | Command + L |
Select All Occurrences of Current Word | Ctrl + F2 | Command + F2 |
Edit Line in Place | Ctrl + Shift + L | Shift + Command + L |
Cut Line | Ctrl + X | Command + X |
Copy Line | Ctrl + C | Command + C |
Paste Line | Ctrl + V | Command + V |
Delete Line | Ctrl + Shift + K | Shift + Command + K |
Insert Line Above/Below | Ctrl + Enter/Shift + Enter | Command + Enter/Shift + Enter |
Move Line Up/Down | Alt + Up/Down | Option + Up/Down |
Comment/Uncomment Line | Ctrl + / | Command + / |
Toggle Line Comment | Ctrl + / | Command + / |
Add Cursor Above/Below | Ctrl + Alt + Up/Down | Option + Up/Down |
Add Selection to Next Find Match | Ctrl + D | Command + D |
Select All Find Matches | Ctrl + Shift + L | Shift + Command + L |
Multiple Cursor Editing | Alt + Click | Option + Click |
Rename Symbol | F2 | F2 |
Format Document | Shift + Alt + F | Shift + Option + F |
Expand/Collapse Region | Ctrl + Shift+ ], Ctrl + Shift + [ | Option + Command + ], Option + Command + [ |
Undo/Redo | Ctrl + Z/Ctrl + Y | Command + Z/Command + Shift + Z |
Zoom In/Out | Ctrl + =/- | Command + =/- |
Reset Zoom | Ctrl + NumPad0 | Command + NumPad0 |
Toggle Zen Mode | Ctrl + K, Z | Command + K, Z |
Toggle Full Screen | F11 | Control + Command + F |
Toggle Word Wrap | Alt + Z | Option + Z |
Toggle Sidebar | Ctrl + B | Command + B |
Toggle Panel | Ctrl + J | Command + J |
Toggle Problems View | Ctrl + Shift + M | Shift + Command + M |
Toggle Search Details | Ctrl + Shift + J | Shift + Command + J |
Show Integrated Terminal | Ctrl + ` | Control + ` |
Create New Terminal | Ctrl + Shift + ` | Control + Shift + ` |
Jump to Matching Bracket | Ctrl + Shift + \ | Shift + Command + \ |
Navigate editor group history | Ctrl + Shift + Tab | Control + Shift + Tab |
Focus into 1st, 2nd or 3rd editor group | Ctrl + 1/2/3 | Command + 1/Command + 2/Command + 3 |
Open Editors View | Ctrl + K, E | Command + K, E |
Show Debug | Ctrl + Shift + D | Shift + Command + D |
Toggle breakpoint | F9 | F9 |
Start/Continue Debugging | F5 | F5 |
Step into/out of Function | F11 / Shift + F11 | F11 / Shift + F11 |
Step over Function | F10 | F10 |
Stop Debugging | Shift + F5 | Shift + F5 |
Show hover | Ctrl + K, Ctrl + I | Command + K, Command + I |
The table above includes key actions and shortcuts for both Windows and Mac. Keep in mind that the actual keys used might differ depending on the specific keyboard layout and language. You can customize or search for specific shortcuts using the Keyboard Shortcuts editor, accessible with Command + K, Command + S
on macOS or Ctrl + K, Ctrl + S
on Windows. Further details can be found in the Useful Resources section.
FAQs and Useful Insights on Visual Studio Code
1. What differentiates Visual Studio Code from Visual Studio?
Visual Studio Code (VS Code) and Visual Studio are both powerful development tools by Microsoft, but they cater to different needs. VS Code is a lightweight, open-source code editor focused on speed, ease of use, and extensibility, making it a favorite for web development. It supports a wide range of programming languages and frameworks out of the box or through extensions.
On the other hand, Visual Studio is a full-fledged Integrated Development Environment (IDE) that provides a comprehensive suite of tools for building, debugging, and testing software across various platforms, making it more suited for large-scale enterprise and application development.
Here's a simplified comparison:
Performance and Size: VS Code is faster and requires less disk space as compared to Visual Studio.
Extensibility: Both offer a wide range of extensions, but VS Code's lean core allows for a more straightforward extension experience.
Language Support: Visual Studio has robust support for .NET languages, while VS Code provides broader language support through extensions.
Platform: VS Code is cross-platform, available on Windows, macOS, and Linux, while Visual Studio is mainly for Windows, with a separate version for macOS.
Built-in Tools: Visual Studio comes with more built-in tools such as a robust debugger, form designer, and profiling tools, which are often essential for enterprise-level application development.
2. Why is Visual Studio Code a go-to choice for web developers compared to other text editors and IDEs?
Visual Studio Code (VS Code) carves a niche between the minimalism of text editors like Sublime Text and others, and the comprehensive feature set of Integrated Development Environments (IDEs) like Visual Studio or WebStorm, making it appealing for web developers.
Lightweight and Fast: Initially, VS Code operates with less resource consumption compared to full-fledged IDEs, facilitating a quicker switch between files and projects. However, the resource usage may increase with the addition of extensions.
Extensible: VS Code starts as a basic editor, but its extension ecosystem allows developers to incorporate specific functionalities as needed. This extensibility is particularly beneficial in the dynamic field of web development.
Integrated Tools: Offering built-in Git support, a terminal, and basic debugging tools, VS Code extends a level of integration that can streamline web development workflows, although may not be as comprehensive as some IDEs.
Language and Framework Support: While VS Code provides decent support for web technologies, the level of support can be significantly enhanced with extensions, catering to a versatile range of web development projects.
Community and Ecosystem: The active community and ecosystem around VS Code offer resources, tutorials, and extensions, aiding web developers across different experience levels.
3. What is the role of Emmet in Visual Studio Code, and how does it improve coding efficiency?
As a feature, Emmet is integrated into Visual Studio Code and designed to speed up web development workflows. It allows developers to write HTML, CSS, and other code using concise abbreviations, which then expands into complete code structures. In addition, it supports a variety of file types beyond just HTML and CSS, including XML, XSL, and files that use syntax inherited from these, like PHP, HAML, Pug, and more. Some examples include:
HTML Abbreviations: You can create complex HTML structures using simple expressions. For example, typing
ul>li*5
and then pressingTab
will generate an unordered list with five list items.CSS Abbreviations: You can also use Emmet for writing CSS. For example, typing
p10
and pressingTab
will generatepadding: 10px;
.Numbering: Emmet supports automatic numbering for elements. For example,
ul>li.item$*5
will generate five list items with a class of item1, item2, etc.Custom Snippets: You can create custom snippets in Emmet to further speed up your workflow.
For configuring Emmet within VS Code and understanding its deeper integration, you can visit the Emmet in Visual Studio Code documentation.
4. How can I extend the capabilities of Visual Studio Code for my development needs?
Extending the capabilities of Visual Studio Code is primarily done through extensions available in the Visual Studio Code Marketplace. Here are steps to extend its functionality:
Explore Extensions: Browse and search for extensions in the VS Code Marketplace or directly within VS Code by going to View -> Extensions.
Install Extensions: Click on the install button next to the extension you want to add.
Configure Extensions: Some extensions may require additional configuration, which can usually be done within the settings of VS Code.
Create Your Extensions: If you have unique requirements, you can create and share your own extensions using the VS Code Extensions API.
You can also customize the appearance and behavior of VS Code through settings and themes to create a personalized development environment.
Essential Extensions
Extensions can improve the functionality of VS Code. They are relatively easy to install and set up, and you can find one for almost any purpose. In curating this list, we've considered factors such as longevity, community feedback, popularity within the developer community, and their ability to improve productivity or solve common issues.
Prettier - Code Formatter
The Prettier - Code Formatter extension is a great addition to enhance your code's readability. It is an opinionated code formatter that supports multiple languages and integrates well with most editors, including VS Code. Prettier helps enforce a consistent code style across your project by parsing your code and reprinting it following a set of rules for how your code should look.
This reduces the cognitive load of reading code and leaves no room for debates around code style in code reviews. Be aware that Prettier's opinions may not always align with the preferred code style for specific projects, and while it does offer some configuration options, they are limited compared to ESLint.
ESLint
If you're working with JavaScript, ESLint is a highly recommended extension. It integrates the popular JavaScript linting utility, ESLint, directly into VS Code, providing real-time feedback and highlighting potential issues as you code. Its primary function is to enforce code quality and maintain coding standards across your projects.
It's highly configurable, allowing you to set your own linting rules or adopt preset configurations. However, the flexibility and power of ESLint also come with a bit of a learning curve. Configuring it to match your project's needs can be somewhat complex for beginners, but its utility in improving code quality is often worth the effort.
Path IntelliSense
Path IntelliSense is a useful extension for developers dealing with larger projects or navigating through deeply nested file structures. It improves productivity by autocompleting filenames in your code, saving time and reducing the chance of errors caused by manual typing.
With this extension, you only need to remember the initial parts of your directory or file names, and it will suggest the rest. While it generally works well out of the box, remember that the efficiency of the autocomplete feature might vary based on the structure and complexity of your project.
Live Server
Live Server provides a local development server for your static and dynamic pages. It greatly simplifies the testing process by instantly reloading your web page in the browser whenever changes are made to the source code. This feature is particularly beneficial for smaller projects, and when working with HTML, CSS, and JavaScript files, allowing for immediate visual feedback and quicker iterations during development.
Do note that Live Server is best suited for simple and smaller-scale web projects. For larger, more complex projects that require a full-fledged backend setup, you might need a more advanced development server setup.
Git Graph
Git Graph is an extension that visualizes the commit history and branching structure of your Git repositories right within VS Code. This extension can be a significant boon for developers seeking to understand the progression and narrative of a project, especially in a collaborative setting. It provides a quick, visual, and interactive way to understand when, how, and by whom changes were introduced.
Git Graph supports a myriad of Git functionalities such as comparing commits, code diff viewing, merging, cherry-picking, rebasing, and much more, all from a visually intuitive interface. Note that while Git Graph is highly useful for visualizing Git repositories, it doesn't replace a thorough understanding of Git commands and processes.
Additional Curated Extensions
Beyond the essential extensions, we've curated a few more that our developers find helpful. These extensions, selected from daily workflows, cater to more specific or niche aspects, potentially uncovering new ways to address strenuous tasks.
TabOut
TabOut is a simple yet effective extension that streamlines cursor movement within your code. When the cursor is next to a bracket or quote, pressing the Tab key moves the cursor outside, saving you a few keystrokes usually spent on reaching for the arrow keys. This is especially handy in situations with nested code or complex expressions, helping to expedite the coding process.
The extension is active by default but can be disabled in your settings with the "tabout.disableByDefault": true
command. You can also toggle the extension on and off with the 'Toggle TabOut' command. The characters to TabOut from are configurable in your settings, allowing for personalized customization to match your coding style.
Error Lens
Error Lens underlines faulty code and brings diagnostic messages to the forefront by placing them right next to the code snippets they refer to. It highlights lines of code with issues and displays messages inline, making it simpler to see what's amiss at a glance.
The extension offers various customization settings like changing the highlight colors, adjusting message display, and providing commands to toggle its features. For instance, with commands like errorLens.toggleError
, you can easily switch on/off the error highlighting as per your needs.
Template String Converter
The Template String Converter is another lean and convenient tool for devs who frequently work with JavaScript template strings.
The extension intelligently identifies when you're looking to leverage template literals and automatically converts standard quotes ""
or ''
to backticks upon typing ${
. With this, you can speed up the process of embedding expressions within strings, without the need for manual conversion.
Some noteworthy features and settings include:
Auto-correction: If you decide to delete the
$
sign or{
, the extension smartly replaces the backticks with the original quotes.Nested Quotes: In situations with nested quotes, you have the option to convert the outermost ones to backticks.
Nested Template Literals: Even within an existing template string, it's possible to further convert strings to template literals upon recognizing
${
.JSX Support: For JSX properties, there's a setting that allows the addition of brackets around the property when converting to a template string.
To refresh your memory, you can read about Template Literals in our Template Literals in ES6 JavaScript guide. Also, feel free to check out the useful resources found below.
Useful Resources
Advanced Customization for Keyboard Shortcuts in VS Code
JavaScript Snippets for Quick Reference
Git Cheat Sheet - A Detailed Reference
10 Must-Follow GitHub Repositories for Developers of All Levels