Minimal plugin to copy (yank) different variants of the current file path - inspired by Neo-tree's Y menu, but without needing Neo-tree.
yank-path-demo.mov
This plugin gives you a simple picker (using vim.ui.select, so telescope/dressing/etc. improve it automatically) to copy:
1. BASENAME: tmux-keybindings
2. EXTENSION: conf
3. FILENAME: tmux-keybindings.conf
4. PATH: /home/paulk/dotfiles/tmux/tmux-keybindings.conf
5. PATH (CWD): tmux/tmux-keybindings.conf
6. PATH (HOME): ~/dotfiles/tmux/tmux-keybindings.conf
7. URI: file:///home/paulk/dotfiles/tmux/tmux-keybindings.conf
- Yank basename, extension, filename, fullpath, cwd-relative, home-relative, or URI
- Uses
vim.ui.selectβ works great with:dressing.nvim- Telescope UI select
- fzf-lua / fzy overrides
- Writes to both:
+system clipboard"unnamed register
- Comes with default keymap (
Y) and:YankPathcommand (and more non-UI direct commands) - No dependencies, tiny, pure Lua
{
"ywpkwon/yank-path.nvim",
config = function()
require("yank-path").setup()
end,
}use {
"ywpkwon/yank-path.nvim",
config = function()
require("yank-path").setup()
end,
}πΉ The primary way to use this plugin is through the interactive picker:
- Keymap:
Y(unless disabled, see below) - Command:
:YankPath
This opens a menu (powered by vim.ui.select) where you can choose which path variant to yank.
πΉ Direct, Non-UI Yank Commands
In addition to the picker, the plugin also provides non-interactive commands that immediately yank a specific path variant without showing a menu. These are perfect if you want to create custom keybindings.
| Command | Description |
|---|---|
:YankPath |
UI picker (interactive selection) |
:YankPathBase |
Yank basename (filename without extension) |
:YankPathExtension |
Yank file extension |
:YankPathFilename |
Yank filename (with extension) |
:YankPathFull |
Yank full absolute path |
:YankPathCwd |
Yank path relative to current working dir |
:YankPathHome |
Yank path with $HOME replaced by ~ |
:YankPathUri |
Yank file URI (file://...) |
All commands (or keybindings) work in:
- regular file buffers
- Oil.nvim buffers (if
use_oil = true) - any custom source added via
register_provider()
Click to expand example keymaps
No default keymaps are provided for these direct commands other than the :YankPath (Y).
Here are some example mappings you can add to your own config:
vim.keymap.set("n", "<leader>ypb", "<cmd>YankPathBase<CR>", { desc = "Yank basename" })
vim.keymap.set("n", "<leader>ype", "<cmd>YankPathExtension<CR>", { desc = "Yank extension" })
vim.keymap.set("n", "<leader>ypf", "<cmd>YankPathFilename<CR>", { desc = "Yank filename" })
vim.keymap.set("n", "<leader>ypp", "<cmd>YankPathFull<CR>", { desc = "Yank full path" })
vim.keymap.set("n", "<leader>ypc", "<cmd>YankPathCwd<CR>", { desc = "Yank CWD path" })
vim.keymap.set("n", "<leader>yph", "<cmd>YankPathHome<CR>", { desc = "Yank HOME path" })
vim.keymap.set("n", "<leader>ypu", "<cmd>YankPathUri<CR>", { desc = "Yank file URI" })If youβre inside an Oil.nvim directory view, the yank commands operate on the file under cursor, even if itβs not opened in a buffer.
This makes it very convenient to copy any fileβs path without leaving the explorer.
yank-path.nvim is configured via the setup() function where all fields are optional.
require("yank-path").setup({
prompt = "Yank which path?",
default_mapping = true,
use_oil = true, -- enable built-in Oil.nvim integration
})Click to expand configuration options
Customize the text at the top of the picker window: (for example, "copy" or "")
require("yank-path").setup({
prompt = "copy", -- or "" for a clean look
})
By default, yank-path.nvim binds Y β :YankPath in the Normal mode.
If you prefer a custom keymap (or no keymap at all), you can disable the default mapping:
require("yank-path").setup({
default_mapping = false,
})Then you can define your own:
vim.keymap.set("n", "<leader>yp", "<cmd>YankPath<CR>", { desc = "Yank file path" })Oil.nvim works automatically. For some reasons, to disable the integration:
require("yank-path").setup({
use_oil = false,
})yank-path.nvim supports integration with any file explorer (Snacks, neo-tree, custom UIs) via small user-provided hooks.
require("yank-path").register_provider(function()
local ok, snacks = pcall(require, "snacks")
if not ok then return nil end
-- PSEUDOCODE (depends on Snacks API):
-- local entry = snacks.explorer.get_cursor_entry()
-- if entry and entry.path then
-- return entry.path
-- end
return nil
end)Provider priority:
- Built-in Oil provider (if
use_oil = true) - User-registered providers
- Fallback: current buffer path
This plugin was inspired by great ideas from the following projects:
-
neo-tree.nvim
TheYyank-path popup in Neo-tree motivated this plugin's core behavior. -
oil.nvim
A fantastic filesystem UI for Neovim.
This plugin includes built-in compatibility to yank paths directly from Oil buffers.
Huge thanks to the authors and contributors of these projects for their amazing work.
This plugin started as a small personal tool to replicate the path-yanking behavior I liked from Neo-tree, but without requiring a full file explorer.
I'm still relatively new to Neovim plugin development, so while I may not always be able to expand or maintain the project actively, I'm happy if others find it useful. Suggestions and contributions are always welcome!
Bug reports, improvements, and PRs are welcome!
If you'd like to contribute support for another file explorer, please use
register_provider() (see documentation above).
MIT
If this little plugin made your workflow happier, feel free to βοΈ the repo β it means a lot :)