Everyday Toolkit

How to Arrange Code in Visual Studio Code

Published 2026-07-25

Updated Jul 2026

Some links on this page are affiliate links. If you buy through them we may earn a small commission at no extra cost to you. We only recommend what we'd use.

Key takeaways
  • Automated formatters like Prettier enforce consistent team style guidelines
  • Built-in split views and custom panel layouts reduce context switching
  • Code folding and outline views make navigating complex source files effortless
  • Native bracket coloring and select extensions keep code bases organized.
How to Arrange Code in Visual Studio Code
Photo: Authors of the study: Shmuel Bialy, Catherine Zucker, Alyssa Goodman, Michael M. Foley, João Alves, Vadim A. Semenov, Robert Benjamin, Reimar Leike, Torsten Enßlin (BY) via Openverse

How to Arrange Code in Visual Studio Code

Arranging code in Visual Studio Code requires combining native layout controls like split editors and panel positioning with automated tools like Prettier, custom code folding, and smart workspace extensions. Taking time to structure your layout and automate formatting removes visual noise, simplifies navigation, and helps you move through projects much faster.

A disorganized editor forces you to spend extra time searching for functions, fixing indentation bugs, or scrolling endlessly through monster files. By configuring your editor settings once, you establish an environment where code naturally formats itself, multi-file editing is easy, and critical information stays front and center.

Basic Formatting with Prettier and EditorConfig

Consistent automated formatting provides the foundation for organized code in Visual Studio Code. Combining Prettier for language-agnostic code formatting with EditorConfig for cross-editor style rules ensures your codebase stays uniformly structured without manual effort, preventing unnecessary style debates during team pull requests.

Setting up formatting tools early prevents bad habits from creeping into your repository. Rather than spending time aligning array elements or adjusting bracket placements manually, you let background tools do the heavy lifting. This guarantees every file in your project follows identical spacing and syntax rules.

Prettier: Automated Formatting

Prettier automates visual code arrangement by enforcing rigid style rules for indentation, line lengths, and quotes every time you save a file. Installing the official Prettier extension eliminates manual spacing fixes, letting you write raw code quickly while trusting the editor to organize it cleanly.

To get started, search for "Prettier - Code formatter" in the extensions view and install it. Open your settings (`Ctrl+,` or `Cmd+,`), search for "Default Formatter," and choose Prettier. Check the box for "Format On Save" so VS Code formats your file automatically whenever you hit save.

For project-specific rules, place a `.prettierrc` JSON or YAML file in your repository root. You can specify options like `"singleQuote": true`, `"tabWidth": 2`, or `"printWidth": 80`. Sharing this file in source control keeps everyone on the team aligned without forcing them to change their global settings.

EditorConfig: Cross-Editor Consistency

EditorConfig maintains consistent formatting rules across different development environments and editors by using a shared root configuration file. The `editorconfig-vscode` extension reads these project rules directly, overriding local workspace settings to guarantee that indent styles, line endings, and character sets remain consistent across your development team.

Create a `.editorconfig` file in the root of your project directory. This plain-text configuration defines basic file handling rules that apply across different text editors and IDEs:

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

Once you install the EditorConfig extension, VS Code respects these settings automatically whenever you open or edit project files. It works quietly in the background to ensure Windows and Mac developers don't accidentally commit conflicting line endings or tab widths.

Code Folding: Managing Complexity

How to Arrange Code in Visual Studio Code
Photo: Epicgenius (BY-SA) via Openverse

Code folding hides complex or repetitive code blocks behind expandable summaries, helping you keep large files readable and manageable. Visual Studio Code includes powerful native folding mechanisms driven by language indentation, explicit region markers, and structural syntax rules to help you focus on active development areas.

Large files often contain top-level imports, long configuration objects, or auxiliary functions that distract from core logic. Folding these secondary sections gives you an instant high-level view of your source file structure without requiring you to break everything into smaller modules immediately.

Manual Code Folding

Manual code folding lets you selectively hide functions, object literals, or imported module lists by clicking the chevron icons in the editor gutter. You can also trigger folding commands using quick keyboard shortcuts to quickly collapse boilerplate sections and keep your primary working logic visible.

Move your cursor over the gutter space between line numbers and the code margin to see folding arrows. Click any arrow to collapse that specific code block. Alternatively, place your cursor inside a block and press `Ctrl+Shift+[` (or `Cmd+Option+[` on Mac) to fold it, and `Ctrl+Shift+]` (`Cmd+Option+]`) to unfold it.

You can also create explicit custom regions in many programming languages. In JavaScript or TypeScript, wrap code blocks with `//#region` and `//#endregion` comments. VS Code recognizes these blocks and lets you fold entire custom sections under descriptive titles.

Automatic Code Folding

Automatic code folding evaluates code structure on file load to collapse specific blocks, such as long top-level import lists or multi-line comment blocks, based on language-specific rules. You can adjust your user settings to set default folding strategies or automatically collapse regions when opening large files.

By default, VS Code uses indentation-based or language-aware syntax evaluation to calculate fold points. You can tweak how folding behaves by adding specific keys to your `settings.json` file:

"editor.folding": true,
"editor.foldingStrategy": "auto",
"editor.showFoldingControls": "mouseover"

Setting folding controls to `mouseover` keeps the editor margin clean, revealing fold chevrons only when you hover over the line numbers. This minor tweak removes extra visual elements while keeping the functionality handy.

Customizing the Editor Layout

