Essential VS Code Shortcuts to Save Time

Visual Studio Code (VS Code) is a powerful and highly customizable code editor that is used by developers throughout the world. Although its capabilities and extensions are widely recognised, learning shortcuts can significantly increase your coding speed and efficiency. Some of the most helpful VS Code shortcuts that every developer should be aware of are presented in this blog.

Why Learn Shortcuts?

Using shortcuts in VS Code offers several benefits:

  • Saves Time: Navigate and edit code faster without using the mouse.

  • Improves Workflow: Streamline repetitive tasks.

  • Reduces Context Switching: Keep your hands on the keyboard and stay focused.

Essential VS Code Shortcuts

Here are some essential shortcuts categorized by functionality. These work on Windows/Linux and macOS (where applicable, macOS shortcuts are in parentheses):

General Shortcuts

  • Command Palette: Ctrl + Shift + P (Cmd + Shift + P)
    Access all available commands and features.

  • Open File: Ctrl + P (Cmd + P)
    Quickly open files in your project.

  • Toggle Sidebar: Ctrl + B (Cmd + B)
    Show or hide the sidebar.

  • Split Editor: Ctrl + \ (Cmd + \)
    Open the same file in a split view.

  • Close Editor: Ctrl + W (Cmd + W)
    Close the current editor tab.

Navigation Shortcuts

  • Go to Line: Ctrl + G (Cmd + G)
    Jump to a specific line in the current file.

  • Go to Definition: F12
    Navigate to the definition of a function, variable, or class.

  • Peek Definition: Alt + F12 (Option + F12)
    View the definition in a small popup.

  • Navigate Back/Forward: Alt + Left/Right (Cmd + Alt + Left/Right)
    Move through your cursor鈥檚 history.

Editing Shortcuts

  • Select Line: Ctrl + L (Cmd + L)
    Select the entire current line.

  • Copy Line Up/Down: Alt + Shift + Up/Down (Option + Shift + Up/Down)
    Duplicate the current line.

  • Move Line Up/Down: Alt + Up/Down (Option + Up/Down)
    Move the current line of code up or down.

  • Delete Line: Ctrl + Shift + K (Cmd + Shift + K)
    Delete the entire line.

  • Format Document: Shift + Alt + F (Shift + Option + F)
    Auto-format the code using your configured formatter.

Multi-Cursor and Selection Shortcuts

  • Add Cursor Above/Below: Ctrl + Alt + Up/Down (Cmd + Option + Up/Down)
    Add multiple cursors for simultaneous editing.

  • Select Next Occurrence: Ctrl + D (Cmd + D)
    Select the next occurrence of the highlighted word.

  • Undo Last Cursor: Ctrl + U (Cmd + U)
    Remove the last added cursor.

  • Select All Occurrences: Ctrl + Shift + L (Cmd + Shift + L)
    Select all occurrences of the highlighted word.

Search and Replace Shortcuts

  • Find: Ctrl + F (Cmd + F)
    Open the search bar for the current file.

  • Replace: Ctrl + H (Cmd + H)
    Find and replace text in the current file.

  • Find in Files: Ctrl + Shift + F (Cmd + Shift + F)
    Search across all files in the project.

  • Replace in Files: Ctrl + Shift + H (Cmd + Shift + H)
    Replace text across all files.

Terminal Shortcuts

Toggle Terminal: Ctrl + ~ (Cmd + ~)
Show or hide the integrated terminal.

  • Create New Terminal: Ctrl + Shift + 路 (Cmd + Shift + 路)
    Open a new terminal instance.

Debugging Shortcuts

  • Start/Continue Debugging: F5
    Begin or continue debugging.

  • Step Over: F10
    Skip to the next line in the code without stepping into functions.

  • Step Into: F11
    Dive into the function being called.

  • Step Out: Shift + F11
    Return to the calling function.

  • Stop Debugging: Shift + F5
    Terminate the debugging session.


Customizing Shortcuts

VS Code allows you to customize shortcuts to fit your workflow:

  1. Open the Keyboard Shortcuts settings: Ctrl + K Ctrl + S (Cmd + K Cmd + S).

  2. Search for a specific command.

  3. Click the pencil icon to edit and assign a new shortcut.


Conclusion

Mastering VS Code shortcuts can significantly boost your efficiency as a developer. Start by learning a few essential shortcuts and gradually expand your repertoire. Over time, these will become second nature, helping you code faster and smarter.

What are your favorite VS Code shortcuts? Let us know in the comments below! 馃槉