Copy file references in Claude Code format directly from Neovim.
When you select code in Neovim and press <leader>yf, this plugin copies a reference like @src/file.lua#L10:C5-C15 to your clipboard. You can paste this reference into Claude Code to point to specific lines and columns.
{
'WarrenZhu050413/nvim-get-ref',
config = function()
require('nvim-get-ref').setup()
end,
}use {
'WarrenZhu050413/nvim-get-ref',
config = function()
require('nvim-get-ref').setup()
end,
}- Visual mode:
<leader>yf- Copy reference for selected text - Normal mode:
<leader>yf- Copy reference for cursor position
Single line selection (columns 5-15 on line 10):
@src/file.lua#L10:C5-C15
Multi-line selection (line 10 col 5 to line 15 col 20):
@src/file.lua#L10:C5-L15:C20
Visual line mode (entire lines 10-15):
@src/file.lua#L10-L15
Single line (visual line mode on line 10):
@src/file.lua#L10
require('nvim-get-ref').setup({
keymaps = {
visual = '<leader>yr', -- Custom visual mode binding
normal = '<leader>yr', -- Custom normal mode binding
},
})require('nvim-get-ref').setup({
register = '"', -- Use default register instead of clipboard
-- Other options: '+' (clipboard, default), '*' (selection), 'a'-'z' (named registers)
})require('nvim-get-ref').setup({
path_style = 'cwd', -- 'absolute' (default) or 'cwd' (relative to current working directory)
path_prefix = '@', -- Prepended to the path. Set '' to disable (default: '@')
})path_style = 'absolute': full file path (default, backward compatible).path_style = 'cwd': path relative togetcwd(). Files outside the project root fall back to the absolute path.path_prefix: string prepended to every path (e.g.@). Set''to disable.
require('nvim-get-ref').setup({
setup_keymaps = false, -- Don't set up keybindings automatically
})Then set your own:
vim.keymap.set('v', '<leader>yf', function()
require('nvim-get-ref').yank_reference()
end)
vim.keymap.set('n', '<leader>yf', function()
require('nvim-get-ref').yank_reference_normal()
end):GetRefYank- Copy reference from visual selection:GetRefYankNormal- Copy reference from cursor position
The plugin reads Neovim's visual selection marks ('< and '>) and formats them into Claude Code's file reference syntax. Line numbers are 1-indexed, matching Claude's file edit tools and standard text editor conventions. It handles:
- Character-wise visual mode (
v) - Line-wise visual mode (
V) - Block-wise visual mode (
<C-v>) - Edge cases (invalid positions, very long lines, etc.)
The plugin includes 37 tests (34 unit + 3 integration).
# Run unit tests
nvim --headless -u tests/minimal_init.lua -c "PlenaryBustedFile tests/unit/core_spec.lua" -c "qa!"
# Run integration tests
nvim --headless -u tests/minimal_init.lua -c "PlenaryBustedFile tests/integration/integration_spec.lua" -c "qa!"Requires plenary.nvim for testing.
MIT