Vscode Start
# Getting Started with VS Code: Opening Projects and Running Code
Visual Studio Code (VS Code) is a lightweight, powerful, and highly extensible source-code editor. Whether you need to edit a single file or manage a complex project directory, VS Code makes the process seamless.
This tutorial will guide you through the basics of starting with VS Code, including opening directories, creating files, and setting up a simple Python development environment.
---
## Opening Files and Directories
When you launch VS Code for the first time, you will be greeted by the **Welcome Page**. This page provides quick shortcuts to get you started.
### 1. Opening a File or Folder via the Welcome Page
On the Welcome Page, you can quickly start your work by selecting:
* **New File...**: Creates a blank, untitled file.
* **Open...** (or **Open Folder...**): Opens an existing file or directory from your local machine.
### 2. Opening via the Menu Bar
Alternatively, you can use the top menu bar:
* Go to **File** > **Open File...** to open a single file.
* Go to **File** > **Open Folder...** to open an entire project directory.
---
## Creating and Running a Python File
To demonstrate how to write and execute code in VS Code, we will walk through creating and running a simple Python script.
### Step 1: Create a New File
1. Open VS Code and click on **New File** on the Welcome Page (or press `Ctrl + N` on Windows/Linux, `Cmd + N` on macOS).
2. Click on **Select a language** in the newly opened editor tab.
3. Type **Python** in the search box and select it from the dropdown list.
### Step 2: Write the Code
Type the following basic Python code into the editor:
```python
print("Runoob")
```
### Step 3: Run Code in the Interactive Window
1. Right-click anywhere inside the editor window.
2. Select **Run Current File in Interactive Window**.
3. **Note:** If VS Code prompts you to install the Python extension or Jupyter extension, click **Install**. If you do not install these extensions, the editor may get stuck trying to connect to the Python kernel.
---
## Working with a Project Directory (Workspace)
For real-world development, it is best practice to open a folder (workspace) rather than editing isolated files. This allows you to manage multiple files and configure project-specific settings.
### Step 1: Open a Project Folder
1. Create a folder on your computer named `runoob-test` (or any name you prefer).
2. In VS Code, go to **File** > **Open Folder...** and select your newly created folder.
> **Note:** Once opened, you might see a `.vscode` folder automatically generated inside your directory. This folder contains workspace-specific configuration settings (such as linter rules, debug configurations, and path settings) and can be ignored for now.
### Step 2: Create a New File in the Directory
1. In the **Explorer** sidebar on the left, hover over your folder name and click the **New File** icon (or right-click and select **New File**).
2. Name the file `test.py` and press `Enter`.
### Step 3: Write and Execute Your Code
Add the following code to `test.py`:
```python
print("Runoob")
```
There are multiple ways to run this script:
#### Method A: Using the Play Button
Click the green **Play (Run Python File)** button located in the top-right corner of the editor window. This will automatically open the integrated terminal and execute your script.
#### Method B: Right-Clicking the File
Right-click the `test.py` file in the Explorer sidebar and select **Run Python File in Terminal**.
#### Method C: Right-Clicking the Editor
Right-click anywhere inside the code editor window and select **Run Python File in Terminal**.
---
## Key Considerations for Beginners
* **Install the Python Extension:** To get syntax highlighting, code completion (IntelliSense), and debugging support, make sure you install the official **Python extension** by Microsoft from the VS Code Extensions Marketplace (`Ctrl + Shift + X` or `Cmd + Shift + X`).
* **Select the Correct Interpreter:** If your code does not run, ensure VS Code has detected your Python installation. You can select your Python interpreter by pressing `Ctrl + Shift + P` (or `Cmd + Shift + P` on macOS), typing `Python: Select Interpreter`, and choosing your installed Python version.
* **Workspace Settings:** The `.vscode` folder is highly useful. If you share your project via Git, committing this folder allows your team members to share the same debug and formatting configurations.
YouTip