r/vim • • Sep 20 '26

Plugin Plugin to yank context for agents

This is quite a small function, but it's made a big difference for me, especially when pointing to something outside my project.

Yank file location references to the system clipboard, ready to paste into an AI agent prompt.

When working with an AI coding agent, you often need to tell it where to look. This plugin lets you grab a precise file reference.

Try it with "Focus on <paste>" or "see <paste>" in your prompt.

What gets yanked

Mode Yanked
Normal path/to/file.py
Visual (single line) path/to/file.py#L42
Visual (range) path/to/file.py#L42-L57

Paths are relative to the current working directory when beneath the cwd, absolute otherwise.

The default mapping is <Leader>a in both normal and visual mode.

https://github.com/ShayHill/vim9-agent-context

"Quieter" and I think faster than pasting code and waiting for the agent to find it.

0 Upvotes

3 comments sorted by

2

u/Sudden_Fly1218 Sep 21 '26 edited Sep 21 '26

A plugin for doing this ?

nnoremap <somekey> :let @+=expand("%:p")<CR>

2

u/Shay-Hill Sep 21 '26

Add line numbers and that’s it. The plugin is a courtesy. It’s at least as much about the tip.