From feed555e48b6c54667c65f4864280b2e3407c0a1 Mon Sep 17 00:00:00 2001 From: punkfairie Date: Sat, 30 Nov 2024 20:47:08 -0800 Subject: [PATCH] WIP neo-tree WIP --- nix/neovim-overlay.nix | 3 + nvim/lua/plugins/editor/init.lua | 5 ++ nvim/lua/plugins/editor/neo-tree-nvim.lua | 91 +++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 nvim/lua/plugins/editor/init.lua create mode 100644 nvim/lua/plugins/editor/neo-tree-nvim.lua 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/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..45bd393 --- /dev/null +++ b/nvim/lua/plugins/editor/neo-tree-nvim.lua @@ -0,0 +1,91 @@ +local lazyvim_root = require('lib.lazyvim.root') + +---@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 (lazyvim_root.get()) 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() + require('neo-tree').setup({ + 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, + }, + + 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 } }, + }, + }, + }) + end, +}