Swiftorial Logo
Home
Swift Lessons
Tutorials
Learn More
Career
Resources

Using the Terminal in VS Code

Introduction

The integrated terminal in Visual Studio Code (VS Code) allows you to run command-line commands directly from the editor. This is an invaluable feature for developers, as it streamlines the workflow by allowing you to execute commands without switching between applications.

Opening the Terminal

To access the integrated terminal in VS Code, you can use the following methods:

  • From the menu, select Terminal > New Terminal.
  • Use the keyboard shortcut Ctrl + ` (the backtick key).

Once opened, the terminal appears at the bottom of the VS Code window.

Terminal > New Terminal

Basic Terminal Commands

Here are some basic commands you can run in the terminal:

  • pwd: Prints the current working directory.
  • ls: Lists files and directories in the current directory.
  • cd [directory]: Changes the current directory to the specified directory.
  • mkdir [directory]: Creates a new directory.
  • rm [file]: Deletes a specified file.

pwd

/Users/yourusername/projects

Running Scripts

You can also run scripts directly from the terminal. For example, if you have a Node.js application, you can start it by running:

node app.js

Server is running on port 3000

To run a Python script, you would use:

python script.py

Hello, World!

Customizing the Terminal

VS Code allows you to customize the terminal's appearance. You can change the font size, colors, and even the shell. To do this:

  1. Open settings by going to File > Preferences > Settings.
  2. Search for Terminal settings.
  3. Modify the desired settings, such as Font Size or Shell Path.

Change font size in settings

Using Multiple Terminals

You can create multiple terminal instances in VS Code. This is useful for running different tasks simultaneously. To create a new terminal instance, click on the plus (+) icon in the terminal panel or use the shortcut Ctrl + Shift + `.

New terminal instance

Keyboard Shortcuts for Terminal

Here are some useful keyboard shortcuts for managing the terminal:

  • Ctrl + `: Toggle the terminal.
  • Ctrl + Shift + `: Create a new terminal.
  • Ctrl + C: Copy selected text in the terminal.
  • Ctrl + V: Paste into the terminal.
  • Ctrl + Shift + C: Copy the entire terminal output.

Conclusion

The integrated terminal in Visual Studio Code is a powerful tool that enhances productivity by allowing developers to execute commands and run scripts without leaving the editor. By familiarizing yourself with its features and commands, you can streamline your development process significantly.