return { { "nvim-neo-tree/neo-tree.nvim", branch = "v3.x", dependencies = { "nvim-lua/plenary.nvim", "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended "MunifTanjim/nui.nvim", { "3rd/image.nvim", opts = {} }, -- Optional image support in preview window: See `# Preview Mode` for more information }, lazy = false, -- neo-tree will lazily load itself ---@module "neo-tree" ---@type neotree.Config? opts = { filesystem = { follow_current_file = { enabled = false }, commands = { -- over write default 'delete' command to 'trash'. delete = function(state) if vim.fn.executable("trash") == 0 then vim.api.nvim_echo({ { "- Trash utility not installed. Make sure to install it first\n", nil }, { "- In macOS run `brew install trash`\n", nil }, { "- Or delete the `custom delete command` section in neo-tree", nil }, }, false, {}) return end local inputs = require("neo-tree.ui.inputs") local path = state.tree:get_node().path local msg = "Are you sure you want to trash " .. path inputs.confirm(msg, function(confirmed) if not confirmed then return end vim.fn.system({ "trash", vim.fn.fnameescape(path) }) require("neo-tree.sources.manager").refresh(state.name) end) end, -- Overwrite default 'delete_visual' command to 'trash' x n. delete_visual = function(state, selected_nodes) if vim.fn.executable("trash") == 0 then vim.api.nvim_echo({ { "- Trash utility not installed. Make sure to install it first\n", nil }, { "- In macOS run `brew install trash`\n", nil }, { "- Or delete the `custom delete command` section in neo-tree", nil }, }, false, {}) return end local inputs = require("neo-tree.ui.inputs") -- Function to get the count of items in a table local function GetTableLen(tbl) local len = 0 for _ in pairs(tbl) do len = len + 1 end return len end local count = GetTableLen(selected_nodes) local msg = "Are you sure you want to trash " .. count .. " files?" inputs.confirm(msg, function(confirmed) if not confirmed then return end for _, node in ipairs(selected_nodes) do vim.fn.system({ "trash", vim.fn.fnameescape(node.path) }) end require("neo-tree.sources.manager").refresh(state.name) end) end, }, }, }, keys = { { "e", false }, { "E", false }, { "en", function() local buf_name = vim.api.nvim_buf_get_name(0) -- Function to check if NeoTree is open in any window local function is_neo_tree_open() for _, win in ipairs(vim.api.nvim_list_wins()) do local buf = vim.api.nvim_win_get_buf(win) if vim.bo[buf].filetype == "neo-tree" then return true end end return false end -- Check if the current file exists if vim.fn.filereadable(buf_name) == 1 or vim.fn.isdirectory(vim.fn.fnamemodify(buf_name, ":p:h")) == 1 then if is_neo_tree_open() then -- Close NeoTree if it's open vim.cmd("Neotree close") else -- Open NeoTree and reveal the current file vim.cmd("Neotree reveal") end else -- If the file doesn't exist, execute the logic for R require("neo-tree.command").execute({ toggle = true, dir = vim.uv.cwd() }) end end, desc = "Open neo-tree", }, { "eN", function() require("neo-tree.command").execute({ toggle = true, dir = vim.uv.cwd() }) end, desc = "Open neo-tree (cwd)", }, }, }, }