Visual Studio Code features a modular interface where you can drag, split, and position panels to match your multitasking requirements. Reconfiguring your editor windows, moving sidebars, and docking integrated terminals creates an ergonomic workspace tailored to your preferred coding workflow and screen real estate.

Default layout configurations don't fit every monitor setup. If you work on a wide display, keeping a single centered code editor wastes valuable screen real estate. Adjusting your panel locations keeps terminal output, project files, and primary source code visible at the same time.

Splitting the Editor

Splitting the editor pane opens multiple files side-by-side or stacks them vertically, enabling direct cross-referencing and concurrent editing. You can split windows using context menus, shortcut keys, or drag-and-drop tab movements to build up complex multi-column editing arrangements across your displays.

Press `Ctrl+\` (or `Cmd+\` on Mac) to split your active editor pane in half. You can also drag an open tab to any edge of the workspace until a blue drop zone appears. Dropping the tab creates a distinct editor group in that position.

VS Code supports up to grid-based grid layouts. If you regularly compare implementation files with their unit test counterparts, keeping them in side-by-side split groups prevents constant tab switching and keeps your context intact.

Arranging Sidebars and Terminals

Customizing sidebar positions and secondary terminal panels optimizes screen real estate and minimizes unnecessary UI visual clutter. Moving the primary sidebar to the right edge prevents source code layout shift when toggling file trees, while docking panels vertically maximizes horizontal editing space.

By default, opening and closing the left sidebar pushes your source code to the right. To stop this screen jitter, right-click the primary sidebar header and select **Move Primary Side Bar to Right**. Now, opening your file explorer or search panel won't shift your active editing lines around.

You can also drag the terminal panel from the bottom of the screen to the right sidebar area. If you use a widescreen monitor, running the terminal alongside your code leaves more vertical space for reading long source files.

Using Code Lenses for Navigation

Code lenses display inline metadata and actionable commands directly above function signatures, class definitions, and variable declarations. They streamline file navigation by exposing reference counts, unit test triggers, and Git annotations right inside your source file without requiring separate tool panels.

Instead of manually searching across your repository to see where a function gets called, code lenses bring structural data directly to the line level. You get a quick view of dependencies before modifying or refactoring critical methods.

Understanding Code Lenses

Code lenses act as interactive context indicators embedded within your code text. They display live statistics like implementation counts or recent commit authors, providing single-click links to jump directly to caller references, run individual test suites, or inspect implementation details elsewhere in your codebase.

When working with C#, TypeScript, or Java, you'll see faint links above class and method definitions showing how many times that element is referenced throughout the workspace. Clicking the "references" link opens an inline peek window showing every caller.

If you write unit tests using frameworks like Jest or Go's built-in testing package, code lenses display interactive "Run Test" or "Debug Test" links directly above test functions. This lets you execute single tests instantly without switching to a terminal window.

Customizing Code Lenses

Language extensions often add domain-specific code lenses for framework debugging, database migrations, or serverless deployments. You can fine-tune which lenses appear through your settings JSON file, disabling noisy notifications to retain a minimal, high-signal editing space tailored strictly to your project.

If code lenses make your editor feel cluttered or push lines down awkwardly, control them globally or by language. Toggle the feature by searching for "Code Lens" in settings or editing your `settings.json` file directly:

"editor.codeLens": true,
"typescript.referencesCodeLens.enabled": true,
"javascript.referencesCodeLens.enabled": false

Disabling lenses for languages where you don't use them keeps line height stable while preserving the feature for complex languages where reference tracking is essential.

Leveraging Extensions for Advanced Organization

Extensions expand VS Code’s workspace organization capabilities by adding features like path autocomplete, visual indent guidelines, and project management dashboards. Careful selection of well-maintained extensions keeps your workbench responsive while providing deep visual aid and structural feedback across massive software projects.

While VS Code includes great core features, adding a few targeted extensions helps address niche workflow needs. The key is choosing lightweight tools that add clear value without bloating editor startup time.

Popular Code Organization Extensions

Essential organization extensions include Path Intellisense for fast module imports, Todo Tree for tracking pending code tasks, and Indent-Rainbow for visualizing deeply nested code logic. Utilizing built-in features like native bracket pair colorization alongside targeted extensions significantly enhances visual readability.

  • Path Intellisense: Autocompletes file paths in import statements, reducing path typos across complex project trees.
  • Todo Tree: Scans your workspace for `TODO` and `FIXME` comment tags, listing them in a neat sidebar tree view so tasks don't get lost.
  • Indent-Rainbow: Colorizes indent spaces in alternate colors, making deeply nested control structures easy to follow.
  • Native Bracket Coloring: Instead of relying on old third-party plugins like "Bracket Pair Colorizer" (which is now deprecated), enable native bracket colorization directly by

    FAQ

    How do I auto-format my code in Visual Studio?

    Use Edit > IntelliSense > Format Document (or Ctrl+K, Ctrl+D). This applies the current coding style rules to your code, improving readability and consistency.

    How can I organize my code into logical blocks?

    Use regions (compiler directives #region and #endregion) to collapse sections of code. This helps navigate large files and focus on specific parts of your project.

    How do I rearrange code lines easily?

    Select the lines you want to move, right-click, and use Cut or Copy followed by Insert Cut Here or Insert Copied Here. This offers precise control over code placement.

    Editorial Team Author & reviewer

    Hands-on reviewers testing tools, apps and services so you do not have to. Every article here is hands-on tested and human-reviewed before publishing.