diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index a70e86dfec1..f085647cff1 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -1608,6 +1608,15 @@ node.open.vertical() *nvim-tree-api.node.open.vertical()* node.open.horizontal() *nvim-tree-api.node.open.horizontal()* |nvim-tree-api.node.edit()|, file will be opened in a new horizontal split. +node.open.drop() *nvim-tree-api.node.open.drop()* + Switch to window with selected file if it exists. + Open file otherwise. + See: `:h :drop`. + + File: open file using `:drop` + Folder: expand or collapse + Root: change directory up + node.open.tab() *nvim-tree-api.node.open.tab()* |nvim-tree-api.node.edit()|, file will be opened in a new tab. diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 6990c89662e..ab9cc1c1853 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -160,6 +160,13 @@ local function open_file_in_tab(filename) vim.cmd("tabe " .. vim.fn.fnameescape(filename)) end +local function drop(filename) + if M.quit_on_open then + view.close() + end + vim.cmd("drop " .. vim.fn.fnameescape(filename)) +end + local function tab_drop(filename) if M.quit_on_open then view.close() @@ -303,6 +310,10 @@ function M.fn(mode, filename) return open_file_in_tab(filename) end + if mode == "drop" then + return drop(filename) + end + if mode == "tab_drop" then return tab_drop(filename) end diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index a4614eee5d0..24b5d1440a5 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -162,6 +162,7 @@ local function open_preview(node) end Api.node.open.edit = wrap_node(open_or_expand_or_dir_up "edit") +Api.node.open.drop = wrap_node(open_or_expand_or_dir_up "drop") Api.node.open.tab_drop = wrap_node(open_or_expand_or_dir_up "tab_drop") Api.node.open.replace_tree_buffer = wrap_node(open_or_expand_or_dir_up "edit_in_place") Api.node.open.no_window_picker = wrap_node(open_or_expand_or_dir_up "edit_no_picker")