---@param root? boolean ---@param grouped? boolean local function make_toggle_mapping(root, grouped) root = root or false grouped = grouped or false local lhs = grouped and 'fe' or 'e' lhs = root and lhs or (lhs:gsub('%l$', string.upper)) return { lhs, function() require('neo-tree.command').execute({ toggle = true, dir = root and (MarleyVim.root()) or (vim.uv.cwd()), }) end, desc = 'explorer (' .. (root and 'root' or 'cwd') .. ')', } end return { 'neo-tree.nvim', cmd = 'Neotree', keys = { make_toggle_mapping(true, true), -- root / grouped make_toggle_mapping(false, true), -- cwd / grouped make_toggle_mapping(true, false), -- root / non-grouped make_toggle_mapping(false, false), -- cwd / non-grouped { 'ge', function() require('neo-tree.command').execute({ source = 'git_status', toggle = true, }) end, desc = 'git explorer', }, { 'be', function() require('neo-tree.command').execute({ source = 'buffers', toggle = true, }) end, desc = 'buffer explorer', }, }, before = function() require('lz.n').trigger_load({ 'plenary.nvim', 'mini.icons', 'nui.nvim', 'which-key.nvim', }) end, after = function() local icons = require('icons') local events = require('neo-tree.events') for _, type in ipairs({ 'Error', 'Warn', 'Info', 'Hint' }) do vim.fn.sign_define( 'DiagnosticSign' .. type, { text = icons.diagnostics[type], texthl = 'DiagnosticSign' .. type } ) end local function on_move(data) Snacks.rename.on_rename_file(data.source, data.destination) end require('neo-tree').setup({ close_if_last_window = true, sources = { 'filesystem', 'buffers', 'git_status' }, open_files_do_not_replace_types = { 'terminal', 'Trouble', 'trouble', 'qf', 'Outline', }, filesystem = { bind_to_cwd = false, follow_current_file = { enabled = true }, use_libuv_file_watcher = true, filtered_items = { visible = true, hide_dotfiles = false, }, }, window = { mappings = { ['l'] = 'open', ['h'] = 'close_node', [''] = 'none', ['Y'] = { function(state) local node = state.tree:get_node() local path = node:get_id() vim.fn.setreg('+', path, 'c') end, desc = 'copy path to clipboard', }, ['P'] = { 'toggle_preview', config = { use_float = false } }, }, }, default_component_configs = { indent = { with_expanders = true, expanders_collapsed = '', expander_expanded = '', expander_highlight = 'NeoTreeExpander', }, git_status = { symbols = { unstaged = icons.git.unstaged, staged = icons.git.staged, }, }, }, event_handlers = { { event = events.FILE_MOVED, handler = on_move }, { event = events.FILE_RENAMED, handler = on_move }, }, }) local colors = require('colors') require('which-key').add({ { 'ge', icon = { icon = '', color = colors.git } }, { 'be', icon = { icon = '', color = colors.buffer } }, }) end, }