Package Control

The Sublime Text package directory, re-imagined.

Copy Path

Copy JSONPath, JSON Pointer and XPath at the caret or right-click position in Sublime Text.

OctSepAugJulJunMayAprMarFebJan Dec2025 Nov 2026-W48 | installs: 2 | removals: 0 | upgrades: 0 2026-W48 | installs: 2 | removals: 0 | upgrades: 0 2026-W48 | installs: 2 | removals: 0 | upgrades: 0 024 WeeklyInstalls 024 WeeklyUpgrades 2026-W48 | upgrades: 0 1.4.0 / 1.3.0 / ... 1.4.0 / 1.3.0 / 1.2.0 2026-W46 1.1.0 / 1.0.1 / ... 1.1.0 / 1.0.1 / 1.0.0
Installations: 2 in total
Installations minus removals
Upgrades

Links

Versions

1.4.0 (ST4215+) ·
2026-11-26 21:03

More

Copy Path for Sublime Text

Copy the structural path of the element under your mouse or caret – not the file's filesystem path.

Requires Sublime Text 4 and is tested with build 4215. The plugin runs in Sublime's Python 3.14 plugin host.

Install

Package Control: open the Command Palette, run Package Control: Install Package and choose Copy Path. Updates install automatically.

Manually:

  1. Download Copy Path.sublime-package from the package website or this repository's dist/ folder.
  2. In Sublime Text, choose Preferences → Browse Packages….
  3. Go up one folder, then open or create Installed Packages.
  4. Place Copy Path.sublime-package there without extracting or renaming it, then restart Sublime Text.

JSON, JSONC and XML work right away. For YAML, Copy Path needs Package Control's pyyaml library: if Package Control is installed, it adds the library at the next start (or run Package Control: Satisfy Libraries), then restart Sublime Text. Without it, copying in a YAML file shows a status-bar message instead.

Do not put the ZIP inside Packages/User or double-click it to install. To update, replace the same file and restart. To uninstall, remove that file (or use Package Control: Remove Package) and optionally Packages/User/Copy Path.sublime-settings. Remove any unpacked development Packages/Copy Path copy before using a release archive; otherwise it can override the release.

Use

Mouse: right-click the desired key, value, tag or attribute and choose Copy Element Path. The clicked position wins, even if the caret is somewhere else. Copy Element Path As offers the other formats that fit the file.

Keyboard: place one or more carets, open the Command Palette, and choose Copy Path: Copy Element Path, Copy Path: Copy JSONPath, Copy Path: Copy JSON Pointer, or one of the Copy Path: Copy XPath – … actions. For a nonempty selection the active end is used, not its beginning. A caret directly after a value, for example after double-clicking it or pressing End, copies that value's path. Multiple carets copy unique paths in selection order, one per line. There are no default keybindings; add one if desired:

{ "keys": ["ctrl+alt+c"], "command": "copy_element_path" }

For macOS, choose an unused super combination instead. These are optional examples, not installed bindings.

{"users": [{"name": "Ada", "a/b~c": 42}]}
<catalog><book id="a"/><book id="b">Title</book></catalog>

On the second book tag or its text:

Attribute preference tries id, then xml:id, then other suitable attributes, checking uniqueness among same-name siblings rather than assuming an id is unique. Other attributes are chosen deterministically by expanded name; blank, multiline or longer-than-128-character values are unsuitable. Text preference uses nonblank, single-line leaf-element string values of at most 128 characters and checks against all same-name siblings, including mixed-content elements. Descriptive styles omit unnecessary positions; ambiguous or unsuitable steps fall back to positions. Text preference does not fall back to attribute predicates. Positional mode always includes each element's ordinal. Explicit submenu choices do not change your default.

Containers own their brackets/tags and intervening whitespace. A property owns its key, colon and value. XML closing tags select the matching element; text, comments and CDATA select their containing element. For well-formed XML, outside the root the path is /. At end-of-file the document/root path is selected; incomplete-XML recovery refuses these uncertain locations. A root JSON Pointer is the empty string; copying it intentionally clears the clipboard and the status message explains this.

Supported input and limits

Except for the bounded XML recovery below, a malformed or unsupported document leaves the clipboard unchanged and gives a short status-bar reason. Fix the document or choose its syntax. If you edit, move the selection, close the view or switch tabs before parsing finishes, that outdated result is discarded. No document text is logged.

Incomplete XML

When the document ends with missing ancestor closing tags, a completed element can still yield a reliable positional path. For example, copying the second book from this unfinished document produces /catalog[1]/book[2]:

<catalog><book id="a"/><book id="b">Title</book>

The status bar explicitly says Copied positional XPath from incomplete XML. This fallback applies even when attributes or text are preferred, since unclosed ancestors prevent proving sibling uniqueness. The buffer is never repaired or changed.

Recovery does not accept mismatched tags, unfinished tags/quotes/comments/CDATA, undefined entities, DTDs, or resource-limit failures. Only completed elements and their attributes are selectable; open ancestors, trailing gaps and EOF are refused. If any caret is uncertain, nothing is copied. JSON/JSONC/YAML still require a valid supported document.

Settings

Open Preferences → Package Settings → Copy Path → Settings, or run Preferences: Copy Path Settings from the Command Palette. Defaults:

{
  "format": "auto",
  "json_path_style": "jsonpath",
  "xml_path_style": "attributes",
  "show_copy_element_path": true,
  "show_submenu_copy_element_path_as": true,
  "max_file_chars": 2000000
}

Right-click menu

The right-click menu has Copy Element Path and the Copy Element Path As submenu. In JSON and YAML files the submenu offers JSONPath and JSON Pointer, in XML files the three XPath styles. In other files every entry is shown greyed out. Sublime Text on Windows and macOS always draws the Copy Element Path As heading, even when show_submenu_copy_element_path_as is false.

To remove the entries completely, or to keep only the ones you use, replace the package's menu file with your own:

  1. Choose Preferences → Browse Packages… and create a folder named Copy Path there.
  2. In that folder, create a file named Context.sublime-menu.
  3. To remove the entries, put [] in the file. To customize them, copy the original menu into the file and delete the entries you don't want.

Your file replaces the package's menu until you delete it. After an update, compare it with the original menu if you want new entries. The Command Palette commands are not affected.

Development

python3 tools/build_package.py
python3 tools/check.py

build_package.py writes dist/Copy Path.sublime-package; check.py runs the tests and fails if that file is out of date. See development and architecture for details.

License

MIT; see LICENSE.

Results

Packages