From 78f04bda73697921fa39cd5223ce9bbbfb0df287 Mon Sep 17 00:00:00 2001 From: "RingOfStorms (Joshua Bell)" Date: Wed, 1 May 2024 18:11:18 -0500 Subject: [PATCH] sessions and nvim tree --- flake.lock | 51 ++++++ flake.nix | 16 +- init.lua | 1 - lua/keymaps.lua | 7 - .../{editor_auto_save.lua => auto_save.lua} | 0 ...itor_comments.lua => comments_support.lua} | 0 ...rl_retirement.lua => early_retirement.lua} | 0 lua/plugins/nvim_tree_files.lua | 157 ++++++++++++++++++ lua/plugins/session.lua | 19 +++ ...or_smooth_scroll.lua => smooth_scroll.lua} | 0 ...me_catppuccin.lua => theme_catppuccin.lua} | 0 .../{editor_whichkey.lua => whichkey.lua} | 0 12 files changed, 239 insertions(+), 12 deletions(-) rename lua/plugins/{editor_auto_save.lua => auto_save.lua} (100%) rename lua/plugins/{editor_comments.lua => comments_support.lua} (100%) rename lua/plugins/{editor_earl_retirement.lua => early_retirement.lua} (100%) create mode 100644 lua/plugins/nvim_tree_files.lua create mode 100644 lua/plugins/session.lua rename lua/plugins/{editor_smooth_scroll.lua => smooth_scroll.lua} (100%) rename lua/plugins/{editor_theme_catppuccin.lua => theme_catppuccin.lua} (100%) rename lua/plugins/{editor_whichkey.lua => whichkey.lua} (100%) diff --git a/flake.lock b/flake.lock index 62b6b09..f8175ab 100644 --- a/flake.lock +++ b/flake.lock @@ -257,6 +257,38 @@ "type": "github" } }, + "nvim_plugin-nvim-tree/nvim-tree.lua": { + "flake": false, + "locked": { + "lastModified": 1714440771, + "narHash": "sha256-yLWb3aKsab3Cqbp3RgP0maiLOQWtxbUdnkLy7sQygx0=", + "owner": "nvim-tree", + "repo": "nvim-tree.lua", + "rev": "347e1eb35264677f66a79466bb5e3d111968e12c", + "type": "github" + }, + "original": { + "owner": "nvim-tree", + "repo": "nvim-tree.lua", + "type": "github" + } + }, + "nvim_plugin-nvim-tree/nvim-web-devicons": { + "flake": false, + "locked": { + "lastModified": 1714371374, + "narHash": "sha256-gc+8GgFSM87dbcYUW8d9If3qY80xJMmy48vnVezNLPk=", + "owner": "nvim-tree", + "repo": "nvim-web-devicons", + "rev": "794bba734ec95eaff9bb82fbd112473be2087283", + "type": "github" + }, + "original": { + "owner": "nvim-tree", + "repo": "nvim-web-devicons", + "type": "github" + } + }, "nvim_plugin-preservim/nerdcommenter": { "flake": false, "locked": { @@ -289,6 +321,22 @@ "type": "github" } }, + "nvim_plugin-rmagatti/auto-session": { + "flake": false, + "locked": { + "lastModified": 1713075135, + "narHash": "sha256-wu/utBYr4o4BenybAumDxBTERBkRkcR1QzlfmnVbOTQ=", + "owner": "rmagatti", + "repo": "auto-session", + "rev": "9e0a169b6fce8791278abbd110717b921afe634d", + "type": "github" + }, + "original": { + "owner": "rmagatti", + "repo": "auto-session", + "type": "github" + } + }, "nvim_plugin-windwp/nvim-ts-autotag": { "flake": false, "locked": { @@ -323,8 +371,11 @@ "nvim_plugin-nvim-telescope/telescope-fzf-native.nvim": "nvim_plugin-nvim-telescope/telescope-fzf-native.nvim", "nvim_plugin-nvim-telescope/telescope-ui-select.nvim": "nvim_plugin-nvim-telescope/telescope-ui-select.nvim", "nvim_plugin-nvim-telescope/telescope.nvim": "nvim_plugin-nvim-telescope/telescope.nvim", + "nvim_plugin-nvim-tree/nvim-tree.lua": "nvim_plugin-nvim-tree/nvim-tree.lua", + "nvim_plugin-nvim-tree/nvim-web-devicons": "nvim_plugin-nvim-tree/nvim-web-devicons", "nvim_plugin-preservim/nerdcommenter": "nvim_plugin-preservim/nerdcommenter", "nvim_plugin-rcarriga/nvim-notify": "nvim_plugin-rcarriga/nvim-notify", + "nvim_plugin-rmagatti/auto-session": "nvim_plugin-rmagatti/auto-session", "nvim_plugin-windwp/nvim-ts-autotag": "nvim_plugin-windwp/nvim-ts-autotag" } }, diff --git a/flake.nix b/flake.nix index 12bc712..48bb1cd 100644 --- a/flake.nix +++ b/flake.nix @@ -75,10 +75,18 @@ url = "github:windwp/nvim-ts-autotag"; flake = false; }; - # "nvim_plugin-nvim-treesitter/nvim-treesitter" = { - # url = "github:nvim-treesitter/nvim-treesitter"; - # flake = false; - # }; + "nvim_plugin-rmagatti/auto-session" = { + url = "github:rmagatti/auto-session"; + flake = false; + }; + "nvim_plugin-nvim-tree/nvim-web-devicons" = { + url = "github:nvim-tree/nvim-web-devicons"; + flake = false; + }; + "nvim_plugin-nvim-tree/nvim-tree.lua" = { + url = "github:nvim-tree/nvim-tree.lua"; + flake = false; + }; }; outputs = { self, nixpkgs, flake-utils, ... } @ inputs: diff --git a/init.lua b/init.lua index 87a2196..7cd2124 100644 --- a/init.lua +++ b/init.lua @@ -4,7 +4,6 @@ if NIX then -- However this pollutes the path, it could be limited to just init files but this approach here one level deep is adequate for my own needs package.path = package.path .. ";" .. NIX.storePath .. "/lua/?.lua" package.path = package.path .. ";" .. NIX.storePath .. "/lua/?/init.lua" - print(vim.inspect(NIX)) end U = require("util") -- NOTE global U[til] diff --git a/lua/keymaps.lua b/lua/keymaps.lua index fed0bbe..2da3d3d 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -23,13 +23,6 @@ U.keymaps({ { "Q", "", mode = nvx }, -- don't do normal Q quit { "a", "ggVG", desc = "Select all", mode = nvx }, { "Q", "qa", desc = "Quit all", mode = nvx }, - -- { - -- "QQ", - -- -- TODO REVISIT is this session stuff still relevant? - -- "NvimTreeCloseSessionDeleteqa", - -- desc = "Quit all, no session saved", - -- mode = nvx, - -- }, { "y", '"+y', desc = "Copy to system clipboard", mode = nvx }, { "p", '"+p', desc = "Paste from system clipboard", mode = nvx }, { "", "nohlsearch", desc = "Clear search on escape" }, diff --git a/lua/plugins/editor_auto_save.lua b/lua/plugins/auto_save.lua similarity index 100% rename from lua/plugins/editor_auto_save.lua rename to lua/plugins/auto_save.lua diff --git a/lua/plugins/editor_comments.lua b/lua/plugins/comments_support.lua similarity index 100% rename from lua/plugins/editor_comments.lua rename to lua/plugins/comments_support.lua diff --git a/lua/plugins/editor_earl_retirement.lua b/lua/plugins/early_retirement.lua similarity index 100% rename from lua/plugins/editor_earl_retirement.lua rename to lua/plugins/early_retirement.lua diff --git a/lua/plugins/nvim_tree_files.lua b/lua/plugins/nvim_tree_files.lua new file mode 100644 index 0000000..1ce0a41 --- /dev/null +++ b/lua/plugins/nvim_tree_files.lua @@ -0,0 +1,157 @@ +return { + "nvim-tree/nvim-tree.lua", + lazy = false, + dependencies = { + "nvim-tree/nvim-web-devicons", + }, + opts = function() + return { + sort = { + sorter = "case_sensitive", + }, + view = { + -- width = getWidth(), + float = { + enable = true, + open_win_config = function() + local cols = vim.api.nvim_get_option("columns") + local rows = vim.api.nvim_get_option("lines") + local width = math.floor(cols / 2) + local height = math.floor(rows / 1.2) + return { + relative = "editor", + row = math.floor(rows / 10), + col = math.floor(cols / 4), + width = width, + height = height, + border = "rounded", + } + end, + }, + }, + renderer = { + group_empty = true, + indent_width = 3, + icons = { + glyphs = { + git = { + unstaged = "", + }, + }, + }, + }, + filters = { + dotfiles = false, + git_ignored = false, + exclude = { ".DS_Store" }, + }, + actions = { + open_file = { + quit_on_open = true, + window_picker = { + enable = false, + }, + }, + }, + on_attach = function(bufnr) + -- https://github.com/nvim-tree/nvim-tree.lua/wiki/Recipes#modify-you-on_attach-function-to-have-ability-to-operate-multiple-files-at-once + local api = require("nvim-tree.api") + local opts = function(desc) + return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + end + -- mark operation + local mark_move_j = function() + api.marks.toggle() + vim.cmd("norm j") + end + local mark_move_k = function() + api.marks.toggle() + vim.cmd("norm k") + end + + -- marked files operation + local mark_remove = function() + local marks = api.marks.list() + if #marks == 0 then + table.insert(marks, api.tree.get_node_under_cursor()) + end + for _, node in ipairs(marks) do + api.fs.remove(node) + end + api.marks.clear() + api.tree.reload() + end + + local mark_copy = function() + local marks = api.marks.list() + if #marks == 0 then + table.insert(marks, api.tree.get_node_under_cursor()) + end + for _, node in pairs(marks) do + api.fs.copy.node(node) + end + api.marks.clear() + api.tree.reload() + end + + local mark_cut = function() + local marks = api.marks.list() + if #marks == 0 then + table.insert(marks, api.tree.get_node_under_cursor()) + end + for _, node in pairs(marks) do + api.fs.cut(node) + end + api.marks.clear() + api.tree.reload() + end + + local mark_move_to_cursor = function() + local marks = api.marks.list() + if #marks == 0 then + table.insert(marks, api.tree.get_node_under_cursor()) + end + for _, node in pairs(marks) do + api.fs.cut(node) + end + api.marks.clear() + api.fs.paste() + api.tree.reload() + end + + vim.keymap.set("n", "J", mark_move_j, opts("Toggle Bookmark Down")) + vim.keymap.set("n", "K", mark_move_k, opts("Toggle Bookmark Up")) + + vim.keymap.set("n", "x", mark_cut, opts("Cut File(s)")) + vim.keymap.set("n", "d", mark_remove, opts("Remove File(s)")) + vim.keymap.set("n", "y", mark_copy, opts("Copy File(s)")) + + vim.keymap.set("n", "mv", mark_move_to_cursor, opts("Move Bookmarked")) + vim.keymap.set("n", "M", api.marks.clear, opts("Clear Bookmarks")) + + -- https://github.com/nvim-tree/nvim-tree.lua/wiki/Recipes#refactoring-of-on_attach-generated-code + vim.keymap.set("n", "q", api.tree.close, opts("Close")) + vim.keymap.set("n", "", api.tree.close, opts("Close")) + vim.keymap.set("n", "o", api.tree.close, opts("Close")) + vim.keymap.set("n", "", api.node.open.edit, opts("Open")) + vim.keymap.set("n", "l", api.node.open.edit, opts("Open")) + vim.keymap.set("n", "h", api.node.navigate.parent_close, opts("Close Directory")) + vim.keymap.set("n", "r", api.fs.rename, opts("Rename")) + vim.keymap.set("n", "a", api.fs.create, opts("Create")) + vim.keymap.set("n", "p", api.fs.paste, opts("Paste")) + vim.keymap.set("n", "R", api.tree.reload, opts("Refresh")) + vim.keymap.set("n", "m", api.marks.toggle, opts("Toggle Bookmark")) + + vim.keymap.set("n", "c", api.fs.copy.absolute_path, opts("Copy Path to Clipboard")) + + vim.keymap.set("n", "h", api.node.navigate.parent_close, opts("Close Directory")) + + vim.keymap.set("n", "?", api.tree.toggle_help, opts("Help")) + end, + } + end, + keys = { + { "e", "NvimTreeToggle", desc = "Open file browser" }, + { "o", "NvimTreeFindFile", desc = "Open file browser at current buffer" }, + }, +} diff --git a/lua/plugins/session.lua b/lua/plugins/session.lua new file mode 100644 index 0000000..61030f7 --- /dev/null +++ b/lua/plugins/session.lua @@ -0,0 +1,19 @@ +return { + "rmagatti/auto-session", + lazy = false, + init = function() + vim.o.sessionoptions = "blank,buffers,curdir,folds,tabpages,winsize,winpos,terminal,localoptions" + end, + opts = { + auto_session_use_git_branch = true, + auto_session_suppress_dirs = { "~/", "sessions", "~/Downloads", "/" }, + post_cwd_changed_hook = function() + U.safeRequire("lualine", function(ll) + ll.refresh() -- refresh lualine so the new session name is displayed in the status bar + end) + end, + }, + config = function(_, opts) + require("auto-session").setup(opts) + end, +} diff --git a/lua/plugins/editor_smooth_scroll.lua b/lua/plugins/smooth_scroll.lua similarity index 100% rename from lua/plugins/editor_smooth_scroll.lua rename to lua/plugins/smooth_scroll.lua diff --git a/lua/plugins/editor_theme_catppuccin.lua b/lua/plugins/theme_catppuccin.lua similarity index 100% rename from lua/plugins/editor_theme_catppuccin.lua rename to lua/plugins/theme_catppuccin.lua diff --git a/lua/plugins/editor_whichkey.lua b/lua/plugins/whichkey.lua similarity index 100% rename from lua/plugins/editor_whichkey.lua rename to lua/plugins/whichkey.lua