diff --git a/nix/neovim-overlay.nix b/nix/neovim-overlay.nix index 4e6ba60..14fa59c 100644 --- a/nix/neovim-overlay.nix +++ b/nix/neovim-overlay.nix @@ -48,6 +48,9 @@ with final.pkgs.lib; let lualine-nvim noice-nvim indent-blankline-nvim + + # Editor + neo-tree-nvim ]; extraPackages = with pkgs; [ diff --git a/nvim/lua/icons.lua b/nvim/lua/icons.lua index b177183..cb25ea7 100644 --- a/nvim/lua/icons.lua +++ b/nvim/lua/icons.lua @@ -14,5 +14,7 @@ return { added = ' ', modified = ' ', removed = ' ', + unstaged = '󰄱', + staged = '󰱒', }, } diff --git a/nvim/lua/plugins/editor/init.lua b/nvim/lua/plugins/editor/init.lua new file mode 100644 index 0000000..530d37a --- /dev/null +++ b/nvim/lua/plugins/editor/init.lua @@ -0,0 +1,5 @@ +local req = require('lib.marleyvim').localRequire('plugins.editor') + +return { + req('neo-tree-nvim'), +} diff --git a/nvim/lua/plugins/editor/neo-tree-nvim.lua b/nvim/lua/plugins/editor/neo-tree-nvim.lua new file mode 100644 index 0000000..3a1cc25 --- /dev/null +++ b/nvim/lua/plugins/editor/neo-tree-nvim.lua @@ -0,0 +1,126 @@ +---@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' }) + 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 }, + }, + }) + end, +}