Skip to content

1.3.2 VS Code Configuration

VS Code project workflow diagram

In this section, we’ll configure VS Code into a development tool that works well for Python and AI learning. You’ll finish editor installation, extension setup, the built-in terminal, and common shortcut settings, so your later coding practice has a stable and convenient workspace.

  • Install VS Code and choose the interface language you prefer
  • Install essential extensions for Python development
  • Learn to use the built-in terminal in VS Code
  • Master 10 of the most commonly used shortcuts
  • Understand AI-assisted programming tools

EditorProsCons
VS CodeFree, lightweight, rich extensions, great AI supportFor large projects, it may be less intelligent than PyCharm
PyCharmStrongest Python support, convenient refactoringCommunity Edition is free but limited; Professional Edition costs money
Vim/NeoVimExtremely fast, geekySteep learning curve

VS Code is currently the most widely used code editor in the world, and it has excellent support for Python and AI development. For beginners, it is the best choice.


Terminal window
# Install with Homebrew (recommended)
brew install --cask visual-studio-code
# Or download from the official website: https://code.visualstudio.com

After installation, configure command-line launch:

  1. Open VS Code
  2. Press Cmd + Shift + P and type “shell command”
  3. Select Shell Command: Install ‘code’ command in PATH

After that, you can use the code command in the terminal to open files and folders:

Terminal window
code . # Open the current folder with VS Code
code ~/projects # Open a specific folder
code hello.py # Open a specific file
Terminal window
# Install with winget
winget install Microsoft.VisualStudioCode
# Or download from the official website: https://code.visualstudio.com

During installation, check “Add to PATH” so you can use the code command in the terminal.

Terminal window
# Method 1: use snap (recommended)
sudo snap install code --classic
# Method 2: use apt
sudo apt install software-properties-common apt-transport-https wget
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
sudo apt update
sudo apt install code

  1. Open VS Code
  2. Press Ctrl + Shift + X (Cmd + Shift + X on macOS) to open the Extensions panel
  3. Search for the language pack you prefer, such as English Language Pack, Chinese (Simplified), or Japanese Language Pack
  4. Click Install
  5. Restart VS Code, and the interface will switch to that language

Open the Extensions panel (the square icon on the left sidebar, or press Ctrl/Cmd + Shift + X), then search for and install the following extensions:

ExtensionPurposeSearch keyword
PythonPython syntax support, debugging, runningms-python.python
PylancePython intelligent suggestions, type checkingms-python.vscode-pylance
JupyterRun notebooks in VS Codems-toolsai.jupyter
GitLensEnhanced Git features, see who changed which lineeamodio.gitlens
Black FormatterFormat Python code consistentlyms-python.black-formatter
ExtensionPurpose
autoDocstringAutomatically generate Python function docstrings
RuffFast linting and import cleanup for Python
indent-rainbowUse colors to distinguish indentation levels
Error LensShow error messages directly at the end of code lines
Material Icon ThemeMore attractive file icons

After installing the Python extension, you need to tell VS Code which Python environment to use:

  1. Press Ctrl/Cmd + Shift + P to open the Command Palette
  2. Type Python: Select Interpreter
  3. Select the conda environment you created earlier (for example, ai-course)

You should see a list of options like this:

Python 3.11.7 ('ai-course') ~/miniconda3/envs/ai-course/bin/python
Python 3.12.1 ('base') ~/miniconda3/bin/python

Choose the ai-course one.


VS Code comes with a built-in terminal, so you don’t need to open a separate terminal window.

