Skip to content

Instantly share code, notes, and snippets.

@rstacruz
Last active August 19, 2025 13:12
Show Gist options
  • Select an option

  • Save rstacruz/c1dbfa0a63dcfa5c6fa3d461bfa0ae70 to your computer and use it in GitHub Desktop.

Select an option

Save rstacruz/c1dbfa0a63dcfa5c6fa3d461bfa0ae70 to your computer and use it in GitHub Desktop.

Copy file path to clipboard

Here's a simple way to integrate Neovim with OpenCode or Claude Code.

  1. Select some text
  2. Press <leader>fyr
  3. Paste it into the LLM agent of your choice

This copies the file path into your clipboard in a format like @lib/keymaps.lua#L24-36. This mimics what the Claude Code VS Code extension would do (Alt+Cmd+K).

You can then paste it into your LLM agent as @docs/instructions.md#L12-19 convert this list to a table

vim.keymap.set("n", "<leader>fyr", function()
local str = vim.fn.expand("%:.")
vim.fn.setreg('"', str)
vim.fn.setreg("+", str)
vim.notify(" " .. str)
end, { desc = " Copy relative path" })
-- Copy relative path with line numbers
vim.keymap.set("v", "<leader>fyr", function()
local start_line = vim.fn.line("v")
local end_line = vim.fn.line(".")
local line_range = ""
if start_line == end_line then
line_range = "#L" .. start_line
else
line_range = "#L" .. start_line .. "-" .. end_line
end
local str = vim.fn.expand("%:.") .. line_range
vim.fn.setreg('"', str)
vim.fn.setreg("+", str)
vim.notify(" " .. str)
end, { desc = " Copy relative path with line numbers" })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment