Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Copy with Line Numbers(And FileName Too!)New to Visual Studio Code? Get it now.
Copy with Line Numbers(And FileName Too!)

Copy with Line Numbers(And FileName Too!)

seanlab

|
81 installs
| (0) | Free
Copy text with custom line numbers and optional file path header
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Copy With Line Numbers

A simple VS Code extension that copies selected text with formatted line numbers and an optional file path header.

Features

  • Line Numbering:
    Prepends each line of the selected text with its corresponding line number. The line numbers are formatted to align based on the total number of lines (e.g., 2 digits for 10–99 lines, 3 digits for 100–999 lines).

  • Optional File Path:
    When enabled, the extension can insert the relative file path as the first line of the copied text.

  • Customizable Spacing:
    Configurable option to add extra spaces after the line numbers for better readability.

Requirements

  • VS Code version 1.96.0 or later.
  • A workspace with a valid file open.

Extension Settings

This extension contributes the following settings to VS Code:

  • copyWithLineNumbers.addFilePath
    Type: Boolean
    Default: false
    Description: Include the file's relative path as a header in the copied text.

  • copyWithLineNumbers.addExtraSpaces
    Type: Boolean
    Default: true
    Description: Insert two extra spaces after each line number.

How It Works

  1. Select Text:
    Highlight the code or text in your editor.

  2. Run Command:
    Trigger the command Copy with line numbers from the Command Palette (Cmd+Shift+P on macOS or Ctrl+Shift+P on other platforms).

  3. Copy to Clipboard:
    The extension processes the selection by:

    • Calculating the appropriate width for line numbers based on the total lines (using logarithmic calculation).
    • Formatting each line with a padded line number and optional extra spaces.
    • Optionally prepending the file’s relative path.
    • Copying the final formatted text to the clipboard.
  4. Paste:
    You can now paste the formatted text wherever needed.

Debugging & Development

  • Running the Extension:
    Press F5 to launch a new VS Code window with your extension loaded and test your changes.

  • Testing:
    A sample unit test is provided in src/test/formatting.test.ts. Run tests using the VS Code testing view or via the command line with npm run test.

Release Notes

  • 0.0.1:
    Initial release of the extension with customizable line numbering and optional file path header.

License

Licensed under the Apache License, Version 2.0.

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