A simple Neovim plugin to copy file paths to your system clipboard.
- Copy absolute file paths with
:CopyFilePathAbsor<leader>yp - Copy relative file paths with
:CopyFilePathRelor<leader>yr - Visual feedback via notifications
- Handles edge cases (empty buffers, no file)
- Zero dependencies (uses only Neovim built-in APIs)
Add this to your plugin configuration (e.g., ~/.config/nvim/lua/plugins/copy-filepath.lua):
return {
"your-username/neovim-plugins",
dir = "copy-filepath.nvim",
-- Load on first keymap use (lazy loading)
keys = {
{ "<leader>yp", desc = "Yank absolute path" },
{ "<leader>yr", desc = "Yank relative path" },
},
}If you're developing or using this locally:
return {
dir = "~/code/neovim-plugins/copy-filepath.nvim",
name = "copy-filepath",
keys = {
{ "<leader>yp", desc = "Yank absolute path" },
{ "<leader>yr", desc = "Yank relative path" },
},
}Add to your runtimepath:
set rtp+=~/code/neovim-plugins/copy-filepath.nvimOr use your preferred plugin manager (vim-plug, packer, etc.).
:CopyFilePathAbs- Copy the absolute path of the current buffer:CopyFilePathRel- Copy the relative path of the current buffer
<leader>yp- Yank (copy) absolute path<leader>yr- Yank (copy) relative path
If you prefer to set your own keymaps, disable the defaults:
vim.g.copy_filepath_no_default_keymaps = 1Then add your custom keymaps:
vim.keymap.set("n", "<your-key>", "<cmd>CopyFilePathAbs<cr>", { desc = "Copy absolute path" })
vim.keymap.set("n", "<your-key>", "<cmd>CopyFilePathRel<cr>", { desc = "Copy relative path" })You can also call the functions directly from Lua:
local copy_filepath = require("copy-filepath")
-- Copy absolute path
copy_filepath.copy_absolute_path()
-- Copy relative path
copy_filepath.copy_relative_path()
-- Setup function (for future configuration options)
copy_filepath.setup({
-- Currently no options, but reserved for future extensibility
})- Neovim 0.7.0 or later
- System clipboard support (
+clipboardfeature)
Check clipboard support with:
:echo has('clipboard')MIT License - see LICENSE file for details