Copy file references and explorer paths from visual selections into the system clipboard.
:'<,'>RefCopycopies the current visual selection. In file buffers it copies a file reference; in supported explorer buffers it copies selected paths.:'<,'>RefCopyAbsolutedoes the same with absolute paths.:'<,'>RefCopyExplorerexplicitly copies selected paths fromnetrworoil.nvim.:'<,'>RefCopyExplorerAbsoluteexplicitly copies absolute explorer paths.- Formats are configurable with simple
{token}placeholders.
The default single-line file format is:
{path}#L{line}
For a single selected line, the default output is:
lua/refcopy/init.lua#L24
The default multi-line file format is:
{path}#L{start}-L{end}
For a multi-line visual selection, the default output is:
lua/refcopy/init.lua#L24-L31
In netrw and oil.nvim buffers, RefCopy copies one selected entry per line. The default explorer format is:
{path}
If you prefer a different shape, configure the single-line, multi-line, and explorer formats directly:
require("refcopy").setup({
single_line_format = "{path}:{line}",
multi_line_format = "{path}:{start}-{end}",
explorer_format = '"{path}"',
})require("refcopy").setup({
clipboard_register = "+",
single_line_format = "{path}#L{line}",
multi_line_format = "{path}#L{start}-L{end}",
explorer_format = "{path}",
})The placeholder syntax is defined by this plugin. It is simple string replacement, not Lua evaluation.
File formats support {path}, {line}, {start}, {end}, and {cwd}.
Explorer formats support {path}, {name}, and {cwd}.
{
"KudoLayton/refcopy.nvim",
main = "refcopy",
opts = {},
keys = {
{ "<leader>ry", ":RefCopy<CR>", mode = "x", desc = "Copy file reference" },
{ "<leader>rY", ":RefCopyAbsolute<CR>", mode = "x", desc = "Copy absolute reference" },
},
}To configure it:
{
"KudoLayton/refcopy.nvim",
main = "refcopy",
opts = {
single_line_format = "{path}#L{line}",
multi_line_format = "{path}#L{start}-L{end}",
explorer_format = "{path}",
},
}- Relative paths are calculated from
vim.fn.getcwd(). - Path separators are not normalized; Neovim and the OS decide the path shape.
oil.nvimsupport is optional. If it is not installed, file buffer and netrw copying still work.