Ora

How do you save changes in VSCode?

Published in VSCode File Management 4 mins read

To save changes in VSCode, the most straightforward methods are using keyboard shortcuts like Ctrl + S (Windows/Linux) or Cmd + S (macOS), or by selecting File > Save from the top menu. These actions ensure your modifications are written to the disk, preserving your work.

Essential Ways to Save Your Work

Visual Studio Code provides several intuitive ways to save your open files, catering to different workflows and preferences.

Using Keyboard Shortcuts

The quickest and most common way to save a single file is by using platform-specific keyboard shortcuts. This method is highly recommended for its efficiency.

  • For Windows and Linux users: Press Ctrl + S
  • For macOS users: Press Cmd + S

These shortcuts will instantly save the active file in the editor.

Operating System Shortcut Action
Windows / Linux Ctrl + S Save active file
macOS Cmd + S Save active file

Through the File Menu

If you prefer using the mouse or are new to VSCode, the top menu bar offers a clear path to saving your files.

  1. Navigate to the File menu at the top of the VSCode window.
  2. Click on Save.

This action will save the currently focused file.

Advanced Saving Options

VSCode offers more than just basic saving, providing robust features for managing your files and workspaces.

Save As: Renaming and Relocating Files

Sometimes you need to save a file under a new name or in a different location. The "Save As" function is perfect for this.

  1. Go to File > Save As...
  2. A dialog box will appear, allowing you to specify a new file name and choose a different directory.

This is particularly useful when you're creating a copy of an existing file or saving an untitled file for the first time.

Save All: Preserving All Open Changes

When working with multiple files simultaneously, tracking unsaved changes across all tabs can be tedious. "Save All" is your go-to option to save every modified file with a single command.

  1. Navigate to File > Save All.
  2. Alternatively, use the shortcut: Ctrl + K S (press Ctrl+K, then release and press S) on Windows/Linux, or Cmd + K S on macOS.

This action will iterate through all open files that have unsaved changes and save them.

Auto Save: Set It and Forget It

For developers who want to avoid manually saving, VSCode's Auto Save feature is a game-changer. Once enabled, VSCode will automatically save your changes based on your chosen setting, significantly reducing the risk of losing work due to accidental closures or crashes.

To enable or configure Auto Save:

  1. Go to File > Auto Save.
  2. Select one of the following options:
    • Off: You must manually save all files.
    • After Delay: Files are saved automatically a set number of milliseconds after you stop typing.
    • On Focus Change: Files are saved when you move focus away from the VSCode window.
    • On Window Change: Files are saved when you switch to another VSCode window.

You can also adjust the Auto Save delay in your VSCode settings by searching for "Auto Save" (e.g., File > Preferences > Settings or Code > Preferences > Settings on macOS).

Recognizing Unsaved Changes

VSCode provides a clear visual indicator for unsaved changes. Any file tab with unsaved modifications will display a small white dot (or circle) next to its name. Once the file is saved, this dot disappears, confirming that your changes are preserved.

Best Practices for Saving in VSCode

  • Save Frequently: Even with Auto Save enabled, it's a good habit to hit Ctrl + S or Cmd + S often, especially before running code or making significant changes.
  • Utilize Auto Save: For peace of mind and to reduce repetitive manual saving, configure Auto Save to your preferred behavior.
  • Understand Save vs. Save As: Use Save for updating an existing file and Save As for creating a new version or moving a file.
  • Backup Your Work: While saving in VSCode writes to your local disk, consider using version control systems like Git and cloud storage solutions for robust backups and collaboration.