Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Preserve Indent on PasteNew to Visual Studio Code? Get it now.
Preserve Indent on Paste

Preserve Indent on Paste

9 Labs Inc.

|
33 installs
| (0) | Free
A simple extension that ensures that code blocks pasted have their indentation preserved
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Paste With Indentation

A Visual Studio Code extension that preserves (and adjusts) indentation when pasting multi-line code snippets. No more endless manual re-formatting!

Features

  • Indentation Preservation: Automatically detects the minimal common indentation in the pasted code and aligns it with your current cursor’s indentation level.
  • Multi-Cursor Support: Works seamlessly with multiple cursors, so each pasted snippet is adjusted appropriately.
  • Configurable Keybinding: By default, this extension listens on Ctrl+Shift+V (Windows/Linux) or Cmd+Shift+V (macOS), but you can easily override your default paste shortcut if you prefer.

How It Works

  1. Copy any code snippet with indentation from another file or source.
  2. Place your cursor where you want the code to be inserted in VS Code.
  3. Trigger the Command:
    • By default, press Ctrl+Shift+V on Windows/Linux, or Cmd+Shift+V on macOS.
  4. Result: Your pasted code is automatically re-indented to match your current line’s indentation.

Installation

From the Marketplace

  1. Open VS Code, go to the Extensions panel.
  2. Search for Paste With Indentation (or your extension name).
  3. Click Install.
  4. Reload Visual Studio Code if prompted.

From a VSIX File (Offline Installation)

If you have the .vsix package:

  1. Open VS Code, go to the Extensions panel.
  2. Click the … menu (top right) and select Install from VSIX.
  3. Choose the downloaded .vsix file.
  4. Reload Visual Studio Code if prompted.

Usage

  • After installation, when you want to preserve indentation while pasting, press Ctrl+Shift+V (Windows/Linux) or Cmd+Shift+V (macOS).
  • The extension detects the current line’s indentation, detects the minimal indentation in the copied snippet, and merges them so your code block remains aligned.

Updating Keybindings

If you want to override the default paste (Ctrl+V / Cmd+V) so that all paste actions use this extension’s functionality:

  1. Open VS Code’s Command Palette

    • Windows/Linux: Ctrl+Shift+P
    • macOS: Cmd+Shift+P
  2. Search for “Preferences: Open Keyboard Shortcuts (JSON)” and select it.

  3. In the keybindings.json file that opens, add or edit entries like this:

    [
      // 1) Unbind the default paste action
      {
        "key": "ctrl+v",
        "command": "-editor.action.clipboardPasteAction",
        "when": "editorTextFocus"
      },
      // 2) Rebind Ctrl+V to the new pasteWithIndentation command
      {
        "key": "ctrl+v",
        "command": "extension.pasteWithIndentation",
        "when": "editorTextFocus"
      }
    ]
    

    Note:

    • Replace ctrl+v with cmd+v on macOS.
    • Adjust keys/shortcuts to your personal preference or OS.
  4. Save the file, and your custom keybinding will take effect immediately.

Contributing

Feel free to open issues or pull requests on the GitHub repository if you encounter any bugs or want to request new features.

License

MIT License. See LICENSE for details.


Enjoy fuss-free, indentation-preserving pastes in your everyday coding!

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft