CiteCode
English | 简体中文
A VSCode extension for quickly copying code citations (file path + line range).
Select code, copy its citation in one click:
src/index.js:21-30
Paste it into an issue, a PR comment, your docs, or send it directly to AI tools like Codex / OpenCode to pinpoint a code location.
Features
- Copy the citation for the current selection:
src/index.js:21-30
- Single-line selections copy only
src/index.js:21
- With no selection, the line under the cursor is cited
- Multiple selections are output one per line (configurable to join with commas)
- Collect ordered, deduplicated references from multiple files in an in-memory reference list, then copy them together
- The status bar shows the reference count and a read-only preview; copying can optionally clear the list
- CodeLens buttons appear above the selection: Copy Reference / Copy Reference and Snippet / Add to Reference List
- Context menu: Copy Code Path, Copy File Path, and Add to Reference List, also available from the command palette
- Keyboard shortcuts:
Ctrl+Alt+C copies the code path / Ctrl+Alt+F copies the file path (macOS: Cmd+Alt+C / Cmd+Alt+F)
- Reference-list shortcuts:
Ctrl+Alt+A adds references / Ctrl+Alt+Shift+C performs the default list copy action (macOS: Cmd+Alt+A / Cmd+Alt+Shift+C)
- Configurable: path format (relative/absolute), include columns, join multiple selections, CodeLens toggle, and clear-after-copy behavior
Installation
Search for CiteCode in the VSCode extension panel (Ctrl+Shift+X) and click Install; or click Install on the Visual Studio Marketplace page.
For local development: run npm run build && npx vsce package in the project directory, then use "Install from VSIX..." to install the generated cite-code-x.y.z.vsix (see Development below).
Requirements
- Visual Studio Code 1.85 or later
Usage
- Select code; three buttons appear above the first line of the selection
- Click Copy Reference to copy
src/index.js:21-30
- Click Copy Reference and Snippet to copy the citation plus the code snippet
- Click Add to Reference List to collect the selection without replacing the clipboard
Method 2: Context menu / command palette
Place the cursor on the target code (with a selection, the selection is cited; without one, the line under the cursor is cited)
Right-click → Copy Code Path (relative path + line range); choose Copy File Path to copy only the file path without line numbers. Or use the shortcuts Ctrl+Alt+C / Ctrl+Alt+F (macOS: Cmd+Alt+C / Cmd+Alt+F, customizable in keybindings.json), or run the commands from the command palette
Paste the citation into an issue, a PR comment, or your docs, for example:
The problem is in src/index.js:21-30
The same format also works with AI tools: paste it into Codex / OpenCode and they can pinpoint the exact code location.
Collect references across files
- Select code in one or more files and run Add to Reference List, or press
Ctrl+Alt+A (macOS: Cmd+Alt+A). Multiple selections are added together; with no selection, the cursor line is added.
- The status bar shows the deduplicated reference count. Hover over it to preview the complete list.
- Click the status bar item or press
Ctrl+Alt+Shift+C (macOS: Cmd+Alt+Shift+C) to copy the list. By default, successfully copied entries are cleared.
The command palette also provides fixed Copy Reference List, Copy and Clear Reference List, and Clear Reference List commands. The list exists only in the current window's memory and is discarded when the window closes or reloads.
Configuration
| Setting |
Default |
Description |
citeCode.pathFormat |
relative |
Path format for all copy entry points (context menu, shortcuts, CodeLens, command palette): relative (e.g. src/index.js) or absolute (e.g. /home/user/project/src/index.js); applies to both code paths and file paths |
citeCode.includeColumns |
false |
When true, citations include start and end columns (e.g. src/index.js:21:10-30:17) |
citeCode.joinMultipleSelections |
false |
When true, multiple selections are joined with commas on one line (e.g. src/index.js:58-64, 80-85); default is one line per selection |
citeCode.showCodeLens |
true |
When false, hides the CodeLens buttons (the context menu still works) |
citeCode.clearReferenceListAfterCopy |
true |
Controls the status bar and reference-list copy shortcut: when true, successfully copied references are removed; when false, the list is preserved and a separate clear button is shown |
Development
npm run typecheck – TypeScript type checking
npm run build / npm run watch – esbuild bundling
npm run unit-test – unit tests for pure logic (no editor needed)
npm run integration-test – integration tests in a real VSCode instance
- Press F5 in VSCode – launch the Extension Development Host for debugging
- Package for the Marketplace:
npx vsce package
License
MIT
| |