Skip to content

ywpkwon/yank-path.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧩 yank-path.nvim

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

✨ Features

  • 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 :YankPath command (and more non-UI direct commands)
  • No dependencies, tiny, pure Lua

πŸ“¦ Installation

lazy.nvim

{
  "ywpkwon/yank-path.nvim",
  config = function()
    require("yank-path").setup()
  end,
}

packer.nvim

use {
  "ywpkwon/yank-path.nvim",
  config = function()
    require("yank-path").setup()
  end,
}

πŸš€ Usage

πŸ”Ή 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

🎹 Example Keymaps (optional)

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" })

🧭 Tip: Works Great with Oil.nvim

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.

πŸ”§ Configuration

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

prompt

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
})
prompt-copy prompt-empty

default_mapping

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" })

use_oil β€” Built-in Oil.nvim support

Oil.nvim works automatically. For some reasons, to disable the integration:

require("yank-path").setup({
  use_oil = false,
})

register_provider() β€” Custom file explorer integrations

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:

  1. Built-in Oil provider (if use_oil = true)
  2. User-registered providers
  3. Fallback: current buffer path

πŸ™ Acknowledgements

This plugin was inspired by great ideas from the following projects:

  • neo-tree.nvim
    The Y yank-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.

πŸ“ Note from the Author

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!

🀝 Contributing

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

πŸ“œ License

MIT


⭐️ Supporting the Project

If this little plugin made your workflow happier, feel free to ⭐️ the repo β€” it means a lot :)

About

A minimal neovim plugin to help copying the file path (in various formats) to the clipboard.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages