From b0610adaaefbf4ad2a80fb87d6cdc8aaabfe99de Mon Sep 17 00:00:00 2001 From: js0ny Date: Thu, 3 Apr 2025 01:38:14 +0100 Subject: [PATCH] feat(nvim): Change explorer to `neo-tree` --- tools/nvim/lua/plugins/edit.lua | 48 +----------- tools/nvim/lua/plugins/fileutils.lua | 15 ++-- tools/nvim/lua/plugins/mod/mc.lua | 47 ++++++++++++ tools/nvim/lua/plugins/mod/neo-tree.lua | 89 ++++++++++++++++++++++ tools/nvim/lua/plugins/mod/snacks-nvim.lua | 38 ++++----- 5 files changed, 164 insertions(+), 73 deletions(-) create mode 100644 tools/nvim/lua/plugins/mod/mc.lua create mode 100644 tools/nvim/lua/plugins/mod/neo-tree.lua diff --git a/tools/nvim/lua/plugins/edit.lua b/tools/nvim/lua/plugins/edit.lua index dabc547..a414cda 100644 --- a/tools/nvim/lua/plugins/edit.lua +++ b/tools/nvim/lua/plugins/edit.lua @@ -12,53 +12,7 @@ return { { "", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" }, }, }, - { - "js0ny/multiple-cursors.nvim", - version = "*", -- Use the latest tagged version - -- opts = , -- This causes the plugin setup function to be called - keys = { - { "", "MultipleCursorsAddDown", mode = { "n", "x" }, desc = "Add cursor and move down" }, - { "", "MultipleCursorsAddUp", mode = { "n", "x" }, desc = "Add cursor and move up" }, - - { "", "MultipleCursorsAddUp", mode = { "n", "i", "x" }, desc = "Add cursor and move up" }, - { "", "MultipleCursorsAddDown", mode = { "n", "i", "x" }, desc = "Add cursor and move down" }, - - { "", "MultipleCursorsMouseAddDelete", mode = { "n", "i" }, desc = "Add or remove cursor" }, - }, - config = function() - local normal_mode_motion = require("multiple-cursors.normal_mode.motion") - local normal_mode_edit = require("multiple-cursors.normal_mode.edit") - - local visual_mode_edit = require("multiple-cursors.visual_mode.edit") - local normal_mode_mode_change = require("multiple-cursors.normal_mode.mode_change") - - local visual_mode_modify_area = require("multiple-cursors.visual_mode.modify_area") - require("multiple-cursors").setup({ - pre_hook = function() - require("nvim-autopairs").disable() - end, - post_hook = function() - require("nvim-autopairs").enable() - end, - custom_key_maps = { - { { "n", "x" }, { "e", "" }, normal_mode_motion.k, "nowrap" }, - { { "n", "x" }, { "n", "" }, normal_mode_motion.j, "nowrap" }, - { { "n", "x" }, { "i", "", "" }, normal_mode_motion.l, "nowrap" }, - { { "n", "x" }, "j", normal_mode_motion.e, "nowrap" }, - { { "n", "x" }, "J", normal_mode_motion.E, "nowrap" }, - { { "n", "x" }, "gj", normal_mode_motion.ge, "nowrap" }, - { { "n", "x" }, "gJ", normal_mode_motion.gE, "nowrap" }, - { "n", "E", normal_mode_edit.J, "nowrap" }, - { "n", "gE", normal_mode_edit.gJ, "nowrap" }, - { "n", { "l", "" }, normal_mode_mode_change.i, "nowrap" }, - { "n", "L", normal_mode_mode_change.I, "nowrap" }, - { "x", "l", visual_mode_modify_area.i, "nowrap" }, - { "x", "E", visual_mode_edit.J, "nowrap" }, - { "x", "gE", visual_mode_edit.gJ, "nowrap" }, - }, - }) - end, - }, + { import = "plugins.mod.mc" }, -- Multiple-cursors { import = "plugins.mod.autopairs" }, { "kylechui/nvim-surround", diff --git a/tools/nvim/lua/plugins/fileutils.lua b/tools/nvim/lua/plugins/fileutils.lua index 2ae591f..5f18020 100644 --- a/tools/nvim/lua/plugins/fileutils.lua +++ b/tools/nvim/lua/plugins/fileutils.lua @@ -28,11 +28,12 @@ return { end, dependencies = { "nvim-telescope/telescope.nvim" }, }, - { - "NeogitOrg/neogit", - config = true, - cmd = { - "Neogit", - }, - }, + -- { + -- "NeogitOrg/neogit", + -- config = true, + -- cmd = { + -- "Neogit", + -- }, + -- }, + { import = "plugins.mod.neo-tree" } } diff --git a/tools/nvim/lua/plugins/mod/mc.lua b/tools/nvim/lua/plugins/mod/mc.lua new file mode 100644 index 0000000..5c63338 --- /dev/null +++ b/tools/nvim/lua/plugins/mod/mc.lua @@ -0,0 +1,47 @@ +return { + "js0ny/multiple-cursors.nvim", + version = "*", -- Use the latest tagged version + -- opts = , -- This causes the plugin setup function to be called + keys = { + { "", "MultipleCursorsAddDown", mode = { "n", "x" }, desc = "Add cursor and move down" }, + { "", "MultipleCursorsAddUp", mode = { "n", "x" }, desc = "Add cursor and move up" }, + + { "", "MultipleCursorsAddUp", mode = { "n", "i", "x" }, desc = "Add cursor and move up" }, + { "", "MultipleCursorsAddDown", mode = { "n", "i", "x" }, desc = "Add cursor and move down" }, + + { "", "MultipleCursorsMouseAddDelete", mode = { "n", "i" }, desc = "Add or remove cursor" }, + }, + config = function() + local normal_mode_motion = require("multiple-cursors.normal_mode.motion") + local normal_mode_edit = require("multiple-cursors.normal_mode.edit") + + local visual_mode_edit = require("multiple-cursors.visual_mode.edit") + local normal_mode_mode_change = require("multiple-cursors.normal_mode.mode_change") + + local visual_mode_modify_area = require("multiple-cursors.visual_mode.modify_area") + require("multiple-cursors").setup({ + pre_hook = function() + require("nvim-autopairs").disable() + end, + post_hook = function() + require("nvim-autopairs").enable() + end, + custom_key_maps = { + { { "n", "x" }, { "e", "" }, normal_mode_motion.k, "nowrap" }, + { { "n", "x" }, { "n", "" }, normal_mode_motion.j, "nowrap" }, + { { "n", "x" }, { "i", "", "" }, normal_mode_motion.l, "nowrap" }, + { { "n", "x" }, "j", normal_mode_motion.e, "nowrap" }, + { { "n", "x" }, "J", normal_mode_motion.E, "nowrap" }, + { { "n", "x" }, "gj", normal_mode_motion.ge, "nowrap" }, + { { "n", "x" }, "gJ", normal_mode_motion.gE, "nowrap" }, + { "n", "E", normal_mode_edit.J, "nowrap" }, + { "n", "gE", normal_mode_edit.gJ, "nowrap" }, + { "n", { "l", "" }, normal_mode_mode_change.i, "nowrap" }, + { "n", "L", normal_mode_mode_change.I, "nowrap" }, + { "x", "l", visual_mode_modify_area.i, "nowrap" }, + { "x", "E", visual_mode_edit.J, "nowrap" }, + { "x", "gE", visual_mode_edit.gJ, "nowrap" }, + }, + }) + end, +} diff --git a/tools/nvim/lua/plugins/mod/neo-tree.lua b/tools/nvim/lua/plugins/mod/neo-tree.lua new file mode 100644 index 0000000..0502999 --- /dev/null +++ b/tools/nvim/lua/plugins/mod/neo-tree.lua @@ -0,0 +1,89 @@ +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 = { + window = { +mappings = { + [""] = "noop", + ["e"] = "noop", + ["<2-LeftMouse>"] = "open", + [""] = "open", + ["i"] = "open", + [""] = "cancel", -- close preview or floating neo-tree window + ["P"] = { "toggle_preview", config = { use_float = true, use_image_nvim = true } }, + -- Read `# Preview Mode` for more information + -- ["i"] = "focus_preview", + ["S"] = "open_split", + ["s"] = "open_vsplit", + -- ["S"] = "split_with_window_picker", + -- ["s"] = "vsplit_with_window_picker", + ["t"] = "open_tabnew", + -- [""] = "open_drop", + -- ["t"] = "open_tab_drop", + ["w"] = "open_with_window_picker", + --["P"] = "toggle_preview", -- enter preview mode, which shows the current node without focusing + ["C"] = "close_node", + -- ['C'] = 'close_all_subnodes', + ["z"] = "close_all_nodes", + --["Z"] = "expand_all_nodes", + ["a"] = { + "add", + -- this command supports BASH style brace expansion ("x{a,b,c}" -> xa,xb,xc). see `:h neo-tree-file-actions` for details + -- some commands may take optional config options, see `:h neo-tree-mappings` for details + config = { + show_path = "none", -- "none", "relative", "absolute" + }, + }, + ["A"] = "add_directory", -- also accepts the optional config.show_path option like "add". this also supports BASH style brace expansion. + ["d"] = "delete", + ["r"] = "rename", + ["b"] = "rename_basename", + ["y"] = "copy_to_clipboard", + ["x"] = "cut_to_clipboard", + ["p"] = "paste_from_clipboard", + ["c"] = "copy", -- takes text input for destination, also accepts the optional config.show_path option like "add": + -- ["c"] = { + -- "copy", + -- config = { + -- show_path = "none" -- "none", "relative", "absolute" + -- } + --} + ["m"] = "move", -- takes text input for destination, also accepts the optional config.show_path option like "add". + ["q"] = "close_window", + ["R"] = "refresh", + ["?"] = "show_help", + ["<"] = "prev_source", + [">"] = "next_source", + ["l"] = "show_file_details", + -- ["i"] = { + -- "show_file_details", + -- -- format strings of the timestamps shown for date created and last modified (see `:h os.date()`) + -- -- both options accept a string or a function that takes in the date in seconds and returns a string to display + -- -- config = { + -- -- created_format = "%Y-%m-%d %I:%M %p", + -- -- modified_format = "relative", -- equivalent to the line below + -- -- modified_format = function(seconds) return require('neo-tree.utils').relative_date(seconds) end + -- -- } + -- }, + } + } + -- fill any relevant options here + }, + keys = { + { + "ft", + "Neotree toggle", + desc = "Toggle File Explorer", + } + } + +} diff --git a/tools/nvim/lua/plugins/mod/snacks-nvim.lua b/tools/nvim/lua/plugins/mod/snacks-nvim.lua index 632000c..6e33e1d 100644 --- a/tools/nvim/lua/plugins/mod/snacks-nvim.lua +++ b/tools/nvim/lua/plugins/mod/snacks-nvim.lua @@ -31,18 +31,18 @@ return { { section = "startup" }, }, }, - explorer = { - -- TODO: Remap some keys in explorer - -- win = { - -- list = { - -- keys = { - -- ["l"] = "focus_input", - -- ["i"] = "confirm", - -- ["O"] = "explorer_open", -- Open with system default - -- }, - -- }, - -- }, - }, + -- explorer = { + -- -- TODO: Remap some keys in explorer + -- -- win = { + -- -- list = { + -- -- keys = { + -- -- ["l"] = "focus_input", + -- -- ["i"] = "confirm", + -- -- ["O"] = "explorer_open", -- Open with system default + -- -- }, + -- -- }, + -- -- }, + -- }, indent = { enabled = true }, -- input = { enabled = true }, -- notifier = { enabled = true }, @@ -54,12 +54,12 @@ return { image = { enabled = true }, }, keys = { - { - "ft", - function() - require("snacks").explorer() - end, - desc = "Toggle File Explorer", - }, + -- { + -- "ft", + -- function() + -- require("snacks").explorer() + -- end, + -- desc = "Toggle File Explorer", + -- }, }, }