Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nvim-get-ref

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.

Installation

lazy.nvim

{
  'WarrenZhu050413/nvim-get-ref',
  config = function()
    require('nvim-get-ref').setup()
  end,
}

packer.nvim

use {
  'WarrenZhu050413/nvim-get-ref',
  config = function()
    require('nvim-get-ref').setup()
  end,
}

Usage

Default Keybindings

  • Visual mode: <leader>yf - Copy reference for selected text
  • Normal mode: <leader>yf - Copy reference for cursor position

Examples

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

Configuration

Custom Keybindings

require('nvim-get-ref').setup({
  keymaps = {
    visual = '<leader>yr',  -- Custom visual mode binding
    normal = '<leader>yr',  -- Custom normal mode binding
  },
})

Custom Register

require('nvim-get-ref').setup({
  register = '"',  -- Use default register instead of clipboard
  -- Other options: '+' (clipboard, default), '*' (selection), 'a'-'z' (named registers)
})

Path Style and Prefix

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 to getcwd(). Files outside the project root fall back to the absolute path.
  • path_prefix: string prepended to every path (e.g. @). Set '' to disable.

Disable Auto Keymaps

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)

Commands

  • :GetRefYank - Copy reference from visual selection
  • :GetRefYankNormal - Copy reference from cursor position

How It Works

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.)

Testing

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.

License

MIT

About

Neovim plugin to copy file references in Claude Code format

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages