TTT #3: Hidden Gems of the VSCode CLI Tool

Stephen CollinsJul 29, 2023

Newsletter Issue: Unlocking the Hidden Gems of the VSCode CLI Tool

While most developers are familiar with the basics of Visual Studio Code, there’s still a lot more useful features that can be found in it’s command line interface (CLI) tool - code. This powerful tool unlocks new workflows and abilities you might not have considered. Today, we’re going to explore a few of the more uncommon commands that code offers.

1. Opening a Specific Line and Column

Did you know you can instantly navigate to a particular line and column in a file using the CLI? The format is quite simple:

code --goto <file>:<line>:<column>

For instance, to open app.js on line 50 and column 5, you’d use:

code --goto app.js:50:5

2. Open a New Window in Diff Mode

Diff mode is invaluable when comparing changes between two files. Though you might be accustomed to using extensions or other tools, code makes it just a command away:

code -d <file1> <file2>

This opens a new VSCode window showing the differences between file1 and file2.

3. Extensions Management from the CLI

Managing extensions directly from the command line can be pretty useful, especially for those maintaining shared development environments.

  • Listing all installed extensions:

    code --list-extensions
  • Installing a new extension:

    code --install-extension <extension-id>
  • Uninstalling an extension:

    code --uninstall-extension <extension-id>

You can streamline your environment setup or share a list of mandatory extensions with your team using these commands.

4. Disabling GPU Acceleration

On rare occasions, you might experience graphical issues due to GPU acceleration. Thankfully, there’s a command to bypass this:

code --disable-gpu

This launches VSCode with GPU acceleration turned off, sidestepping any potential rendering problems.

Wrapping Up

These commands, while a little less known, showcase the flexibility and depth of the code CLI tool. Whether you’re aiming for increased productivity, unique workflows, or just love playing around with nifty commands, the potential is vast. Dive in and explore!

To get a complete list of commands and their descriptions, remember:

code --help