diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 426846d5dce..93a3f6f63b9 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -185,6 +185,7 @@ Show the mappings: `g?` `f` Live Filter: Start |nvim-tree-api.live_filter.start()| `g?` Help |nvim-tree-api.tree.toggle_help()| `gy` Copy Absolute Path |nvim-tree-api.fs.copy.absolute_path()| +`ge` Copy Basename |nvim-tree-api.fs.copy.basename()| `H` Toggle Filter: Dotfiles |nvim-tree-api.tree.toggle_hidden_filter()| `I` Toggle Filter: Git Ignore |nvim-tree-api.tree.toggle_gitignore_filter()| `J` Last Sibling |nvim-tree-api.node.navigate.sibling.last()| @@ -2240,6 +2241,7 @@ You are encouraged to copy these to your own |nvim-tree.on_attach| function. vim.keymap.set('n', 'f', api.live_filter.start, opts('Live Filter: Start')) vim.keymap.set('n', 'g?', api.tree.toggle_help, opts('Help')) vim.keymap.set('n', 'gy', api.fs.copy.absolute_path, opts('Copy Absolute Path')) + vim.keymap.set('n', 'ge', api.fs.copy.basename, opts('Copy Basename')) vim.keymap.set('n', 'H', api.tree.toggle_hidden_filter, opts('Toggle Filter: Dotfiles')) vim.keymap.set('n', 'I', api.tree.toggle_gitignore_filter, opts('Toggle Filter: Git Ignore')) vim.keymap.set('n', 'J', api.node.navigate.sibling.last, opts('Last Sibling')) diff --git a/lua/nvim-tree/actions/fs/copy-paste.lua b/lua/nvim-tree/actions/fs/copy-paste.lua index 87f9bbb545b..efb2b1ef16a 100644 --- a/lua/nvim-tree/actions/fs/copy-paste.lua +++ b/lua/nvim-tree/actions/fs/copy-paste.lua @@ -295,6 +295,12 @@ function M.copy_filename(node) copy_to_clipboard(node.name) end +---@param node Node +function M.copy_basename(node) + local basename = vim.fn.fnamemodify(node.name, ":r") + copy_to_clipboard(basename) +end + ---@param node Node function M.copy_path(node) local absolute_path = node.absolute_path diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index c3f4722c37d..9587b813a87 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -163,6 +163,7 @@ Api.fs.print_clipboard = wrap(actions.fs.copy_paste.print_clipboard) Api.fs.copy.node = wrap_node(actions.fs.copy_paste.copy) Api.fs.copy.absolute_path = wrap_node(actions.fs.copy_paste.copy_absolute_path) Api.fs.copy.filename = wrap_node(actions.fs.copy_paste.copy_filename) +Api.fs.copy.basename = wrap_node(actions.fs.copy_paste.copy_basename) Api.fs.copy.relative_path = wrap_node(actions.fs.copy_paste.copy_path) ---@param mode string diff --git a/lua/nvim-tree/keymap.lua b/lua/nvim-tree/keymap.lua index 0b0797a8dd6..1999c73d262 100644 --- a/lua/nvim-tree/keymap.lua +++ b/lua/nvim-tree/keymap.lua @@ -68,6 +68,7 @@ function M.default_on_attach(bufnr) vim.keymap.set('n', 'f', api.live_filter.start, opts('Live Filter: Start')) vim.keymap.set('n', 'g?', api.tree.toggle_help, opts('Help')) vim.keymap.set('n', 'gy', api.fs.copy.absolute_path, opts('Copy Absolute Path')) + vim.keymap.set('n', 'ge', api.fs.copy.basename, opts('Copy Basename')) vim.keymap.set('n', 'H', api.tree.toggle_hidden_filter, opts('Toggle Filter: Dotfiles')) vim.keymap.set('n', 'I', api.tree.toggle_gitignore_filter, opts('Toggle Filter: Git Ignore')) vim.keymap.set('n', 'J', api.node.navigate.sibling.last, opts('Last Sibling'))