Helix keybinding: copy file location + selected code for coding agents #15774
Unanswered
mtul0729
asked this question in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have been using a small Helix keybinding that has turned out to be very useful when working with coding agents.
The idea is simple: select some code, press a key, and copy both:
This makes it easy to paste precise context into ChatGPT, Codex, Claude, GitHub issues, or review comments.
For example, selecting a few lines and pressing
Space lcopies something like this:Space Ldoes the same thing, but expands the file path to an absolute path.Requirements
This depends on current Helix preview/master because it uses
:set-register.The keybinding also uses Helix expansion variables such as
%{buffer_name},%{selection_line_start},%{selection_line_end}, and%{selection}.I use Nushell as the editor shell so the small script can stay reasonably cross-platform:
Configuration
Notes
extend_to_line_boundsis intentional here. When I send code to an agent, I usually want complete lines rather than a partial character selection.The temporary
lregister is only used to build the location string. The final result is written to the system clipboard register+, then the temporary register is cleared.The relative-path version is better for repository-local discussion. The absolute-path version is useful when the receiving tool has access to the same local filesystem and can open the exact file directly.
All reactions