The Developer's Primary Tool
Welcome to our exploration of code editors—specifically, Visual Studio Code (VS Code). As a developer, your code editor is perhaps the most important tool in your arsenal. You'll spend thousands of hours working within this environment, so understanding how to use it effectively is crucial to your productivity and enjoyment as a programmer.
Think of a code editor as a craftsperson's workshop. Just as a carpenter needs a well-organized space with quality tools arranged for maximum efficiency, a developer needs an editor that supports their workflow, enhances their capabilities, and reduces friction in the coding process.
In this session, we'll focus on Visual Studio Code (VS Code), which has become the most popular code editor among web developers due to its balance of performance, features, and extensibility. By the end of this session, you'll be comfortable with VS Code's interface, key features, and customization options—setting you up for success throughout this course and your development career.
What Is a Code Editor?
Before diving into VS Code specifically, let's clarify what a code editor is and how it differs from related tools.
Code Editors vs. Text Editors
A text editor is any program that can edit plain text files. Notepad (Windows), TextEdit (macOS), and gedit (Linux) are examples of basic text editors. While you can write code in these programs, they lack specialized features for programming.
A code editor, by contrast, is specifically designed for writing and editing code, with features like:
- Syntax highlighting
- Code completion
- Error checking
- Bracket matching
- Code folding
- Multiple cursors
The relationship between text editors and code editors is like the difference between a basic kitchen knife and a chef's knife set—both can cut food, but the specialized tools make the process more efficient and the results more precise.
Code Editors vs. IDEs
An Integrated Development Environment (IDE) takes things a step further by combining a code editor with additional tools like:
- Built-in compiler/interpreter
- Debugger
- Build automation tools
- Integrated terminal
- Testing frameworks
- Profiling tools
Traditional IDEs include Visual Studio (not to be confused with VS Code), PyCharm, Eclipse, and IntelliJ IDEA. They're typically more powerful but also heavier and more resource-intensive.
VS Code blurs the line between code editor and IDE. It starts as a lightweight code editor, but through extensions, it can incorporate many IDE-like features. This makes it extremely versatile—you can keep it lean for simple projects or expand its capabilities for complex ones.
If a code editor is like a chef's knife set, an IDE is like a fully equipped commercial kitchen—more powerful but requiring more space and setup time.
Popular Code Editors
While VS Code has become dominant, other popular code editors include:
- Sublime Text: Known for speed and minimalism
- Atom: GitHub's editor (now discontinued in favor of VS Code)
- Vim/Neovim: Terminal-based editors beloved for efficiency
- Emacs: Highly customizable with a dedicated user base
- Notepad++: Lightweight Windows-only editor
We're focusing on VS Code because of its dominant position in the industry, particularly for web development, and its excellent support for Python, JavaScript, HTML, CSS, and other languages we'll use in this course.
Why VS Code?
Visual Studio Code has risen to prominence for several compelling reasons:
Open Source and Free
VS Code is open-source and free to use, even in commercial settings. This has helped drive widespread adoption across different types of development teams and individual developers.
Cross-Platform
VS Code runs identically on Windows, macOS, and Linux. This consistency is particularly valuable in today's development landscape, where many tools and projects need to work across different operating systems.
Performance
Despite its rich feature set, VS Code maintains impressive performance. It launches quickly and handles large files and projects efficiently, striking a balance between capability and resource usage.
Extensibility
Perhaps VS Code's greatest strength is its extension system. The VS Code Marketplace offers thousands of extensions that can add language support, themes, debugging capabilities, and integrations with other tools and services.
This extensibility is like having a modular workshop where you can add exactly the tools you need for each project, without cluttering your space with unused equipment.
Intelligent Features
VS Code includes built-in IntelliSense, which provides smart completions based on variable types, function definitions, and imported modules. It also offers intelligent code navigation, refactoring tools, and integrated Git support.
Monthly Updates
Microsoft releases updates to VS Code monthly, continuously adding features, fixing bugs, and improving performance. This regular update cycle keeps the editor current with evolving development practices.
Strong Community and Documentation
VS Code has an active community contributing extensions, themes, and support. Microsoft also provides excellent documentation, tutorials, and video guides for getting started and mastering advanced features.
Industry Adoption
According to the 2021 Stack Overflow Developer Survey, VS Code is the most popular development environment, used by approximately 71% of professional developers. This widespread adoption means that skills you develop with VS Code will be relevant in most professional settings.
Installing VS Code
Let's begin by installing VS Code on your system:
System Requirements
VS Code has modest requirements:
- Windows: Windows 8.0, 10, 11 (32-bit and 64-bit)
- macOS: macOS 10.14 (Mojave) or higher
- Linux: Debian, Ubuntu, Red Hat, Fedora, SUSE, and other major distributions
- Memory: 1GB RAM minimum
- Disk Space: Approximately 200MB
Download and Installation
- Visit the VS Code website
- Click the download button for your operating system
- Run the installer and follow the prompts
Platform-Specific Notes
Windows
- During installation, consider these recommended options:
- Add "Open with Code" to Windows Explorer context menu
- Add VS Code to PATH (to open from command line)
- Register VS Code as an editor for supported file types
macOS
- Download the .zip file, extract it, and move Visual Studio Code.app to your Applications folder
- To enable launching from the terminal, run VS Code and press Cmd+Shift+P, type "shell command," and select "Install 'code' command in PATH"
Linux
- Download options include .deb (Debian/Ubuntu), .rpm (Red Hat/Fedora), or .tar.gz (other distributions)
- Repository installations ensure automatic updates (recommended)
- Example for Ubuntu:
sudo apt update sudo apt install code # or for the OSS version without Microsoft branding: sudo apt install code-oss - Snap installation (works on many distributions):
sudo snap install code --classic
Verifying Installation
After installation, launch VS Code:
- Windows: From Start menu or desktop shortcut
- macOS: From Applications folder or Spotlight (Cmd+Space, type "Visual Studio Code")
- Linux: From application launcher or terminal with
codecommand
From the terminal on any platform (if PATH integration is enabled):
# Open VS Code
code
# Open current directory in VS Code
code .
# Open a specific file
code filename.py
# Open a specific folder
code /path/to/folder
VS Code Interface Overview
Let's explore the main components of the VS Code interface:
Activity Bar
The vertical bar on the far left provides access to different views:
- Explorer: View and manage files and folders
- Search: Search across files
- Source Control: Git integration
- Run and Debug: Run and debug your code
- Extensions: Manage extensions
Think of the Activity Bar as the main navigation system for your workshop—it helps you switch between different work areas depending on what you're trying to accomplish.
Side Bar
The panel that opens from the Activity Bar, showing content relevant to the selected activity. For example, when the Explorer is selected, the Side Bar shows your project's file structure.
The Side Bar is like your workbench—the place where you organize materials and tools for your current task.
Editor Group
The main area where you edit files. VS Code supports multiple editor groups, allowing you to view and edit multiple files side by side.
The Editor Group is your primary work surface—where you actually shape and craft your code.
Panel
The bottom panel can show different tools:
- Terminal: Integrated command-line interface
- Output: Shows output from various tools
- Problems: Lists errors and warnings
- Debug Console: Shows debug output
The Panel is like your testing area—where you run tools, check for errors, and see the results of your work.
Status Bar
The bar at the bottom of the window shows contextual information:
- Current language mode
- Line and column position
- Encoding and line ending information
- Git branch and sync status
- Error and warning counts
The Status Bar is like your workshop's information display—providing at-a-glance status updates without interrupting your flow.
Command Palette
Access VS Code's command palette with Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac). This powerful tool provides access to virtually all VS Code's functionality through a searchable interface.
The Command Palette is like having an assistant who can fetch any tool or perform any action in your workshop just by asking for it—an invaluable time-saver.
Essential VS Code Features
Let's explore some of the key features that make VS Code powerful for daily development:
Syntax Highlighting
VS Code automatically colorizes code based on its syntax, making it easier to read and understand. The editor identifies language-specific keywords, strings, comments, and other elements and applies consistent coloring.
Syntax highlighting is like color-coding different types of components in your workshop—instantly making it clear what each piece does.
IntelliSense
IntelliSense provides intelligent code completion, parameter info, quick info, and member lists based on the language you're using and the context of your code.
# Example: When typing in Python, IntelliSense suggests methods
# After typing "string." VS Code shows available string methods
string.up # IntelliSense suggests upper(), uppercase(), etc.
IntelliSense is like having an expert whispering suggestions in your ear—helping you remember function names, parameters, and available options without breaking your flow.
Multiple Cursors and Selection
VS Code allows you to place multiple cursors in different locations, enabling simultaneous editing:
Alt+Click(Windows/Linux) orOption+Click(Mac): Add a cursor at click positionCtrl+Alt+Down/Up(Windows/Linux) orCmd+Option+Down/Up(Mac): Add a cursor above/belowCtrl+D(Windows/Linux) orCmd+D(Mac): Select the next occurrence of the current selection
Multiple cursors are like having several pairs of hands working simultaneously—dramatically speeding up repetitive edits.
Code Navigation
VS Code offers powerful navigation features:
Ctrl+G(Windows/Linux) orCmd+G(Mac): Go to line numberF12: Go to definition of symbol under cursorAlt+F12(Windows/Linux) orOption+F12(Mac): Peek definitionShift+F12: Show all referencesCtrl+T(Windows/Linux) orCmd+T(Mac): Show all symbols in current fileCtrl+Shift+O(Windows/Linux) orCmd+Shift+O(Mac): Navigate to a specific symbol in the current file
These navigation features are like having a detailed map and teleportation device for your codebase—allowing you to instantly jump to exactly what you're looking for.
Integrated Terminal
VS Code includes a fully-featured terminal that you can open with:
Ctrl+`(the backtick key, typically below Esc)- From the menu: View > Terminal
The integrated terminal allows you to:
- Run commands without leaving VS Code
- Open multiple terminal instances (even with different shells)
- Split terminal views
- Run tasks defined in your project
The integrated terminal is like having a command center built right into your workshop—no need to step outside to issue commands or check results.
File and Folder Management
The Explorer view (accessible via the first icon in the Activity Bar) allows you to:
- Create, delete, rename, and move files and folders
- Collapse and expand folder structures
- Filter files by type or name
- Work with multiple root folders in a single workspace
Right-clicking in the Explorer provides a context menu with additional options.
The Explorer is like having a well-organized filing system for your project materials—allowing you to quickly locate and manage everything related to your work.
Search and Replace
VS Code offers powerful search capabilities:
Ctrl+F(Windows/Linux) orCmd+F(Mac): Search in current fileCtrl+H(Windows/Linux) orCmd+H(Mac): Replace in current fileCtrl+Shift+F(Windows/Linux) orCmd+Shift+F(Mac): Search across all filesCtrl+Shift+H(Windows/Linux) orCmd+Shift+H(Mac): Replace across all files
The search functionality supports:
- Regular expressions
- Case matching options
- Whole word matching
- Including/excluding specific files or folders
Search and replace capabilities are like having a super-powered detector that can find any piece of code in your project, no matter where it's hiding.
Split Editing
You can split the editor to view and edit multiple files simultaneously:
Ctrl+\\(Windows/Linux) orCmd+\\(Mac): Split the current editor- Drag and drop a tab to create a new editor group
- Right-click a tab and select "Split Right" or "Split Down"
Split editing is like having multiple workbenches side by side—perfect for comparing code, referencing documentation while coding, or working on related files simultaneously.
Extending VS Code with Extensions
One of VS Code's greatest strengths is its extensibility. Let's explore how to find, install, and use extensions to enhance your development experience.
What Are Extensions?
Extensions are add-ons that enhance VS Code with additional features, language support, themes, and integrations. They're like specialized tools you can add to your workshop as needed.
Accessing the Extensions View
Access the Extensions view through:
- Click the Extensions icon in the Activity Bar (looks like a square block)
- Use keyboard shortcut:
Ctrl+Shift+X(Windows/Linux) orCmd+Shift+X(Mac) - From the Command Palette: Type "Extensions: Install Extensions"
Finding and Installing Extensions
In the Extensions view:
- Search for extensions by name, category, or functionality
- Browse featured, popular, or recommended extensions
- Click the "Install" button on an extension to add it
- Some extensions may require reloading VS Code after installation
Managing Extensions
The Extensions view allows you to:
- View installed extensions
- Enable/disable extensions
- Uninstall extensions
- Update extensions
- Configure extension settings
Essential Extensions for Python Web Development
Here are some recommended extensions for our course:
Python Development
-
Python (Microsoft): Official Python extension with support for debugging, linting, IntelliSense, etc.
- Features: IntelliSense, linting, debugging, code navigation, code formatting
- Publisher: Microsoft
-
Pylance: Fast, feature-rich language server for Python
- Features: Type information, auto-imports, signature help
- Publisher: Microsoft
-
Python Docstring Generator: Generate Python docstrings automatically
- Features: Support for various docstring formats (Google, NumPy, etc.)
- Publisher: Nils Werner
Web Development
-
HTML CSS Support: Enhanced support for HTML and CSS
- Features: Class and ID completion, HTML syntax highlighting
- Publisher: ecmel
-
JavaScript (ES6) code snippets: Snippets for JavaScript in ES6 syntax
- Features: Common JavaScript snippets
- Publisher: charalampos karypidis
-
ESLint: Integrates ESLint JavaScript linting
- Features: Code quality and style checking
- Publisher: Microsoft
General Productivity
-
GitLens: Enhanced Git capabilities
- Features: Blame annotations, commit search, history visualization
- Publisher: GitKraken
-
Prettier - Code formatter: Consistent code formatting
- Features: Format on save, custom formatting rules
- Publisher: Prettier
-
Remote - SSH: Work with remote files over SSH
- Features: Connect to remote servers, edit remote files
- Publisher: Microsoft
-
Live Server: Launch a local development server
- Features: Live reload, local hosting
- Publisher: Ritwick Dey
Themes and Visual Enhancements
-
Material Theme: Material design-inspired themes
- Features: Multiple color variants, icon packs
- Publisher: Equinusocio
-
One Dark Pro: Atom's iconic One Dark theme
- Features: Dark theme with vibrant colors
- Publisher: binaryify
-
vscode-icons: File and folder icons
- Features: Distinctive icons for different file types
- Publisher: VSCode Icons Team
Extension Settings
Most extensions provide settings that you can customize:
- Go to File > Preferences > Settings (or
Ctrl+,) - Search for the extension name
- Adjust available settings to your preference
Some extensions add their own commands to the Command Palette or their own views to the Activity Bar.
Customizing VS Code
VS Code is highly customizable, allowing you to tailor the editor to your preferences and workflow.
Settings
Access settings through:
- File > Preferences > Settings
- Keyboard shortcut:
Ctrl+,(Windows/Linux) orCmd+,(Mac) - Command Palette: "Preferences: Open Settings"
VS Code offers two ways to modify settings:
- UI Editor: User-friendly interface with search and categorization
- JSON Editor: Directly edit the settings.json file
Settings can be applied at two levels:
- User Settings: Apply to all projects
- Workspace Settings: Apply only to the current project
Common settings to consider customizing:
// Basic editor appearance
"editor.fontSize": 14,
"editor.fontFamily": "Consolas, 'Courier New', monospace",
"editor.lineHeight": 24,
"editor.minimap.enabled": false,
// Behavior
"editor.formatOnSave": true,
"editor.tabSize": 4,
"editor.insertSpaces": true,
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 1000,
// Terminal
"terminal.integrated.fontSize": 14,
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
// Language-specific settings
"[python]": {
"editor.tabSize": 4,
"editor.formatOnSave": true
},
"[javascript]": {
"editor.tabSize": 2,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
Themes
VS Code allows you to customize both the color theme (syntax highlighting and UI colors) and file icon theme:
-
Color Theme:
- File > Preferences > Color Theme
- Keyboard shortcut:
Ctrl+K Ctrl+T - Command Palette: "Preferences: Color Theme"
-
File Icon Theme:
- File > Preferences > File Icon Theme
- Command Palette: "Preferences: File Icon Theme"
VS Code comes with several built-in themes (Light, Dark, High Contrast), and you can install more from the Extensions view.
Keyboard Shortcuts
Customize keyboard shortcuts through:
- File > Preferences > Keyboard Shortcuts
- Keyboard shortcut:
Ctrl+K Ctrl+S(Windows/Linux) orCmd+K Cmd+S(Mac) - Command Palette: "Preferences: Open Keyboard Shortcuts"
The keyboard shortcuts editor allows you to:
- Search for commands
- View existing shortcuts
- Add, remove, or change shortcuts
- Reset to defaults
You can also define keybindings in a keybindings.json file for more advanced configurations.
User Snippets
Create your own code snippets for frequently used code patterns:
- File > Preferences > User Snippets
- Select a language or create a new global snippet file
- Define snippets using the JSON format
Here's an example Python snippet:
{
"Print debug": {
"prefix": "pdb",
"body": [
"print(f\"DEBUG: ${1:variable} = {${1:variable}}\")"
],
"description": "Print a debug statement with variable name and value"
},
"Flask route": {
"prefix": "froute",
"body": [
"@app.route('/${1:path}', methods=['${2:GET}'])",
"def ${3:function_name}():",
" ${4:pass}"
],
"description": "Create a new Flask route"
}
}
After creating a snippet, you can trigger it by typing the prefix and pressing Tab or Enter.
Workspace Customization
VS Code workspaces allow you to save and restore complex project setups:
- Group multiple root folders into a single workspace
- Save workspace-specific settings
- Remember editor layout and open files
To create a workspace:
- File > Add Folder to Workspace (add one or more folders)
- File > Save Workspace As (save the configuration with a .code-workspace extension)
Workspace files are JSON and can be edited directly to customize advanced settings.
Practical Workflows
Let's explore some practical workflows that will make you more productive in VS Code.
Effective Code Navigation
Moving around your codebase efficiently is crucial for productivity. Try these techniques:
-
Search Symbols:
Ctrl+T(Windows/Linux) orCmd+T(Mac) to jump to symbols in your workspaceCtrl+Shift+O(Windows/Linux) orCmd+Shift+O(Mac) for symbols in current file
-
Recent Files:
Ctrl+P(Windows/Linux) orCmd+P(Mac) to quickly open filesCtrl+Tabto cycle through open files
-
Code Definition:
F12to go to definitionAlt+F12(Windows/Linux) orOption+F12(Mac) to peek definitionShift+F12to find all references
- Breadcrumbs: Use the breadcrumbs bar at the top of the editor to navigate file structure
Editing Techniques
These editing techniques can significantly speed up your coding:
-
Multiple Cursors:
Alt+Click(Windows/Linux) orOption+Click(Mac) to add cursorsCtrl+D(Windows/Linux) orCmd+D(Mac) to select next occurrenceCtrl+Shift+L(Windows/Linux) orCmd+Shift+L(Mac) to select all occurrences
-
Line Operations:
Alt+Up/Down(Windows/Linux) orOption+Up/Down(Mac) to move linesShift+Alt+Up/Down(Windows/Linux) orShift+Option+Up/Down(Mac) to copy linesCtrl+Shift+K(Windows/Linux) orCmd+Shift+K(Mac) to delete lines
-
Code Folding:
Ctrl+Shift+[(Windows/Linux) orCmd+Option+[(Mac) to fold regionsCtrl+Shift+](Windows/Linux) orCmd+Option+](Mac) to unfold
-
Smart Selection:
Shift+Alt+Right(Windows/Linux) orShift+Option+Right(Mac) to expand selectionShift+Alt+Left(Windows/Linux) orShift+Option+Left(Mac) to shrink selection
Git Integration
VS Code's built-in Git integration provides a smooth workflow:
-
Source Control View: Click the Source Control icon in the Activity Bar
- See changed files
- Stage changes
- Write commit messages
- Push/pull from remotes
-
Inline Changes: See changes highlighted in the editor
- Green gutter marks for additions
- Blue for modifications
- Red for deletions
- Branch Management: Switch branches from the status bar
- Merge Conflict Resolution: Visual tools for resolving conflicts
The GitLens extension adds even more powerful Git features.
Debugging Workflow
VS Code's debugging capabilities are powerful for finding and fixing issues:
-
Set Breakpoints:
- Click in the gutter next to line numbers
- Set conditional breakpoints by right-clicking the gutter
-
Configure Debug Settings:
- Create or modify launch.json for your project
- Select run configuration from the debug dropdown
-
Start Debugging:
- Press F5 or click the green play button
-
Use Debug Controls:
- Continue (F5), Step Over (F10), Step Into (F11), Step Out (Shift+F11)
- Examine variables in the Variables pane
- Use the Debug Console to evaluate expressions
- View the call stack
For Python, ensure you have the Python extension installed and configured with the correct interpreter.
Integrated Terminal Workflow
The integrated terminal is perfect for running commands without leaving VS Code:
-
Open/Close Terminal:
Ctrl+`(backtick) - Multiple Terminals: Click the + icon to create additional terminals
- Split Terminal: Use the split icon to view terminals side by side
- Switch Shells: Select different shell types from the dropdown
-
Common Use Cases:
- Running tests
- Starting development servers
- Installing packages
- Building projects
Tip: You can run tasks defined in tasks.json using the Command Palette ("Tasks: Run Task").
Setting Up VS Code for Python Development
Let's configure VS Code specifically for Python development, which will be our primary focus in this course.
Installing the Python Extension
- Open VS Code
- Go to the Extensions view (
Ctrl+Shift+X) - Search for "Python"
- Install the "Python" extension by Microsoft
- Also install "Pylance" for enhanced language features
Selecting a Python Interpreter
VS Code needs to know which Python installation to use:
- Open the Command Palette (
Ctrl+Shift+P) - Type and select "Python: Select Interpreter"
- Choose from the available Python installations
The selected interpreter appears in the status bar and is used for IntelliSense, linting, and debugging.
Working with Virtual Environments
Virtual environments are essential for Python development:
# Creating a virtual environment (in terminal)
python -m venv .venv
# Activating the environment
# On Windows:
.venv\Scripts\activate
# On macOS/Linux:
source .venv/bin/activate
# VS Code will detect the virtual environment and ask if you want to use it
VS Code integrates well with virtual environments:
- Automatically detects virtual environments in your workspace
- Suggests using them when detected
- Shows the active environment in the status bar
- Respects the activated environment in the terminal
Running Python Code
There are several ways to run Python code in VS Code:
-
Run Python File:
- Click the play button in the top-right corner of the editor
- Right-click in editor and select "Run Python File in Terminal"
- Use the keyboard shortcut
Ctrl+F5
-
Run Selection/Line:
- Select code and press
Shift+Enter - Right-click and select "Run Selection/Line in Python Terminal"
- Select code and press
-
Jupyter Notebooks:
- VS Code supports .ipynb files with cell execution, markdown, and interactive outputs
Python Linting and Formatting
Configure linting and formatting for consistent code quality:
-
Linters: VS Code supports various Python linters
- Open Settings and search for "Python Linting"
- Enable pylint, flake8, or mypy
- Customize severity levels and rules
-
Formatters: Configure automatic code formatting
- Open Settings and search for "Python Formatting"
- Select a formatter (autopep8, black, yapf)
- Enable "Format on Save" for automatic formatting
Example settings.json for Python development:
{
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.flake8Enabled": false,
"python.formatting.provider": "black",
"python.formatting.blackArgs": ["--line-length", "88"],
"editor.formatOnSave": true,
"python.analysis.typeCheckingMode": "basic",
"[python]": {
"editor.defaultFormatter": "ms-python.python",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
}
}
Python Debugging
VS Code offers robust Python debugging:
- Set breakpoints by clicking in the gutter
- Press F5 to start debugging the current file
- Use the Debug toolbar to control execution:
- Continue (F5)
- Step Over (F10)
- Step Into (F11)
- Step Out (Shift+F11)
- Restart (Ctrl+Shift+F5)
- Stop (Shift+F5)
- Inspect variables in the Variables pane
- Use the Debug Console to execute code in the current context
For more complex projects, configure launch.json with custom debug configurations.
Setting Up VS Code for Web Development
Since we're focusing on full stack development, let's also configure VS Code for HTML, CSS, and JavaScript.
Essential Web Development Extensions
- HTML CSS Support: Provides CSS class name completion for HTML
- Live Server: Launch a development server with live reload
- Prettier: Code formatter for HTML, CSS, JavaScript
- ESLint: JavaScript code quality and style checker
- Auto Rename Tag: Automatically rename paired HTML tags
- Path Intellisense: Autocompletes filenames in import statements
HTML Development Features
VS Code has built-in support for HTML:
-
Emmet Integration: Write HTML quickly with abbreviations
- IntelliSense: Autocomplete for tags, attributes, and values
-
Format Document:
Shift+Alt+Fto format HTML - Live Preview: Use Live Server extension to see changes in real-time
CSS Development Features
CSS editing is enhanced with:
- IntelliSense: Autocomplete for properties and values
- Color Picker: Visual editor for color values
- CSS Validation: Built-in linting for CSS
-
Emmet for CSS: Abbreviations for CSS properties
/* Type "bg#f5f5f5" and press Tab for "background: #f5f5f5;" */ /* Type "d:f" and press Tab for "display: flex;" */
JavaScript Development Features
JavaScript support includes:
- IntelliSense: Rich autocompletion and type checking
- ESLint Integration: Real-time linting with customizable rules
- Debugging: Debug JavaScript directly in VS Code
- Refactoring Tools: Extract method, rename symbol, etc.
Web Development Workflow
A typical web development workflow in VS Code:
- Create HTML, CSS, and JavaScript files
- Use Emmet to quickly write HTML structure
- Start Live Server to preview in browser
- Make changes and see real-time updates
- Use built-in tools to debug JavaScript
- Format documents with Prettier
Example settings.json for web development:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"prettier.printWidth": 100,
"prettier.tabWidth": 2,
"prettier.singleQuote": true,
"emmet.includeLanguages": {
"javascript": "javascriptreact"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
VS Code Tips and Tricks
Here are some lesser-known features and productivity boosters for VS Code:
Command Palette Power
The Command Palette (Ctrl+Shift+P) is more powerful than most realize:
- Prefix commands with
>to filter to actions - Use
@to navigate symbols in the current file - Use
#to search across the workspace - Use
:followed by a number to go to a line - Type
?to see all available command types
Zen Mode and Focus
Remove distractions with VS Code's focus features:
Ctrl+K Z(Windows/Linux) orCmd+K Z(Mac): Enter Zen Mode- Toggle the Activity Bar and Sidebar to maximize editor space
- Use breadcrumbs instead of the explorer for navigation
- Try the Screencast Mode for presentations (shows keypresses)
Integrated Task Running
Automate repetitive tasks:
- Create a tasks.json file in the .vscode folder
- Define custom tasks for building, testing, deploying, etc.
- Run tasks from the Command Palette with "Tasks: Run Task"
- Bind tasks to keyboard shortcuts
// Example tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Current Python File",
"type": "shell",
"command": "python",
"args": ["${file}"],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Start Flask Server",
"type": "shell",
"command": "flask",
"args": ["run"],
"options": {
"env": {
"FLASK_APP": "app.py",
"FLASK_ENV": "development"
}
}
}
]
}
Multicursor and Selection Techniques
Beyond the basics, try these multicursor techniques:
Alt+Clickto add cursorsCtrl+Alt+Down/Upto add cursors above/belowCtrl+Dto select next occurrence of current selectionCtrl+Shift+Lto select all occurrencesCtrl+F2to select all occurrences of current wordShift+Alt+Dragfor column selectionShift+Alt+Rightto expand selection
Terminal Tricks
Make the most of the integrated terminal:
- Split terminals with the split icon
- Drag terminals to rearrange them
- Use
Ctrl+`to toggle the terminal - Use
Ctrl+Shift+`to create a new terminal - Configure terminal shell per project in settings.json
- Copy terminal selection with
Ctrl+Shift+C
Workspace Organization
For complex projects:
- Use multi-root workspaces to group related projects
- Create workspace-specific settings
- Use the File > Save Workspace As command to save configurations
- Pin frequently accessed files with the "Pin Editor" command
- Use editor groups to view files side by side
Performance Optimization
Keep VS Code running smoothly:
- Disable unused extensions
- Exclude large folders from search (in settings.json)
- Set up regular automatic saves to prevent data loss
- Use workspace trust for secure code execution
// Performance-related settings
{
"files.exclude": {
"**/.git": true,
"**/node_modules": true,
"**/__pycache__": true
},
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/*.code-search": true,
"**/venv": true,
"**/.venv": true
},
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/node_modules/**": true,
"**/.venv/**": true
}
}
Troubleshooting Common Issues
Even the best tools sometimes have issues. Here's how to handle common VS Code problems:
Extension Problems
-
Extension not working:
- Check if it's enabled
- Try reloading VS Code (
Ctrl+Ror Command Palette: "Developer: Reload Window") - Check extension settings
- Uninstall and reinstall the extension
-
Conflicts between extensions:
- Disable extensions one by one to identify the conflict
- Check for duplicative extensions (e.g., multiple formatters)
- Set explicit default formatters per language
Performance Issues
-
VS Code running slowly:
- Check CPU and memory usage in Task Manager/Activity Monitor
- Disable extensions you're not actively using
- Exclude large folders from the workspace
- Check startup performance with
--statuscommand-line flag - Reset user data if necessary (backup settings first!)
-
High CPU usage:
- Identify the culprit using the Process Explorer (Help > Process Explorer)
- Check for problematic extensions or language servers
- Reduce the scope of language services with
files.exclude
Language Service Issues
-
IntelliSense not working:
- Check language extension is installed and enabled
- Verify correct interpreter/environment selection
- Reload window or restart language server
- Check language server status in Output panel
-
Linting/formatting issues:
- Confirm linter/formatter is installed (both VS Code extension and system tool)
- Check configuration in settings.json
- Verify path to executable is correct
- Try running the tool from command line to check for errors
Git Integration Problems
-
Git features not working:
- Verify Git is installed and accessible in PATH
- Check Git configuration (user.name, user.email)
- Ensure you're in a Git repository
- Try restarting VS Code or reinstalling Git extension
Debugging Issues
-
Debugger not working:
- Verify debug configuration in launch.json
- Check if the right interpreter/runtime is selected
- Ensure debugger extension is installed for your language
- Try running with verbose logging (set "trace": "verbose" in launch.json)
-
Breakpoints not hitting:
- Check if breakpoints are bound (solid red vs hollow red)
- Verify code path is actually being executed
- Try setting a logpoint instead to confirm execution
Getting Help
When you encounter issues that you can't resolve:
-
Documentation:
- Check the VS Code documentation
- Look at extension-specific documentation
-
Community Support:
- Search or ask on Stack Overflow
- Visit the VS Code GitHub repository
- Join the VS Code community
-
Reporting Bugs:
- Use the "Help > Report Issue" menu item
- Include detailed reproduction steps
- Attach logs (Help > Toggle Developer Tools > Console)
The Future of VS Code
VS Code continues to evolve with monthly updates. Here are some trends and upcoming features to watch:
AI-Assisted Development
VS Code is increasingly incorporating AI to help developers:
- GitHub Copilot integration for AI code suggestions
- IntelliCode for AI-enhanced IntelliSense
- Smart code refactoring powered by machine learning
- Automated bug detection and fixes
These AI assistants are like having an experienced pair programmer constantly at your side, suggesting improvements and spotting potential issues.
Remote Development
VS Code is expanding its remote development capabilities:
- Remote - SSH for working on remote servers
- Remote - Containers for containerized development environments
- GitHub Codespaces for cloud-based development
- Remote - WSL for Windows Subsystem for Linux integration
These tools enable you to work in consistent, powerful environments regardless of your local machine's capabilities.
Collaborative Editing
Real-time collaboration features are increasingly important:
- Live Share for real-time collaborative editing and debugging
- Enhanced commenting and review capabilities
- Integration with communication platforms
These features transform VS Code from a solo workspace into a collaborative environment, like turning an individual workshop into a shared studio.
Web-Based Editing
VS Code is becoming available in more contexts:
- VS Code for the Web (vscode.dev) for browser-based editing
- GitHub.dev for editing directly from GitHub
- Progressive Web App (PWA) support
These web-based options allow you to code from any device with a browser, further breaking down the barriers to development.
Practical Exercise: VS Code Setup and Exploration
Let's put what we've learned into practice with a hands-on exercise:
Exercise Setup
- Ensure VS Code is installed on your system
- Create a new folder called "vscode-practice" on your desktop
- Open VS Code and use File > Open Folder to open this folder
Task 1: Basic Editor Skills
- Create a new file called "index.html" (File > New File)
- Type "!" and press Tab to generate an HTML boilerplate
- Inside the body tag, add a heading and paragraph of your choice
- Practice using multiple cursors: add a class to both your heading and paragraph
- Use keyboard shortcuts to duplicate lines, move lines, and delete lines
- Save the file (Ctrl+S)
Task 2: Extension Installation
- Open the Extensions view (Ctrl+Shift+X)
- Search for and install "Live Server"
- Right-click on index.html in the Explorer view and select "Open with Live Server"
- Observe how changes to the file are automatically reflected in the browser
Task 3: Python Setup
- Install the Python extension if not already installed
- Create a new file called "app.py"
- Add the following Python code:
def greet(name): """ Returns a greeting message for the provided name. """ return f"Hello, {name}! Welcome to VS Code." def main(): user_name = input("Please enter your name: ") message = greet(user_name) print(message) # TODO: Add more functionality here if __name__ == "__main__": main() - Practice using VS Code features:
- Hover over function names to see their docstrings
- Use F12 to navigate to function definitions
- Use the "Problems" tab to see any issues
- Run the Python file using the play button in the top-right
Task 4: Terminal and Git
- Open the integrated terminal (Ctrl+`)
- Initialize a Git repository in your folder:
git init - Notice how the Source Control icon in the Activity Bar now shows changes
- Click the Source Control icon to see your changes
- Stage your files by clicking the + icon next to each file
- Add a commit message and commit your changes
Task 5: Customization
- Open settings (Ctrl+,)
- Try changing a few settings:
- Change the color theme (Color Theme in the search box)
- Adjust the font size (Font Size in the search box)
- Enable word wrap (Word Wrap in the search box)
- Create a custom snippet:
- File > Preferences > User Snippets
- Select "python.json"
- Add a snippet for a docstring:
"Docstring": { "prefix": "docs", "body": [ "\"\"\"", "${1:Description of the function}", "", "Args:", " ${2:param_name} (${3:type}): ${4:Description of the parameter}", "", "Returns:", " ${5:type}: ${6:Description of the return value}", "\"\"\"", "$0" ], "description": "Function docstring" } - Try using your snippet in app.py by adding a new function and typing "docs" followed by Tab
Bonus Tasks
- Create a "launch.json" file for debugging your Python application
- Set up a custom task in "tasks.json" to run your Python file
- Try using the Command Palette (Ctrl+Shift+P) to discover new commands
- Experiment with the Zen Mode (Ctrl+K Z) for distraction-free coding
- Try the multi-file editing with split editors (Ctrl+\)
Conclusion: VS Code as Your Development Partner
Throughout this session, we've explored Visual Studio Code—a powerful, flexible tool that will serve as your primary development environment throughout this course and likely well into your professional career.
Remember that mastering your tools is an investment that pays dividends every day. The time you spend learning VS Code's features and customizing it to your preferences will be repaid through increased productivity and a more enjoyable development experience.
As you continue your journey as a developer, your relationship with VS Code will evolve:
- Initially, you'll learn the basic features needed to write and edit code
- As you grow, you'll discover more advanced capabilities that enhance your workflow
- Eventually, you'll tailor VS Code to be a personalized environment that feels like an extension of your thinking process
Remember that VS Code is continuously improving, with new features and extensions released regularly. Stay curious and open to learning new tricks—there's always another productivity enhancement waiting to be discovered.
In our next sessions, we'll build upon this foundation as we explore Python programming fundamentals and web development concepts. Your familiarity with VS Code will allow you to focus on learning these technologies rather than struggling with your tools.
Assignment: VS Code Proficiency
To reinforce your VS Code skills, complete the following tasks:
-
VS Code Setup and Customization:
- Install VS Code if you haven't already
- Install the recommended extensions for Python and web development
- Configure at least five settings to match your preferences
- Create at least two custom snippets that you think will be useful
- Choose a color theme and icon theme that you find appealing
- Take a screenshot of your customized VS Code
-
Keyboard Shortcut Mastery:
- Create a markdown document called "vscode_shortcuts.md"
- List at least 15 keyboard shortcuts that you find most useful
- For each shortcut, include:
- The key combination
- What the shortcut does
- A brief example of when you would use it
- Practice using these shortcuts for at least one day
-
Python Environment Setup:
- Create a Python project with a proper folder structure
- Set up a virtual environment within VS Code
- Configure linting and formatting for Python
- Create a simple Python program with multiple files
- Practice debugging by setting breakpoints and stepping through code
- Document your setup process and any challenges you encountered
-
Web Development Workflow:
- Create a simple web project with HTML, CSS, and JavaScript files
- Use Emmet abbreviations to quickly generate HTML structure
- Set up Live Server to preview your web pages
- Use the CSS preview and color picker features
- Practice using multiple cursors for bulk editing
- Create a short screencasting showing your workflow
-
VS Code Features Exploration:
- Create a document called "vscode_features.md"
- Explore the Command Palette and discover five commands you didn't know about
- Experiment with at least three extensions not mentioned in this lesson
- Try using workspace features with multiple folders
- For each feature or extension, write a brief description and how it might be useful
Submit your completed assignment, including all documents, screenshots, and any code you created, before the next class session. The goal is not just to complete the tasks, but to begin developing an efficient, personalized workflow in VS Code.
Additional Resources
- VS Code Documentation - Official documentation
- VS Code Tips and Tricks - Official tips from the VS Code team
- Python in VS Code - Python-specific documentation
- VS Code Marketplace - Browse extensions
- VS Code Recipes - Specific setup configurations for different scenarios
- VS Code Can Do That?! - Collection of VS Code tips
- Remote Containers and WSL - Advanced development environments
- VS Code for the Web - Try the browser version of VS Code
Books and Courses:
- "Visual Studio Code Distilled" by Alessandro Del Sole
- "VS Code: End-to-End Editing and Debugging Tools for Web Developers" by Bruce Johnson
- LinkedIn Learning and Pluralsight have several VS Code courses
YouTube Channels:
- VS Code - Official VS Code channel
- Microsoft Developer - Often features VS Code content
- Burke Holland - VS Code tips and tricks