Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sentry launches MCP monitoring tool

      August 14, 2025

      10 Benefits of Hiring a React.js Development Company (2025–2026 Edition)

      August 13, 2025

      From Line To Layout: How Past Experiences Shape Your Design Career

      August 13, 2025

      Hire React.js Developers in the US: How to Choose the Right Team for Your Needs

      August 13, 2025

      I’ve tested every Samsung Galaxy phone in 2025 – here’s the model I’d recommend on sale

      August 14, 2025

      Google Photos just put all its best editing tools a tap away – here’s the shortcut

      August 14, 2025

      Claude can teach you how to code now, and more – how to try it

      August 14, 2025

      One of the best work laptops I’ve tested has MacBook written all over it (but it’s even better)

      August 14, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Controlling Execution Flow with Laravel’s Sleep Helper

      August 14, 2025
      Recent

      Controlling Execution Flow with Laravel’s Sleep Helper

      August 14, 2025

      Generate Secure Temporary Share Links for Files in Laravel

      August 14, 2025

      This Week in Laravel: Filament 4, Laravel Boost, and Junie Review

      August 14, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      KDE Plasma 6 on Wayland: the Payoff for Years of Plumbing

      August 14, 2025
      Recent

      KDE Plasma 6 on Wayland: the Payoff for Years of Plumbing

      August 14, 2025

      FOSS Weekly #25.33: Debian 13 Released, Torvalds vs RISC-V, Arch’s New Tool, GNOME Perfection and More Linux Stuff

      August 14, 2025

      Ultimate ChatGPT-5 Prompt Guide: 52 Ideas for Any Task

      August 14, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Operating Systems»Linux»Handling Indentation in VS Code

    Handling Indentation in VS Code

    May 13, 2025

    Handling Indentation in VS Code

    Indentation is how code is visually spaced. It helps define structure, scope, and readability. For example, Python requires indentation to define blocks of code.

    Other languages might not require it, but messy indentation can make code really hard to read (and debug). Common indentation styles include:

    • 2 spaces (popular in JS, HTML, CSS)
    • 4 spaces (common in Python, Java)
    • Tabs (some devs swear by them)

    VS Code lets you customize indentation per file, per language, or globally.

    Let’s explore all the ways to tweak that!

    1. Change indentation via the status bar (per-file basis)

    This is the easiest method and perfect when you’re editing just one file.

    1. Open a file in VS Code.
    2. Look at the bottom-right corner of the window. You’ll see something like Spaces: 4 or Tab Size: 4.
    Handling Indentation in VS Code
    1. Click that label, a menu pops up!

    Now, you can choose:

    • Indent Using Tabs
    • Indent Using Spaces
    Handling Indentation in VS Code

    And below that, choose how many spaces (2, 4, 8 – up to you).

    Just changing the indentation setting doesn’t automatically re-indent the whole file. You’ll want to reformat the document too.

    Here’s how:

    • Press Ctrl + Shift + P (Linux/Windows) or Cmd + Shift + P (macOS).
    • Type Format Document and select it.
    Handling Indentation in VS Code
    • Or use the shortcut:
      • Ctrl + Shift + I on Linux
      • Shift + Alt + F on Windows
      • Shift + Option + F on macOS

    Boom! The file gets prettied up with your chosen indentation.

    2. Set global indentation in user settings

    Want to make your indentation choice apply to all new files in VS Code? Here’s how:

    1. Open Command Palette with Ctrl + Shift + P or F1.
    2. Type Preferences: Open User Settings.
    Handling Indentation in VS Code
    1. In the Settings UI, search for Tab Size and set it (e.g., 4).
    Handling Indentation in VS Code
    1. Then search Insert Spaces and make sure it’s checked.
    Handling Indentation in VS Code

    This tells VS Code:

    “Whenever I press Tab, insert 4 spaces instead.”

    Also check for Detect Indentation, if it’s ON, VS Code will override your settings based on the file content. Disable it if you want consistency across files.

    3. Set project-specific indentation (Workspace settings)

    Maybe you want different indentation just for one project, not globally.

    1. Open the project folder in VS Code.
    2. Go to the Command Palette and select Preferences: Open Workspace Settings.
    Handling Indentation in VS Code
    1. Switch to the Workspace tab.
    2. Search and set the same Tab Size, Insert Spaces, and Detect Indentation options.
    Handling Indentation in VS Code

    These get saved inside your project’s .vscode/settings.json file.

    Perfect if you want 2-space indentation in a JS project but 4 spaces in a Python project you’re working on separately.

    4. Set indentation based on programming language

    Now, here’s the power-user move. Let’s say you want:

    • 4 spaces for Python
    • 2 spaces for JavaScript and TypeScript

    Easy!

    1. Open the Command Palette → Preferences: Open User Settings (JSON)
    Handling Indentation in VS Code
    1. Add this snippet:
    "[python]": {
      "editor.tabSize": 4
    },
    "[javascript]": {
      "editor.tabSize": 2
    },
    "[typescript]": {
      "editor.tabSize": 2
    }
    

    This overrides the indentation per language.

    Handling Indentation in VS Code

    You can find all language identifiers in the VS Code docs if you want to customize more.

    You can also drop this into your .vscode/settings.json file if you want project-level overrides.

    Bonus Tip: Convert tabs to spaces (and vice versa)

    Already working on a file but the indentation is inconsistent?

    • Open the Command Palette → Type Convert Indentation
    • Choose either:
      • Convert Indentation to Spaces
      • Convert Indentation to Tabs
    Handling Indentation in VS Code

    You can also do this from the status bar at the bottom.

    If you need to convert all tabs in the file to spaces:

    1. Press Ctrl + F
    2. Expand the search box
    3. Enable Regex (.* icon)
    4. Search for t and replace it with two or four spaces

    Wrapping up

    Like word wrapping in VS Code, indentation may seem like a small thing, but it’s one of the cornerstones of clean, readable code.

    Whether you’re coding solo or collaborating on big projects, being consistent with indentation helps avoid annoying bugs (especially in Python!) and keeps the codebase friendly for everyone.

    VS Code makes it super easy to control indentation your way, whether you want to set it globally, per project, or even per language.

    We’ll be back soon with another helpful tip in our VS Code series.

    Source: Read More

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleCanonical Donating $120,000 to Open Source Projects This Year
    Next Article CVE-2025-3623 – WordPress Uncanny Automator PHP Object Injection Vulnerability

    Related Posts

    Learning Resources

    KDE Plasma 6 on Wayland: the Payoff for Years of Plumbing

    August 14, 2025
    Learning Resources

    FOSS Weekly #25.33: Debian 13 Released, Torvalds vs RISC-V, Arch’s New Tool, GNOME Perfection and More Linux Stuff

    August 14, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    CVE-2024-11953 – Apache Apache HTTP Server Cross-Site Request Forgery

    Common Vulnerabilities and Exposures (CVEs)

    Case Studies: Real-World Applications of Context Engineering

    Machine Learning

    serpl is a TUI to search and replace keywords

    Linux
    New TCESB Malware Found in Active Attacks Exploiting ESET Security Scanner

    New TCESB Malware Found in Active Attacks Exploiting ESET Security Scanner

    Development

    Highlights

    CVE-2025-54218 – Adobe InCopy Out-of-Bounds Write Arbitrary Code Execution

    August 12, 2025

    CVE ID : CVE-2025-54218

    Published : Aug. 12, 2025, 9:15 p.m. | 3 hours ago

    Description : InCopy versions 20.4, 19.5.4 and earlier are affected by an out-of-bounds write vulnerability that could result in arbitrary code execution in the context of the current user. Exploitation of this issue requires user interaction in that a victim must open a malicious file.

    Severity: 7.8 | HIGH

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    CVE-2025-47750 – SFT VS Out-of-Bounds Write Vulnerability

    May 19, 2025

    CVE-2025-4054 – Relevanssi WordPress Stored Cross-Site Scripting Vulnerability

    May 6, 2025

    DragonForce Ransomware Claimed To Compromise Over 120 Victims in The Past Year

    June 6, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.