A single Lua keymap that copies @file:line-range to your system clipboard, so you can attach any selection to Claude Code the same way Cursor lets you with Cmd+L.
One thing I missed when I moved from Cursor to Neovim + Claude Code was the context attachment shortcut. In Cursor, Cmd+K opens an inline prompt where the current file is already attached. Cmd+L does the same for the chat panel. You select some code, hit the shortcut, and you’re talking about exactly that snippet.
Claude Code has no equivalent built-in for Neovim. There’s no IDE extension, no sidebar — just a CLI running in a terminal. You’re on your own to bridge the gap.
What I tried first
The most common advice online is: run Claude Code in a tmux pane next to Neovim, yank text to system clipboard with "+y, switch panes, paste. Simple, zero setup.
It works, but the friction adds up. You lose the line range context. Claude sees floating code with no file name and no location. If you’re asking about a function, you almost always need to say where it lives, and typing that by hand every time gets old fast.
The key insight
Claude Code understands @file:line-range syntax. If you paste @/absolute/path/to/file.lua:80-92 into the prompt, Claude fetches those exact lines and treats them as context — the same way it does when you use @ to attach a file from the CLI.
So the problem reduces to: make Neovim write that string to the clipboard automatically when I select code.
The keymap
Two keymaps share the same mnemonic (<leader>yp — yank path). Normal mode copies just the file path. Visual mode copies the full @file:line-range reference (Yes, I have a command to copy the absolute path, it is super useful!).
-- Normal mode: copy absolute file path
vim.keymap.set('n', '<leader>yp', function()
local path = vim.fn.expand'%:p'
vim.fn.setreg('+', path)
vim.notify('Copied: ' .. path)
end, { desc ='[Y]ank file [p]ath' })
-- Visual mode: copy @file:line or @file:start-end
end, { desc ='[Y]ank file [p]ath with line range' })
A few things worth noting:
vim.fn.expand '%:p' expands the current buffer’s path to its absolute form. No relative paths, no ~ — Claude Code needs the full path to easily find the file.
vim.fn.line 'v' gives the line where the visual selection started, and vim.fn.line '.' gives where the cursor currently is. When you select upward, start > end, so the swap normalizes the order.
Single-line selection produces @/path/file:42, multi-line produces @/path/file:42-50. Keeps it clean.
vim.fn.setreg('+', ...) writes to the system clipboard register directly. No "+y needed.
vim.notify gives you a confirmation popup — helpful to confirm what got copied before you switch windows.
How to use it
Open any file in Neovim.
Enter visual mode (v, V, or Cmd+V) and select the lines you want to reference.
Press <leader>yp. A notification appears showing the copied reference.
Switch to your Claude Code terminal and paste (Cmd+V or middle-click).
The pasted text looks like this:
@/Users/jcconnects/.dotfiles/nvim/init.lua:17-29
Claude Code reads the file at that path, extracts lines 17–29, and includes them as context for your prompt.
Proof it works
During the session where I built this, I tested it immediately by copying a reference and pasting it raw into Claude Code with no other prompt:
@/Users/jcconnects/.dotfiles/nvim/init.lua:17-29
Claude’s response:
Yes, I can see it. That’s lines 17–29 of your init.lua:
The keymap is working. That’s your editor options block.
It fetched exactly those lines. No copy-paste of the code content required.
What this replaces
The workflow now feels close to what Cursor offers:
Cursor
Neovim + Claude Code
Select code, Cmd+K → inline prompt with context attached
<leader>yp → switch to Claude Code → paste reference + type prompt
Cmd+L → chat with file attached
<leader>yp → switch to Claude Code → paste reference
Not identical — you still switch windows — but the context is precise and zero-friction once the keymap is in muscle memory.
<leader>yp covers 90% of the workflow. Twenty-something lines of Lua, no plugins, no external dependencies.
Conclusion
Cursor’s Cmd+L is convenient because it removes a mental step: you don’t have to tell the AI where the code is, it already knows. That’s the whole trick — and it turns out you can replicate it in Neovim with a single keymap and no plugins.
The @file:line-range syntax is the bridge. Once you know it exists, the rest is just Lua glue to put the right string on your clipboard. If you live in Neovim and use Claude Code, this is worth the five minutes it takes to add.
João Cordeiro is a DevOps and SRE specialist who loves building connections between people and technology.