### mini.deps Example for Neo-tree.nvim Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/README.md Installation configuration for Neo-tree.nvim using mini.deps. Specifies source, checkout branch, and dependencies. ```lua local add = MiniDeps.add add({ source = 'nvim-neo-tree/neo-tree.nvim', checkout = 'v3.x', depends = { "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim", "nvim-tree/nvim-web-devicons", -- optional, but recommended } }) ``` -------------------------------- ### lazy.nvim Example for Neo-tree.nvim Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/README.md Basic lazy.nvim configuration for installing Neo-tree.nvim. Ensure plenary.nvim and nui.nvim are also installed. ```lua return { { "nvim-neo-tree/neo-tree.nvim", branch = "v3.x", dependencies = { "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim", "nvim-tree/nvim-web-devicons", -- optional, but recommended }, lazy = false, -- neo-tree will lazily load itself } } ``` -------------------------------- ### Basic Neo-tree Setup Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/README.md Use this basic setup function to initialize neo-tree.nvim with default options. No specific imports are needed beyond the require statement. ```lua require('neo-tree').setup({ -- options go here }) ``` -------------------------------- ### Packer.nvim Example for Neo-tree.nvim Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/README.md Configuration for installing Neo-tree.nvim using Packer.nvim. Requires plenary.nvim, nui.nvim, and optionally nvim-web-devicons. ```lua use({ "nvim-neo-tree/neo-tree.nvim", branch = "v3.x", requires = { "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim", "nvim-tree/nvim-web-devicons", -- optional, but recommended } }) ``` -------------------------------- ### Install Neo-tree with vim.pack Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/README.md Example of installing Neo-tree.nvim and its dependencies using vim.pack. Ensure Neovim 0.12 or later is used. This snippet includes core dependencies and recommended optional ones. ```lua vim.pack.add({ { src = 'https://github.com/nvim-neo-tree/neo-tree.nvim', version = vim.version.range('3') }, -- dependencies "https://github.com/nvim-lua/plenary.nvim", "https://github.com/MunifTanjim/nui.nvim", -- optional, but recommended "https://github.com/nvim-tree/nvim-web-devicons", }) ``` -------------------------------- ### Install Neo-tree.nvim with lazy.nvim Source: https://context7.com/nvim-neo-tree/neo-tree.nvim/llms.txt Recommended installation method using lazy.nvim. Ensure to include necessary dependencies like plenary.nvim and nui.nvim. Keep `lazy = false` for neo-tree to load correctly. ```lua -- lazy.nvim return { "nvim-neo-tree/neo-tree.nvim", branch = "v3.x", dependencies = { "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim", "nvim-tree/nvim-web-devicons", -- optional, recommended for icons }, lazy = false, -- neo-tree lazily loads itself; keep this false } ``` -------------------------------- ### lazy.nvim Example with Optional Plugins Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/README.md Advanced lazy.nvim configuration including Neo-tree.nvim, lsp-file-operations, and nvim-window-picker. Setup for window-picker is included. ```lua return { { "nvim-neo-tree/neo-tree.nvim", branch = "v3.x", dependencies = { "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim", "nvim-tree/nvim-web-devicons", }, }, { "antosha417/nvim-lsp-file-operations", dependencies = { "nvim-lua/plenary.nvim", "nvim-neo-tree/neo-tree.nvim", -- makes sure that this loads after Neo-tree. }, config = function() require("lsp-file-operations").setup() end, }, { "s1n7ax/nvim-window-picker", version = "2.*", config = function() require("window-picker").setup({ filter_rules = { include_current_win = false, autoselect_one = true, -- filter using buffer options bo = { -- if the file type is one of following, the window will be ignored filetype = { "neo-tree", "neo-tree-popup", "notify" }, -- if the buffer type is one of following, the window will be ignored buftype = { "terminal", "quickfix" }, }, }, }) end, }, } ``` -------------------------------- ### Advanced Neo-tree Configuration Example Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/README.md An extensive example showcasing various configuration options for neo-tree.nvim, including file tree appearance, git status integration, and custom sorting. ```lua vim.keymap.set("n", "e", "Neotree") require("neo-tree").setup({ close_if_last_window = false, -- Close Neo-tree if it is the last window left in the tab popup_border_style = "NC", -- or "" to use 'winborder' on Neovim v0.11+ clipboard = { sync = "none", -- or "global"/"universal" to share a clipboard for each/all Neovim instance(s), respectively }, enable_git_status = true, enable_diagnostics = true, open_files_do_not_replace_types = { "terminal", "trouble", "qf" }, -- when opening files, do not use windows containing these filetypes or buftypes open_files_using_relative_paths = false, sort_case_insensitive = false, -- used when sorting files and directories in the tree sort_function = nil, -- use a custom function for sorting files and directories in the tree -- sort_function = function (a,b) -- if a.type == b.type then -- return a.path > b.path -- else -- return a.type > b.type -- end -- end , -- this sorts files and directories descendantly default_component_configs = { container = { enable_character_fade = true, }, indent = { indent_size = 2, padding = 1, -- extra padding on left hand side -- indent guides with_markers = true, indent_marker = "│", last_indent_marker = "└", highlight = "NeoTreeIndentMarker", -- expander config, needed for nesting files with_expanders = nil, -- if nil and file nesting is enabled, will enable expanders expander_collapsed = "", expander_expanded = "", expander_highlight = "NeoTreeExpander", }, icon = { folder_closed = "", folder_open = "", folder_empty = "󰜌", provider = function(icon, node, state) -- default icon provider utilizes nvim-web-devicons if available if node.type == "file" or node.type == "terminal" then local success, web_devicons = pcall(require, "nvim-web-devicons") local name = node.type == "terminal" and "terminal" or node.name if success then local devicon, hl = web_devicons.get_icon(name) icon.text = devicon or icon.text icon.highlight = hl or icon.highlight end end end, -- The next two settings are only a fallback, if you use nvim-web-devicons and configure default icons there -- then these will never be used. default = "*", highlight = "NeoTreeFileIcon", use_filtered_colors = true, -- Whether to use a different highlight when the file is filtered (hidden, dotfile, etc.). }, modified = { symbol = "[+]", highlight = "NeoTreeModified", }, name = { trailing_slash = false, use_filtered_colors = true, -- Whether to use a different highlight when the file is filtered (hidden, dotfile, etc.). use_git_status_colors = true, highlight = "NeoTreeFileName", }, git_status = { symbols = { -- Change type added = "", -- or "✚" modified = "", -- or "" deleted = "✖", -- this can only be used in the git_status source renamed = "󰁕", -- this can only be used in the git_status source -- Status type untracked = "", ignored = "", unstaged = "󰄱", staged = "", conflict = "", }, }, -- If you don't want to use these columns, you can set `enabled = false` for each of them individually file_size = { enabled = true, width = 12, -- width of the column required_width = 64, -- min width of window required to show this column }, type = { enabled = true, width = 10, -- width of the column required_width = 122, -- min width of window required to show this column }, last_modified = { enabled = true, width = 20, -- width of the column required_width = 88, -- min width of window required to show this column }, created = { enabled = true, }, } }) ``` -------------------------------- ### Lazy.nvim Integration for Neo-tree Setup Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/README.md Configure neo-tree.nvim using lazy.nvim's `opts` table for a more declarative setup. Ensure all necessary dependencies are listed. ```lua return { "nvim-neo-tree/neo-tree.nvim", branch = "v3.x", dependencies = { "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim", "nvim-tree/nvim-web-devicons", -- optional, but recommended }, lazy = false, -- neo-tree will lazily load itself --@module 'neo-tree' --@type neotree.Config opts = { -- options go here } } ``` -------------------------------- ### Lua Setup for Custom Components Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt The basic structure for setting up neo-tree with custom components. ```lua require("neo-tree").setup({ ``` -------------------------------- ### Fuzzy Sorter Configuration Example Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Example of configuring the fuzzy sorter with a custom function, allowed servers, and ignored servers. The function takes precedence. ```lua { fn = function(name) return name ~= "null-ls" end, allow_only = { "clangd", "lua_ls" }, ignore = { "pyright" }, } ``` -------------------------------- ### Open Filesystem Browser with Key-Value Arguments Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/README.md Opens a file browser using explicit key=value arguments for clarity. This achieves the same result as the previous example but is more verbose. ```vim :Neotree source=filesystem reveal=true position=right ``` -------------------------------- ### Configure Neo-tree.nvim with setup() Source: https://context7.com/nvim-neo-tree/neo-tree.nvim/llms.txt Configure Neo-tree.nvim by calling `require('neo-tree').setup(config)`. This merges your configuration with defaults. Customize options like `close_if_last_window`, `clipboard`, `enable_git_status`, `enable_diagnostics`, and component configurations. ```lua require("neo-tree").setup({ -- Close the tree if it is the only window left in the tab close_if_last_window = false, -- Share clipboard across all Neovim instances ("none" | "global" | "universal") clipboard = { sync = "none" }, -- Show git status icons and LSP diagnostics in the tree enable_git_status = true, enable_diagnostics = true, -- Do not replace terminal / quickfix windows when opening a file open_files_do_not_replace_types = { "terminal", "Trouble", "qf", "edgy" }, -- Source selector tabs on the winbar (requires Neovim 0.8+) source_selector = { winbar = true, statusline = false, }, -- Global default components rendered for every file node default_component_configs = { indent = { indent_size = 2, with_markers = true, indent_marker = "│", last_indent_marker = "└", }, icon = { folder_closed = "", folder_open = "", folder_empty = "󰉖", default = "*", }, git_status = { symbols = { added = "✚", modified = "", deleted = "✖", renamed = "󰁕", untracked = "", ignored = "", unstaged = "󰄱", staged = "", conflict = "", }, }, }, -- Global key mappings available in all sources window = { position = "left", width = 40, mappings = { [""] = { "toggle_node", nowait = false }, [""] = "open", ["S"] = "open_split", ["s"] = "open_vsplit", ["t"] = "open_tabnew", ["P"] = { "toggle_preview", config = { use_float = true } }, ["z"] = "close_all_nodes", ["R"] = "refresh", ["a"] = { "add", config = { show_path = "none" } }, ["d"] = "delete", ["r"] = "rename", ["y"] = "copy_to_clipboard", ["x"] = "cut_to_clipboard", ["p"] = "paste_from_clipboard", ["q"] = "close_window", ["?"] = "show_help", }, }, }) ``` -------------------------------- ### Lazy Loading Neo-tree with Dependencies Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Example of how to configure neo-tree.nvim using lazy.nvim, including essential dependencies and optional image support. ```lua -- if using lazy.nvim: { "nvim-neo-tree/neo-tree.nvim", dependencies = { "nvim-lua/plenary.nvim", "nvim-tree/nvim-web-devicons", "MunifTanjim/nui.nvim", -- { "3rd/image.nvim", opts = {} }, -- Optional image support }, lazy = false, -- neo-tree lazy-loads itself ---@module "neo-tree" ---@type neotree.Config? -- opts = { -- -- fill any relevant options here -- }, } ``` -------------------------------- ### Neo-tree.nvim Commands Mapping Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Example mapping of keys to neo-tree.nvim commands. These are common commands for navigation and file operations. ```lua ["o"] = "jump_to_symbol", ["r"] = "rename", ["P"] = "preview", (and related commands) ["s"] = "split", (and related commands) ``` -------------------------------- ### Lua Container Example Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt An example of a Lua container component that aligns name, diagnostics, and git status to the right. ```lua { "container", width = "100%", right_padding = 1, content = { { "name", use_git_status_colors = true, zindex = 10 }, { "diagnostics", zindex = 20, align = "right" }, { "git_status", zindex = 20, align = "right" }, }, } ``` -------------------------------- ### Global Mapping for Toggling Neo-tree with Buffer Source Source: https://github.com/nvim-neo-tree/neo-tree.nvim/wiki/Recipes Set up a global key mapping to toggle the neo-tree with the 'buffers' source and position it on the left. This example is tailored for LazyVim configurations. ```lua keys = { { "r", function() require("neo-tree.command").execute({ toggle = true, source = "buffers", position = "left", }) end, desc = "Buffers (root dir)", }, } ``` -------------------------------- ### Configure Event Handlers Source: https://context7.com/nvim-neo-tree/neo-tree.nvim/llms.txt Set up custom event handlers for Neo-tree.nvim lifecycle events within the setup configuration. Handlers receive an 'args' table specific to each event. ```lua require("neo-tree").setup({ event_handlers = { -- Auto-close tree when a file is opened { event = "file_open_requested", handler = function() require("neo-tree.command").execute({ action = "close" }) end, }, -- Equalize window widths when the sidebar opens / closes { event = "neo_tree_window_after_open", handler = function(args) if args.position == "left" or args.position == "right" then vim.cmd("wincmd =") end end, }, { event = "neo_tree_window_after_close", handler = function(args) if args.position == "left" or args.position == "right" then vim.cmd("wincmd =") end end, }, -- React to file rename (e.g. update LSP references) { event = "file_renamed", handler = function(args) print(args.source, "renamed to", args.destination) -- call LSP workspace/willRenameFiles here if needed end, }, -- Hide cursor while inside Neo-tree window { event = "neo_tree_buffer_enter", handler = function() vim.cmd("highlight! Cursor blend=100") end, }, { event = "neo_tree_buffer_leave", handler = function() vim.cmd("highlight! Cursor guibg=#5f87af blend=0") end, }, -- Custom file-open logic: always open in the prior window { event = "file_open_requested", handler = function(args) local prior = require("neo-tree").get_prior_window() if prior > 0 then pcall(vim.api.nvim_set_current_win, prior) vim.cmd((args.open_cmd or "edit") .. " " .. args.path) return { handled = true } end return { handled = false } end, }, }, }) ``` -------------------------------- ### Define Neo-tree Mappings Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Example mappings for common neo-tree actions like toggling, revealing, and opening in a split or float. ```vim nnoremap / :Neotree toggle current reveal_force_cwd nnoremap | :Neotree reveal nnoremap gd :Neotree float reveal_file= reveal_force_cwd nnoremap b :Neotree toggle show buffers right nnoremap s :Neotree float git_status ``` -------------------------------- ### Map Keys to Switch Neo-tree Views Source: https://github.com/nvim-neo-tree/neo-tree.nvim/wiki/Recipes Configure key mappings to easily switch between filesystem, buffers, and git_status views in neo-tree. This setup is useful for quickly navigating different project contexts. ```lua require('neo-tree').setup({ window = { mappings = { ['e'] = function() vim.api.nvim_exec('Neotree focus filesystem left', true) end, ['b'] = function() vim.api.nvim_exec('Neotree focus buffers left', true) end, ['g'] = function() vim.api.nvim_exec('Neotree focus git_status left', true) end, }, }, }) ``` -------------------------------- ### Configure File Name Component in Neo-tree Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Example of setting up a custom 'name' component for the file system in neo-tree. This configuration allows for dynamic highlighting based on node type, depth, and git status. ```lua require("neo-tree").setup({ filesystem = { components = { name = function(config, node, state) local highlight = config.highlight or highlights.FILE_NAME if node.type == "directory" then highlight = highlights.DIRECTORY_NAME end if node:get_depth() == 1 then highlight = highlights.ROOT_NAME else if config.use_git_status_colors == nil or config.use_git_status_colors then local git_status = state.components.git_status({}, node, state) if git_status and git_status.highlight then highlight = git_status.highlight end end end return { text = node.name, highlight = highlight, } end } } }) ``` -------------------------------- ### Install/Update Dependencies with Mise Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/CONTRIBUTING.md Use this command to install or update project dependencies managed by Mise. ```bash mise deps # Or `mise update-dependencies` ``` -------------------------------- ### Lua Component Example Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt A basic Lua component returning a single text object with a highlight group. ```lua { text = "Node A", highlight = "Normal" } ``` -------------------------------- ### Enable Basic File Nesting Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Configure nesting rules by file extension to enable nested file display. This example shows how to nest '.js.map' files under '.js' files. ```lua require("neo-tree").setup({ nesting_rules = { ["js"] = { "js.map" }, } }) ``` -------------------------------- ### Setup Event Handler for File Open Source: https://context7.com/nvim-neo-tree/neo-tree.nvim/llms.txt Configures neo-tree to use a custom handler for the 'file_open_requested' event. This handler attempts to reopen the file in the most recently used non-Neo-tree window within the current tab, ignoring terminal and quickfix windows. ```lua require("neo-tree").setup({ event_handlers = { { event = "file_open_requested", handler = function(args) local nt = require("neo-tree") -- Ignore terminal and quickfix when looking for prior window local prior = nt.get_prior_window({ "terminal", "qf" }) if prior > 0 then vim.api.nvim_set_current_win(prior) vim.cmd((args.open_cmd or "edit") .. " " .. args.path) return { handled = true } end return { handled = false } end, }, }, }) ``` -------------------------------- ### Integrate Telescope Find/Grep with Neo-tree Source: https://github.com/nvim-neo-tree/neo-tree.nvim/wiki/Recipes Configure neo-tree to use Telescope for finding files or live grepping within the current node's directory. This requires Telescope to be installed. ```lua local function getTelescopeOpts(state, path) return { cwd = path, search_dirs = { path }, attach_mappings = function (prompt_bufnr, map) local actions = require "telescope.actions" actions.select_default:replace(function() actions.close(prompt_bufnr) local action_state = require "telescope.actions.state" local selection = action_state.get_selected_entry() local filename = selection.filename if (filename == nil) then filename = selection[1] end -- any way to open the file without triggering auto-close event of neo-tree? require("neo-tree.sources.filesystem").navigate(state, state.path, filename) end) return true end } end require("neo-tree").setup({ filesystem = { window = { mappings = { ["tf"] = "telescope_find", ["tg"] = "telescope_grep", }, }, }, commands = { telescope_find = function(state) local node = state.tree:get_node() local path = node:get_id() require('telescope.builtin').find_files(getTelescopeOpts(state, path)) end, telescope_grep = function(state) local node = state.tree:get_node() local path = node:get_id() require('telescope.builtin').live_grep(getTelescopeOpts(state, path)) end, }, }) ``` -------------------------------- ### Custom Clipboard Backend Implementation for Neo-tree Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Example of defining a custom clipboard backend for neo-tree. This allows for custom logic to save and load clipboard states, potentially persisting them or integrating with external systems. ```lua --[[@class your.neotree.clipboard.Backend : neotree.clipboard.Backend]] local Backend = {} --[[A backend saves and loads clipboards to and from states. Returns nil if the backend couldn't be created properly. @return your.neotree.clipboard.Backend?]] function Backend:new() local backend = {} setmetatable(backend, self) self.__index = self -- if not do_setup() then -- return nil -- will default to no sync/backend -- end return backend end -- local function applicable(state) -- return state.name ~= "document_symbols" -- end --[[Saves a state's clipboard to the backend. Automatically called whenever a user changes a state's clipboard. Returns nil when the save is not applicable. @param state neotree.State @return boolean? success_or_noop]] function Backend:save(state) -- if not applicable(state) then -- return nil -- nothing happens -- end -- local saved, err = save_clipboard_to_somewhere(state) -- if not saved then -- return false, err -- will error -- end -- on true, neo-tree will try Backend:load with all other states -- return true end ``` -------------------------------- ### Integrate Neo-tree with Telescope for File Search Source: https://context7.com/nvim-neo-tree/neo-tree.nvim/llms.txt Configures neo-tree to use Telescope's `find_files` and `live_grep` commands, scoped to the directory under the cursor. This setup allows opening Telescope searches directly from Neo-tree using custom key mappings. ```lua local function telescope_opts(state, path) return { cwd = path, search_dirs = { path }, attach_mappings = function(prompt_bufnr) local actions = require("telescope.actions") local action_state = require("telescope.actions.state") actions.select_default:replace(function() actions.close(prompt_bufnr) local sel = action_state.get_selected_entry() local filename = sel.filename or sel[1] require("neo-tree.sources.filesystem").navigate(state, state.path, filename) end) return true end, } end require("neo-tree").setup({ filesystem = { window = { mappings = { ["tf"] = "telescope_find", ["tg"] = "telescope_grep", }, }, }, commands = { telescope_find = function(state) local path = state.tree:get_node():get_id() require("telescope.builtin").find_files(telescope_opts(state, path)) end, telescope_grep = function(state) local path = state.tree:get_node():get_id() require("telescope.builtin").live_grep(telescope_opts(state, path)) end, }, }) ``` -------------------------------- ### Lua File Open Request Handling Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Example of handling the `file_open_requested` event. This allows you to intercept file open operations and decide whether Neo-tree should handle them or pass them to the default Neovim behavior. ```lua return { handled = true } ``` -------------------------------- ### Configure Custom Neo-tree Mappings Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Define custom mappings for Neo-tree, overriding global mappings at the source level. This example shows how to map 'A' to different commands for general sources and the filesystem source. ```lua require("neo-tree").setup({ window = { mappings = { ["A"] = "command_a", ["i"] = { function(state) local node = state.tree:get_node() print(node.path) end, desc = "print path", }, } }, filesystem = { window = { mappings = { ["A"] = "command_b" } } } }) ``` -------------------------------- ### Configure Neo-tree Filesystem Window Mappings Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Sets up custom key mappings for the filesystem window in neo-tree, overriding or adding new actions. ```lua require("neo-tree").setup({ filesystem = { window = { mappings = { [""] = "refresh", ["o"] = "open", } } } }) ``` -------------------------------- ### Configure Neo-tree Preview Mode Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Set up preview mode mappings, including options for using floating windows, images, and scrolling. This configuration applies to all sources. ```lua require("neo-tree").setup({ window = { mappings = { ["P"] = { "toggle_preview", config = { use_float = false, use_snacks_image = true, use_image_nvim = true } }, ["l"] = "focus_preview", [""] = { "scroll_preview", config = {direction = 10} }, [""] = { "scroll_preview", config = {direction = -10} }, } } }) ``` -------------------------------- ### Paste Default Configuration Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/README.md Use this command to paste the default configuration into your Neovim buffer after installing Neo-tree. ```vim :lua require("neo-tree").paste_default_config() ``` -------------------------------- ### Define Built-in Delete Commands Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Example of how the built-in `delete` and `delete_visual` commands are defined using Lua functions. ```lua M.delete = function(state, callback) local tree = state.tree local node = tree:get_node() fs_actions.delete_node(node.path, callback) end M.delete_visual = function(state, selected_nodes, callback) local paths_to_delete = {} for _, node_to_delete in pairs(selected_nodes) do table.insert(paths_to_delete, node_to_delete.path) end fs_actions.delete_nodes(paths_to_delete, callback) end ``` -------------------------------- ### Configure Neo-tree Preview Mode Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/README.md Configure the preview mode mapping to use a floating window or an existing split. Files will be previewed without switching focus from the Neo-tree window. ```lua require("neo-tree").setup({ window = { mappings = { ["P"] = { "toggle_preview", config = { use_float = false, -- use_image_nvim = true, -- use_snacks_image = true, -- title = 'Neo-tree Preview', }, }, } } }) ``` -------------------------------- ### Open Files/Directories with System Viewer Source: https://github.com/nvim-neo-tree/neo-tree.nvim/wiki/Recipes Configure a mapping to open the selected file or directory using the operating system's default viewer. This recipe includes platform-specific commands for macOS, Linux, and Windows. ```lua require("neo-tree").setup({ filesystem = { window = { mappings = { ["o"] = "system_open", }, }, }, commands = { system_open = function(state) local node = state.tree:get_node() local path = node:get_id() -- macOs: open file in default application in the background. vim.fn.jobstart({ "open", path }, { detach = true }) -- Linux: open file in default application vim.fn.jobstart({ "xdg-open", path }, { detach = true }) -- Windows: Without removing the file from the path, it opens in code.exe instead of explorer.exe local p local lastSlashIndex = path:match("^.+()\\[^\\]*$") -- Match the last slash and everything before it if lastSlashIndex then p = path:sub(1, lastSlashIndex - 1) -- Extract substring before the last slash else p = path -- If no slash found, return original path end vim.cmd("silent !start explorer " .. p) end, }, }) ``` -------------------------------- ### Open Directory with Neo-tree Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/README.md Use these commands to open a directory and have neo-tree hijack the behavior, opening it in the current window. ```vimscript :edit . ``` ```vimscript :[v]split . ``` -------------------------------- ### Define a Custom Neo-tree Event Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Define custom events with setup, seed, and teardown functions. Options for debouncing, firing once, and cancellation are available. ```lua require("neo-tree.events").define_event(event_name, { setup = , seed = , teardown = , debounce_frequency = , once = , cancelled = }) ``` -------------------------------- ### Lua Event Handler Configuration Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Example of how to configure event handlers in Neo-tree.nvim. This structure allows you to hook into various events emitted by the plugin to customize its behavior. ```lua { event = "event_name", handler = function(arg) -- do something, the value of arg varies by event. end, id = "optional unique id, only meaningful if you want to unsubscribe later" } ``` -------------------------------- ### Open Default Neotree Window Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/README.md Opens the Neotree window with default settings, typically showing the filesystem source on the left and focusing it. Use this when no specific configuration is needed. ```vim :Neotree ``` -------------------------------- ### Open Neotree with Absolute Directory Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/README.md Opens Neotree with an absolute path as the root directory. This ensures Neotree starts in a specific location regardless of the current working directory. ```vim :Neotree /home/user/relative/path ``` -------------------------------- ### Run Project Tests Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/CONTRIBUTING.md Execute this command to run the project's test suite. ```bash mise test ``` -------------------------------- ### Integrate Harpoon Index Display Source: https://github.com/nvim-neo-tree/neo-tree.nvim/wiki/Recipes Add a custom component to display the index number of files marked with the Harpoon plugin. This example shows one method of retrieving the index. ```lua require("neo-tree").setup({ filesystem = { components = { harpoon_index = function(config, node, _) local harpoon_list = require("harpoon"):list() local path = node:get_id() local harpoon_key = vim.uv.cwd() for i, item in ipairs(harpoon_list.items) do local value = item.value if string.sub(item.value, 1, 1) ~= "/" then value = harpoon_key .. "/" .. item.value end if value == path then vim.print(path) return { text = string.format(" ⥤ %d", i), -- <-- Add your favorite harpoon like arrow here highlight = config.highlight or "NeoTreeDirectoryIcon", } end end return {} end, }, renderers = { file = { { "icon" }, { "name", use_git_status_colors = true }, { "harpoon_index" }, --> This is what actually adds the component in where you want it { "diagnostics" }, { "git_status", highlight = "NeoTreeDimText" }, }, }, }, }) ``` -------------------------------- ### Configure Neo-tree Clipboard Backend Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Set a custom backend for clipboard synchronization in Neo-tree. This allows for custom logic when loading clipboards. ```lua function Backend:load(state) -- if not applicable(state) then -- return nil -- nothing happens -- end -- local clipboard, err = load_clipboard_from_somewhere(state) -- if err then -- -- don't modify the clipboard and log an error -- return nil, err -- end -- change the clipboard to the saved clipboard -- return clipboard end return Backend require("neo-tree").setup({ clipboard = { sync = Backend } }) ``` -------------------------------- ### Configure Diagnostic Symbols and Highlights in Neo-tree Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Specify custom symbols and highlight groups for diagnostics directly within the Neo-tree setup call. Settings not provided here will fallback to the `sign_define` method. ```lua require("neo-tree").setup({ default_component_configs = { diagnostics = { symbols = { hint = "H", info = "I", warn = "!", error = "X", }, highlights = { hint = "DiagnosticSignHint", info = "DiagnosticSignInfo", warn = "DiagnosticSignWarn", error = "DiagnosticSignError", }, }, } }) ``` -------------------------------- ### Navigation with HJKL Keys (Lua) Source: https://github.com/nvim-neo-tree/neo-tree.nvim/wiki/Tips Implement HJKL keybindings for navigating within the neo-tree sidebar. 'h' moves to the parent directory or collapses the current directory, while 'l' expands a directory or moves to the first child. ```lua ["h"] = function(state) local node = state.tree:get_node() if node.type == 'directory' and node:is_expanded() then require'neo-tree.sources.filesystem'.toggle_directory(state, node) else require'neo-tree.ui.renderer'.focus_node(state, node:get_parent_id()) end end, ``` ```lua ["l"] = function(state) local node = state.tree:get_node() if node.type == 'directory' then if not node:is_expanded() then require'neo-tree.sources.filesystem'.toggle_directory(state, node) elseif node:has_children() then require'neo-tree.ui.renderer'.focus_node(state, node:get_child_ids()[1]) end end end, ``` -------------------------------- ### Configure Git Status Symbols Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Customize the symbols used to display Git status for files. Ensure a nerd font is installed for default symbols. Symbols can be disabled by setting them to an empty string. ```lua require("neo-tree").setup({ default_component_configs = { git_status = { symbols = { -- Change type added = "✚", deleted = "✖", modified = "", renamed = "󰁕", -- Status type untracked = "", ignored = "", unstaged = "󰄱", staged = "", conflict = "", } } } }) ``` -------------------------------- ### Configure Folder Expansion/Collapse Mappings Source: https://github.com/nvim-neo-tree/neo-tree.nvim/wiki/Recipes Sets up custom key mappings for controlling folder expansion and collapse behavior in neo-tree.nvim's file system window. These mappings allow for granular control over the tree's depth. ```lua neotree.setup { filesystem = { window = { mappings = { ["z"] = "none", ["zo"] = neotree_zo, ["zO"] = neotree_zO, ["zc"] = neotree_zc, ["zC"] = neotree_zC, ["za"] = neotree_za, ["zA"] = neotree_zA, ["zx"] = neotree_zx, ["zX"] = neotree_zX, ["zm"] = neotree_zm, ["zM"] = neotree_zM, ["zr"] = neotree_zr, ["zR"] = neotree_zR, }, }, }, } ``` -------------------------------- ### Configure Buffers Source in Neo-tree Source: https://context7.com/nvim-neo-tree/neo-tree.nvim/llms.txt Set up the buffers source to display open Neovim buffers, optionally including unloaded session buffers. Configure grouping of empty directories, buffer order, and window-specific mappings for buffer actions. ```lua require("neo-tree").setup({ buffers = { follow_current_file = { enabled = true }, group_empty_dirs = true, show_unloaded = true, -- show session-restored but unfocused buffers terminals_first = false, -- list terminals above file buffers when true window = { mappings = { ["d"] = "buffer_delete", ["bd"] = "buffer_delete", [""] = "navigate_up", ["."] = "set_root", }, }, }, }) ``` -------------------------------- ### Configure Filesystem Source in Neo-tree Source: https://context7.com/nvim-neo-tree/neo-tree.nvim/llms.txt Customize the filesystem browser source with options for following the current file, using OS-level watchers, hijacking netrw, binding to cwd, and filtering items. Define window-specific key mappings for navigation and actions. ```lua require("neo-tree").setup({ filesystem = { -- Automatically follow the current buffer in the tree follow_current_file = { enabled = true, leave_dirs_open = false, }, -- OS-level inotify/FSEvents watcher (recommended for large repos) use_libuv_file_watcher = true, -- Replace netrw: opening a directory opens neo-tree in window.position hijack_netrw_behavior = "open_default", -- "open_current" opens like netrw (inside current window) -- "disabled" leaves netrw alone -- Bind neo-tree root to vim's cwd (two-way sync) bind_to_cwd = true, -- Items to hide (and optional "show differently" mode) filtered_items = { visible = false, -- true = show hidden items in a dimmed highlight hide_dotfiles = true, hide_gitignored = true, hide_by_name = { ".DS_Store", "thumbs.db" }, always_show = { ".env" }, -- never hidden even if a rule would hide it never_show_by_pattern = { ".null-ls_*" }, }, -- Filesystem window-specific mappings window = { mappings = { ["H"] = "toggle_hidden", ["/"] = "fuzzy_finder", ["D"] = "fuzzy_finder_directory", ["f"] = "filter_on_submit", [""] = "navigate_up", ["."] = "set_root", ["[g"] = "prev_git_modified", ["]g"] = "next_git_modified", ["i"] = "show_file_details", }, }, }, }) ``` -------------------------------- ### Neo-tree Command with Key-Value Arguments Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Demonstrates the :Neotree command using key-value pairs for arguments, offering an alternative to positional arguments. ```vim :Neotree action=show source=buffers position=right toggle=true ``` -------------------------------- ### Configure Indent Markers per Renderer in Neo-tree Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Customize indent markers for specific renderers (e.g., directory, file) within Neo-tree. This allows for granular control over indent guide appearance. ```lua require("neo-tree").setup({ filesystem = { renderers = { directory = { { "indent", with_markers = true, indent_marker = "│", last_indent_marker = "└", indent_size = 2, }, -- other components }, file = { { "indent", with_markers = true, indent_marker = "│", last_indent_marker = "└", indent_size = 2, }, -- other components } } } }) ``` -------------------------------- ### Configure Working Directory Binding Source: https://github.com/nvim-neo-tree/neo-tree.nvim/blob/main/doc/neo-tree.txt Set up a two-way binding between Neo-tree's root and nvim's current working directory. Choose targets like 'tab', 'window', 'global', or 'none' for different binding behaviors. ```lua require("neo-tree").setup({ filesystem = { bind_to_cwd = true, -- true creates a 2-way binding between vim's cwd and neo-tree's root cwd_target = { sidebar = "tab", -- sidebar is when position = left or right current = "window" -- current is when position = current }, } }) ``` -------------------------------- ### Customize Neo-tree Highlight Groups Source: https://context7.com/nvim-neo-tree/neo-tree.nvim/llms.txt Provides examples for customizing Neo-tree's visual appearance by linking to existing highlight groups (e.g., for nvim-tree compatibility) or by directly overriding colours for various elements. ```lua -- Link neo-tree to nvim-tree highlight groups (for themes that support nvim-tree) vim.cmd([[ highlight! link NeoTreeDirectoryIcon NvimTreeFolderIcon highlight! link NeoTreeDirectoryName NvimTreeFolderName highlight! link NeoTreeRootName NvimTreeRootFolder highlight! link NeoTreeSymbolicLinkTarget NvimTreeSymlink ]]) -- Direct colour overrides vim.api.nvim_set_hl(0, "NeoTreeNormal", { bg = "#1e1e2e" }) vim.api.nvim_set_hl(0, "NeoTreeNormalNC", { bg = "#1e1e2e" }) vim.api.nvim_set_hl(0, "NeoTreeFileName", { fg = "#cdd6f4" }) vim.api.nvim_set_hl(0, "NeoTreeGitAdded", { fg = "#a6e3a1" }) vim.api.nvim_set_hl(0, "NeoTreeGitModified", { fg = "#fab387" }) vim.api.nvim_set_hl(0, "NeoTreeGitConflict", { fg = "#f38ba8", bold = true }) vim.api.nvim_set_hl(0, "NeoTreeIndentMarker", { fg = "#45475a" }) vim.api.nvim_set_hl(0, "NeoTreeTabActive", { fg = "#cdd6f4", bg = "#313244" }) vim.api.nvim_set_hl(0, "NeoTreeTabInactive", { fg = "#6c7086", bg = "#1e1e2e" }) ```