Copy file path, line number, and selected text in VS Code via a CMD+CTRL+C A developer published a macOS-only VS Code setup that binds ⌘⌃C to copy an absolute path:line reference, plus the selected text in a dynamically sized Markdown code block, for pasting into code reviews or coding-agent chats. The setup uses VS Code's built-in tasks and macOS's pbcopy, with no extensions or external dependencies, and adjusts the code fence length to avoid conflicts with backticks in the selection. Two task definitions and two keybindings are added to the user's existing tasks and keybindings JSON files. Use ⌘⌃C on macOS to copy a reference for a code review or a coding agent. The shortcut uses VS Code’s built-in tasks and macOS’s pbcopy . - With no selection, it copies just the absolute path:line . - With a selection, it copies path:line followed by the selected text in a Markdown code block. - The code block delimiter dynamically adjusts its length to avoid conflicts with backticks in the selected text. Alternative formatting options are also provided. Paste into your chat and type your feedback after the reference. In a Git diff, use the editable side so the line number refers to the working file. No extensions or external dependencies are required. js /Users/you/Code/my-project/app/src/example.ts:23 Selected code: const title = item.name.trim ; For a multiline selection, the reference uses the active cursor line, and the code block includes the full selection. /Users/you/Code/my-project/app/src/example.ts:23 The script starts with three backticks and adds more until the delimiter no longer appears anywhere in the selected text. This prevents nested code blocks from prematurely closing the outer code block. For example, if the selected text contains three consecutive backticks, the outer code block will use four. Open the Command Palette with ⌘⇧P and run Tasks: Open User Tasks . If you already have tasks, add these two objects to your existing tasks array. { "version": "2.0.0", "tasks": { "label": "Copy path and line", "type": "process", "command": "/bin/bash", "args": "-c", "printf '%s' \"$1\" | /usr/bin/pbcopy", "--", "${file}:${lineNumber}" , "presentation": { "reveal": "never", "close": true, "echo": false, "focus": false, "showReuseMessage": false, }, "problemMatcher": , }, { "label": "Copy path and selection", "type": "process", "command": "/bin/bash", "args": "-c", "fence=' '; while \"$2\" == \"$fence\" ; do fence+=' '; done; printf '%s\\n\\nSelected code:\\n%s\\n%s\\n%s\\n\\n' \"$1\" \"$fence\" \"$2\" \"$fence\" | /usr/bin/pbcopy", // alternative 1: "printf '%s\\n\\n