Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Copy Path with LinesNew to Visual Studio Code? Get it now.
Copy Path with Lines

Copy Path with Lines

Thiago Melo

|
1 install
| (0) | Free
Copy absolute or relative file paths with line and selection references to the clipboard.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Copy Path with Lines

Copy absolute or relative file paths — with optional line numbers and selection ranges — straight to your clipboard. Ideal for referencing code locations in tickets, pull requests, chat, or documentation.


Commands

Four commands are available from the right-click context menu inside the editor (under Copy Path with Lines) and from the Command Palette (Ctrl+Shift+P / Cmd+Shift+P):

Command Description
Copy Absolute Path Full OS path to the file, no line suffix
Copy Absolute Path with Lines Full path + current cursor line or selection range(s)
Copy Relative Path Path relative to the workspace root, no line suffix
Copy Relative Path with Lines Relative path + current cursor line or selection range(s)

Output Format

<path>:<line-suffix>

The path separator matches your OS (backslash on Windows, forward slash on Linux/Mac). Line numbers are always 1-based.

Linux / Mac examples

Situation Absolute Relative
No selection (file only) /home/user/proj/src/my_file.py src/my_file.py
Cursor on line 23 /home/user/proj/src/my_file.py:23 src/my_file.py:23
Selection: lines 23–45 /home/user/proj/src/my_file.py:23-45 src/my_file.py:23-45
Two ranges: 23–45 and 50 /home/user/proj/src/my_file.py:23-45,50 src/my_file.py:23-45,50
Two ranges: 23–45 and 50–98 /home/user/proj/src/my_file.py:23-45,50-98 src/my_file.py:23-45,50-98
Two cursors: line 23 and 50 /home/user/proj/src/my_file.py:23,50 src/my_file.py:23,50
Cursor 23 and range 50–98 /home/user/proj/src/my_file.py:23,50-98 src/my_file.py:23,50-98

Windows examples

Situation Absolute Relative
No selection C:\Users\user\proj\src\my_file.py src\my_file.py
Cursor on line 23 C:\Users\user\proj\src\my_file.py:23 src\my_file.py:23
Selection: lines 23–45 C:\Users\user\proj\src\my_file.py:23-45 src\my_file.py:23-45
Two ranges: 23–45 and 50–98 C:\Users\user\proj\src\my_file.py:23-45,50-98 src\my_file.py:23-45,50-98

Usage

  1. Position your cursor or make a selection (or multiple selections — see below)
  2. Right-click anywhere in the editor
  3. Hover over Copy Path with Lines
  4. Click the command you want
  5. The result is in your clipboard — paste anywhere

Working with Multiple Selections

The "with Lines" commands are aware of all active cursors and selections. Each selection becomes a token (line or start-end), sorted top-to-bottom and joined with commas.

Multiple cursors → :23,50

Shortcut How
Alt+Click / Option+Click Place an additional cursor anywhere
Ctrl+D / Cmd+D Select next occurrence of the current word (adds a cursor per match)
Ctrl+Alt+↑ / Cmd+Option+↑ Add cursor on the line above
Ctrl+Alt+↓ / Cmd+Option+↓ Add cursor on the line below

Each cursor is on a single line → each token is a single line number → result: :23,50

Multiple range selections → :10-15,23-30

Shortcut How
Ctrl+D / Cmd+D (repeated) Each press selects the next occurrence as a full range
Ctrl+Shift+L / Cmd+Shift+L Select all occurrences of the current word at once

Each selection spans multiple lines → each token is a range → result: :10-15,23-30

Column / box selection → one token per row

Shortcut How
Shift+Alt+drag / Shift+Option+drag Drag to create a rectangular multi-line selection

Each row becomes a separate selection → each token is a single line → result: :10,11,12,13


Fallback Behavior

  • No workspace open: "Copy Relative Path" commands automatically fall back to the absolute path.
  • File outside the workspace root: same fallback — if the relative path would start with ../, the absolute path is used instead.
  • Unsaved (untitled) file: a warning is shown and nothing is copied.

Installation

From the Marketplace

Search for Copy Path with Lines in the VS Code Extensions panel (Ctrl+Shift+X / Cmd+Shift+X) and click Install.

From a .vsix file

code --install-extension copy-path-with-lines-0.1.0.vsix

License

MIT

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