Shortcut: Ctrl + ` (the key in the upper-left corner of the keyboard, below ESC)

Or from the menu: Terminal → New Terminal

Example: complete the full development workflow in VS Code

Section titled “Example: complete the full development workflow in VS Code”
Terminal window
# 1. Activate the environment in the terminal
conda activate ai-course
# 2. Create a project folder
mkdir my-first-project
cd my-first-project
# 3. Open this folder with VS Code (it will open in a new window)
code .

Then in VS Code:

  1. In the file explorer on the left, click the New File icon and create hello.py
  2. Write the code:
name = input("What is your name?")
print(f"Hello, {name}! Welcome to the AI world 🤖")
  1. Click the ▶ Run button in the upper-right corner (or press Ctrl/Cmd + Shift + P → “Run Python File”)
  2. Check the output in the terminal
  • Multiple terminals: click the + button in the top-right of the terminal panel to open more terminals
  • Split view: you can split the editor and terminal side by side, so you can write code while watching the terminal
  • Terminal type: you can choose different shells such as bash, zsh, and PowerShell

You don’t need to memorize everything. First remember the top 5, and look up the rest when you need them.

ActionWindows/LinuxmacOS
Command Palette (most important!)Ctrl + Shift + PCmd + Shift + P
Quick Open FileCtrl + PCmd + P
Open/Close TerminalCtrl + `Ctrl + `
SaveCtrl + SCmd + S
UndoCtrl + ZCmd + Z
ActionWindows/LinuxmacOS
Duplicate current lineShift + Alt + ↓Shift + Option + ↓
Move current lineAlt + ↑/↓Option + ↑/↓
Delete current lineCtrl + Shift + KCmd + Shift + K
Multi-cursor editingAlt + ClickOption + Click
Comment codeCtrl + /Cmd + /
Format codeShift + Alt + FShift + Option + F
ActionWindows/LinuxmacOS
Global searchCtrl + Shift + FCmd + Shift + F
Search within fileCtrl + FCmd + F
Find and replaceCtrl + HCmd + Option + F
Go to lineCtrl + GCtrl + G

Example: the power of multi-cursor editing

Section titled “Example: the power of multi-cursor editing”

Suppose you need to rename 5 variable names from data1, data2… to dataset1, dataset2…:

data1 = load("file1.csv")
data2 = load("file2.csv")
data3 = load("file3.csv")
data4 = load("file4.csv")
data5 = load("file5.csv")

Steps:

  1. Select the first data
  2. Press Ctrl/Cmd + D five times to select all data occurrences one by one
  3. Type dataset

All 5 places are changed at the same time, and it’s done in 2 seconds.


There are now many AI tools that can help you write code in VS Code. As a learner in an AI course, it’s worth knowing about them:

  • Automatically completes code as you type
  • Press Tab to accept suggestions
  • Eligible education accounts may receive free access through GitHub Education
  • Extension search: GitHub.copilot
  • Free AI code completion tool
  • Similar to Copilot, completely free for individual users
  • Extension search: Codeium.codeium

Press Ctrl/Cmd + , to open Settings, then search for and change the following options:

SettingRecommended valueReason
Auto SaveafterDelayAuto-save so you never have to worry about forgetting Ctrl+S
Font Size14 or 15Slightly larger code font, easier on the eyes
Tab Size4Standard Python indentation
Word WraponAutomatically wrap long lines
MinimapoffTurn off the small map on the right to save screen space

Or edit settings.json directly (Ctrl/Cmd + Shift + P → “Open Settings JSON”):

{
"files.autoSave": "afterDelay",
"editor.fontSize": 14,
"editor.tabSize": 4,
"editor.wordWrap": "on",
"editor.minimap.enabled": false,
"python.terminal.activateEnvironment": true,
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.analysis.typeCheckingMode": "basic"
}

  1. Install VS Code and the essential extensions (Python, Pylance, Jupyter, GitLens)
  2. Create a project and open it with VS Code:
Terminal window
mkdir vscode-practice && cd vscode-practice && code .
  1. Create practice.py and write the following code:
# Practice VS Code shortcuts
tasks = [
"load config",
"validate dataset",
"run smoke test",
"write metrics",
"commit changes",
]
for i, task in enumerate(tasks):
print(f"{i + 1}. {task}")
# Calculate the average task label length
avg_len = sum(len(task) for task in tasks) / len(tasks)
print(f"\nAverage task label length: {avg_len:.1f} characters")
  1. Run the code (click the ▶ button in the upper-right corner)
  2. Try these shortcuts:
    • Use Ctrl/Cmd + / to comment out the last two lines
    • Use Alt + ↑/↓ to move one line of code
    • Use Ctrl/Cmd + D to multi-select one word
    • Use Ctrl/Cmd + Shift + F to search globally for “task”
Project reference and review notes
  1. code . should open the current project folder, not a single detached file.
  2. The selected Python interpreter should match your course environment. Check the VS Code status bar or the command palette.
  3. Running practice.py should print five AI project task lines and an average task label length.
  4. If the Run button uses the wrong Python, run the file from the integrated terminal and then fix the selected interpreter.
  5. The shortcut practice passes when you can undo your edits and still run the script successfully.

Keep this page’s proof of learning as a small evidence card:

Environment
Python/Node/editor/notebook version and selected interpreter/kernel
Verification
one command or notebook cell proving the setup works
Project Folder
where dependencies, scripts, and notebooks live
Failure Check
wrong interpreter, missing package, stale kernel, or editor path mismatch
Expected Output
setup screenshot or terminal output plus one fallback note