Installing & Configuring VS Code
Turn your code editor into a productivity powerhouse. Master user vs. workspace settings.json, optimize indentation and auto-formatting, and memorize high-leverage keyboard shortcuts.
🎯 Learning Objectives
- Understand the hierarchy between User Settings and Workspace
.vscode/settings.json. - Configure essential web developer settings:
editor.tabSize,formatOnSave,wordWrap, andlinkedEditing. - Master the top 10 productivity keyboard shortcuts (Command Palette, multi-cursor, line shifting, file switcher).
- Automate document formatting and clean indentation workflows.
📖 Mental Model: The Custom Ergonomic Racecar Cockpit
When an F1 driver gets into a racing car, the pedals, steering wheel paddles, mirrors, and seat mold are tuned specifically to the millimeter for their body. They don't waste seconds searching for buttons or adjusting clumsy levers mid-race.
Configuring VS Code with your settings.json and muscle-memory shortcuts is building your ergonomic cockpit. Every second saved reaching for a mouse or manually aligning indentation adds up to hundreds of hours of flow state over a career.
The Core Configuration: settings.json
While VS Code has a visual Settings UI (`Ctrl+,` or `Cmd+,`), professional engineers maintain their configuration directly in JSON. VS Code uses two distinct layers of settings:
Essential Web Developer Settings
Here is the industry-standard baseline configuration for HTML and web development:
{
// Use standard 2-space indentation for HTML/CSS/JS
"editor.tabSize": 2,
"editor.insertSpaces": true,
// Automatically format code with Prettier when saving (Ctrl+S / Cmd+S)
"editor.formatOnSave": true,
// Wrap long lines horizontally without horizontal scrollbars
"editor.wordWrap": "on",
// Automatically rename closing HTML tag when opening tag is edited!
"editor.linkedEditing": true,
// Visually color-code matching brackets and tags
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active",
// Render whitespace dots to catch accidental rogue spaces
"editor.renderWhitespace": "boundary",
// Trim trailing spaces automatically on save
"files.trimTrailingWhitespace": true
}
Keyboard Shortcuts Cheatsheet
These 10 shortcuts will give you immediate speed advantages:
| Action | Windows / Linux | macOS | Why It Matters |
|---|---|---|---|
| Command Palette | Ctrl + Shift + P | Cmd + Shift + P | Access every command, setting, and extension action instantly without menus. |
| Quick File Open | Ctrl + P | Cmd + P | Jump directly to any file in your project by typing part of its name. |
| Duplicate Line Up/Down | Shift + Alt + ↓ / ↑ | Shift + Option + ↓ / ↑ | Clones the current line or selection instantly without copy-pasting. |
| Move Line Up/Down | Alt + ↓ / ↑ | Option + ↓ / ↑ | Shifts a tag or block up or down within your document structure. |
| Multi-Cursor Selection | Ctrl + D | Cmd + D | Selects the next occurrence of the highlighted word for simultaneous multi-point editing. |
| Toggle Integrated Terminal | Ctrl + ` | Ctrl + ` | Opens or hides the built-in command line without switching windows. |
| Toggle Primary Sidebar | Ctrl + B | Cmd + B | Gives maximum screen real estate to your active code editor. |
| Format Entire Document | Shift + Alt + F | Shift + Option + F | Instantly re-indents and formats HTML tags according to style rules. |
Live Code Example: Indentation & Clean Formatting
Clean nesting is crucial for readability. In the editor below, observe how proper 2-space hierarchy makes element parent-child relationships obvious at a glance:
🏋️ Hands-On Exercise: Clean Up a Messy Nested Structure
- The snippet below has inconsistent indentation, random tab widths, and chaotic tag alignments.
- Re-format the code cleanly using strict 2-space indentation for all child elements.
- Add a footer section inside the card with a button labeled
"Get Started Today". - Test the result by clicking ▶ Run Code.
⚠️ Common Pitfall: Tabs vs. Spaces Inconsistencies
If one developer uses 4-space hard tabs and another uses 2 spaces, Git diffs will flag every single line as changed even when no code logic was modified. Always set "editor.insertSpaces": true and "editor.tabSize": 2 in your project's .vscode/settings.json to maintain consistency.
💡 Pro Tip: Turn on "Linked Editing"
Enable "editor.linkedEditing": true in your settings. Whenever you change an opening HTML tag (e.g. changing <h2> to <h3>), VS Code automatically and instantaneously updates the matching </h2> closing tag simultaneously!
📌 Key Takeaways
- User settings apply globally across your entire OS, while workspace settings in
.vscode/settings.jsonoverride rules for a specific repository. - Set
"editor.tabSize": 2and"editor.insertSpaces": trueas the modern frontend standard. - Enable
"editor.formatOnSave": trueand"editor.linkedEditing": trueto eliminate manual tag renaming and re-indentation chores. - Use Ctrl/Cmd + Shift + P to access the Command Palette and Ctrl/Cmd + P for quick file navigation.
- Multi-cursor editing (Ctrl/Cmd + D) and line shifting (Alt/Option + Arrows) dramatically speed up markup manipulation.