A Neovim plugin that yanks code references in Claude AI's preferred format (@filename#L10-20), making it seamless to share code context in conversations.
yank.mp4
- Smart Format: Automatically formats code references as
@file.lua#L10-L20for multi-line or@file.lua#L10for single line - Visual Mode Support: Works naturally with Neovim's visual selection
- Yank Highlight: Integrates with existing
TextYankPostautocmds to show visual feedback - Flexible: Use via commands or direct key mappings
- Include Code: Option to include actual code content along with references
Using lazy.nvim
{
'wasabeef/yank-for-claude.nvim',
config = function()
require('yank-for-claude').setup()
end,
keys = {
-- Reference only
{ '<leader>y', function() require('yank-for-claude').yank_visual() end, mode = 'v', desc = 'Yank for Claude' },
{ '<leader>y', function() require('yank-for-claude').yank_line() end, mode = 'n', desc = 'Yank line for Claude' },
-- Reference + Code
{ '<leader>Y', function() require('yank-for-claude').yank_visual_with_content() end, mode = 'v', desc = 'Yank with content' },
{ '<leader>Y', function() require('yank-for-claude').yank_line_with_content() end, mode = 'n', desc = 'Yank line with content' },
},
}use {
'wasabeef/yank-for-claude.nvim',
config = function()
require('yank-for-claude').setup()
end
}-- Setup the plugin first
require('yank-for-claude').setup()
-- Map keys to commands
vim.keymap.set('v', '<leader>y', ':YankForClaude<cr>', { desc = 'Yank for Claude' })
vim.keymap.set('v', '<leader>Y', ':YankForClaudeWithContent<cr>', { desc = 'Yank with content' })- Visual Mode: Select code and press your mapped key (e.g.,
<leader>y) - Normal Mode: Press your mapped key to yank current line reference
- Paste in Claude AI chat - it will recognize the format
Reference only (<leader>y):
@src/utils.lua#L45-L67
Reference with code (<leader>Y):
@src/utils.lua#L45-L67
function calculateTotal(items)
local total = 0
for _, item in ipairs(items) do
total = total + item.price
end
return total
end
require('yank-for-claude').setup({
-- Show notifications after yanking
notify = true,
})| Command | Description |
|---|---|
:YankForClaude |
Yank code reference in Claude AI format |
:YankForClaudeWithContent |
Yank code reference with content |
All commands support range (work with visual selection).
For direct key mappings, these functions are available:
| Function | Mode | Description |
|---|---|---|
yank_visual() |
Visual | Yank reference only |
yank_visual_with_content() |
Visual | Yank reference + code |
yank_line() |
Normal | Yank current line reference |
yank_line_with_content() |
Normal | Yank current line + code |
- The plugin respects your existing yank highlight settings (
TextYankPost) - Works with both
+and*registers for maximum compatibility - File paths are relative to your current working directory
- Neovim >= 0.7.0
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
MIT License - see LICENSE for details.
Made with โค๏ธ to enhance Claude AI conversations