wasabeef/yank-for-claude.nvim

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.

โ˜… 17Forks 1LuaGitHub โ†—Compare
neovim-plugin

README

yank-for-claude.nvim

Format & Lint License: MIT Neovim

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

โœจ Features

  • Smart Format: Automatically formats code references as @file.lua#L10-L20 for multi-line or @file.lua#L10 for single line
  • Visual Mode Support: Works naturally with Neovim's visual selection
  • Yank Highlight: Integrates with existing TextYankPost autocmds to show visual feedback
  • Flexible: Use via commands or direct key mappings
  • Include Code: Option to include actual code content along with references

๐Ÿ“ฆ Installation

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' },
  },
}

Using packer.nvim

use {
  'wasabeef/yank-for-claude.nvim',
  config = function()
    require('yank-for-claude').setup()
  end
}

Alternative: Using commands

-- 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' })

๐Ÿš€ Usage

Basic Usage

  1. Visual Mode: Select code and press your mapped key (e.g., <leader>y)
  2. Normal Mode: Press your mapped key to yank current line reference
  3. Paste in Claude AI chat - it will recognize the format

Examples

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

โš™๏ธ Configuration

require('yank-for-claude').setup({
  -- Show notifications after yanking
  notify = true,
})

๐Ÿ”ง Commands

Command Description
:YankForClaude Yank code reference in Claude AI format
:YankForClaudeWithContent Yank code reference with content

All commands support range (work with visual selection).

๐Ÿ“š Functions

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

๐ŸŽฏ Tips

  • 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

๐Ÿ“‹ Requirements

  • Neovim >= 0.7.0

๐Ÿค Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

๐Ÿ“„ License

MIT License - see LICENSE for details.


Made with โค๏ธ to enhance Claude AI conversations

Contributors

wasabeef

Issues