From c42f197307ed537e07d9dc2ce15bad1d63ab43a3 Mon Sep 17 00:00:00 2001 From: "RingOfStorms (Joshua Bell)" Date: Wed, 1 May 2024 01:14:46 -0500 Subject: [PATCH] WIP on new config --- README.md | 9 +- flake.lock | 104 +++++++++++++- flake.nix | 25 ++++ init.lua | 9 +- lua/autocommands.lua | 11 ++ lua/keymaps.lua | 135 +++++++++--------- lua/options.lua | 41 ++++-- lua/plugins/editor_auto_save.lua | 18 +++ lua/plugins/editor_earl_retirement.lua | 10 ++ lua/plugins/editor_noice.lua | 32 +++++ lua/plugins/editor_notify.lua | 27 ++++ lua/plugins/editor_smooth_scroll.lua | 15 ++ ...puccin.lua => editor_theme_catppuccin.lua} | 3 + 13 files changed, 354 insertions(+), 85 deletions(-) create mode 100644 lua/plugins/editor_auto_save.lua create mode 100644 lua/plugins/editor_earl_retirement.lua create mode 100644 lua/plugins/editor_noice.lua create mode 100644 lua/plugins/editor_notify.lua create mode 100644 lua/plugins/editor_smooth_scroll.lua rename lua/plugins/{catppuccin.lua => editor_theme_catppuccin.lua} (91%) diff --git a/README.md b/README.md index 44a8e6e..41adcec 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Goals: - Works with or without nix +- LSP integration with the current project's settings if available ## Running @@ -41,10 +42,10 @@ rm -rf ~/.local/state/nvim - For scratches, just make an input box for custom extension rather than predefined list - for find files, ignore git, capital F for find all - better copilot alternatives? Local LLM usage only? etc? +- blacklist for undofile? .age files... etc +- TODO learn more about augroup in autocommands. - plugins to install: - - pocco81/auto-save.nvim - - folke/noice.nvim - messages/cmdline/popupmenu updates - rmagatti/auto-session - session management - TODO look for alternatives? I am not a huge fan of this as it causes some issues on startup sometimes. I really only care about window placements and I want the rest to load naturally - preservim/nerdcommenter - [un]comment support @@ -74,6 +75,7 @@ rm -rf ~/.local/state/nvim - lnc3l0t/glow.nvim - markdown preview - null_ls replacement?? need a formater replacement, diff between lsp reformat? - cspell? vs built in spell check? + - Lets use https://github.com/mfussenegger/nvim-lint - Almo7aya/openingh.nvim - tpope/vim-surround - nvim-telescope/telescope-file-browser.nvim ?? do I want to keep this? @@ -88,10 +90,7 @@ rm -rf ~/.local/state/nvim - folke/which-key.nvim - check out - - https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-bufremove.md - - OR https://github.com/famiu/bufdelete.nvim - https://github.com/onsails/lspkind.nvim - - declancm/cinnamon.nvim - smooth scroll effect - https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-align.md - plugins I decided to remove from my old config diff --git a/flake.lock b/flake.lock index 3e5fb61..eb22581 100644 --- a/flake.lock +++ b/flake.lock @@ -33,6 +33,38 @@ "type": "indirect" } }, + "nvim_plugin-MunifTanjim/nui.nvim": { + "flake": false, + "locked": { + "lastModified": 1710740032, + "narHash": "sha256-Zr5CNx6BIM6naCXW8YBc/Oj1qOtWV/3tuMoaaZjoSZA=", + "owner": "MunifTanjim", + "repo": "nui.nvim", + "rev": "cbd2668414331c10039278f558630ed19b93e69b", + "type": "github" + }, + "original": { + "owner": "MunifTanjim", + "repo": "nui.nvim", + "type": "github" + } + }, + "nvim_plugin-Pocco81/auto-save.nvim": { + "flake": false, + "locked": { + "lastModified": 1667329943, + "narHash": "sha256-bWGil73YiCKZEaY7IuUOIU4Q7k7qCMjSeQ4I+cAVe44=", + "owner": "Pocco81", + "repo": "auto-save.nvim", + "rev": "979b6c82f60cfa80f4cf437d77446d0ded0addf0", + "type": "github" + }, + "original": { + "owner": "Pocco81", + "repo": "auto-save.nvim", + "type": "github" + } + }, "nvim_plugin-catppuccin/nvim": { "flake": false, "locked": { @@ -49,6 +81,38 @@ "type": "github" } }, + "nvim_plugin-chrisgrieser/nvim-early-retirement": { + "flake": false, + "locked": { + "lastModified": 1706108060, + "narHash": "sha256-5lpGqHg0jrLawr2A8mNwADHG62A92By6ZpZeqzd2uUs=", + "owner": "chrisgrieser", + "repo": "nvim-early-retirement", + "rev": "8d83da8a5e5dd29e35a291fcb1c47290df9b7699", + "type": "github" + }, + "original": { + "owner": "chrisgrieser", + "repo": "nvim-early-retirement", + "type": "github" + } + }, + "nvim_plugin-declancm/cinnamon.nvim": { + "flake": false, + "locked": { + "lastModified": 1714107684, + "narHash": "sha256-cMP9WRZzevxaWgpILyDh1JwNukm3Jl3JKJYPT2HnFns=", + "owner": "declancm", + "repo": "cinnamon.nvim", + "rev": "a011e84b624cd7b609ea928237505d31b987748a", + "type": "github" + }, + "original": { + "owner": "declancm", + "repo": "cinnamon.nvim", + "type": "github" + } + }, "nvim_plugin-folke/lazy.nvim": { "flake": false, "locked": { @@ -65,12 +129,50 @@ "type": "github" } }, + "nvim_plugin-folke/noice.nvim": { + "flake": false, + "locked": { + "lastModified": 1711471279, + "narHash": "sha256-y6gHNkWVsIuwBf7MblCTKTZSqjGDxqeFeQZWexzwk94=", + "owner": "folke", + "repo": "noice.nvim", + "rev": "0cbe3f88d038320bdbda3c4c5c95f43a13c3aa12", + "type": "github" + }, + "original": { + "owner": "folke", + "repo": "noice.nvim", + "type": "github" + } + }, + "nvim_plugin-rcarriga/nvim-notify": { + "flake": false, + "locked": { + "lastModified": 1708161547, + "narHash": "sha256-xJYPOX4YLcWojMCdP1RO22/7FMrbcBQxqxrcVCE2TrU=", + "owner": "rcarriga", + "repo": "nvim-notify", + "rev": "5371f4bfc1f6d3adf4fe9d62cd3a9d44356bfd15", + "type": "github" + }, + "original": { + "owner": "rcarriga", + "repo": "nvim-notify", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", + "nvim_plugin-MunifTanjim/nui.nvim": "nvim_plugin-MunifTanjim/nui.nvim", + "nvim_plugin-Pocco81/auto-save.nvim": "nvim_plugin-Pocco81/auto-save.nvim", "nvim_plugin-catppuccin/nvim": "nvim_plugin-catppuccin/nvim", - "nvim_plugin-folke/lazy.nvim": "nvim_plugin-folke/lazy.nvim" + "nvim_plugin-chrisgrieser/nvim-early-retirement": "nvim_plugin-chrisgrieser/nvim-early-retirement", + "nvim_plugin-declancm/cinnamon.nvim": "nvim_plugin-declancm/cinnamon.nvim", + "nvim_plugin-folke/lazy.nvim": "nvim_plugin-folke/lazy.nvim", + "nvim_plugin-folke/noice.nvim": "nvim_plugin-folke/noice.nvim", + "nvim_plugin-rcarriga/nvim-notify": "nvim_plugin-rcarriga/nvim-notify" } }, "systems": { diff --git a/flake.nix b/flake.nix index 93dd092..4103777 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,31 @@ url = "github:catppuccin/nvim"; flake = false; }; + "nvim_plugin-Pocco81/auto-save.nvim" = { + url = "github:Pocco81/auto-save.nvim"; + flake = false; + }; + "nvim_plugin-chrisgrieser/nvim-early-retirement" = { + url = "github:chrisgrieser/nvim-early-retirement"; + flake = false; + }; + "nvim_plugin-MunifTanjim/nui.nvim" = { + url = "github:MunifTanjim/nui.nvim"; + flake = false; + }; + "nvim_plugin-rcarriga/nvim-notify" = { + url = "github:rcarriga/nvim-notify"; + flake = false; + }; + "nvim_plugin-folke/noice.nvim" = { + url = "github:folke/noice.nvim"; + flake = false; + }; +# TODO TELESCOPE + "nvim_plugin-declancm/cinnamon.nvim" = { + url = "github:declancm/cinnamon.nvim"; + flake = false; + }; }; outputs = { self, nixpkgs, flake-utils, ... } @ inputs: diff --git a/init.lua b/init.lua index 0f1801d..78c16a4 100644 --- a/init.lua +++ b/init.lua @@ -47,6 +47,7 @@ function getSpec() p.dir = NIX.pluginPaths[nixName] p.name = p.name or p[1] p.url = "not_used_in_nix" + p.pin = true if p.dependencies then p.dependencies = ensure_table(p.dependencies) for i, dep in ipairs(p.dependencies) do @@ -62,7 +63,6 @@ function getSpec() local plugin = string.sub(file, 0, -5) table.insert(plugins, convertPluginToNixStore(require("plugins." .. plugin))) end - print("PLUGINS" .. vim.inspect(plugins)) return plugins else -- TODO I want this to work in the nixos versionhttps://github.com/RingOfStorms/nvim/blob/nix-flake/init.lua#L39-L55 @@ -78,10 +78,15 @@ require("lazy").setup({ enabled = false, }, defaults = { - -- lazy = true + lazy = true, }, }) vim.cmd("colorscheme catppuccin") require("tools") require("autocommands") + +-- - **LazyDone**when lazy has finished starting up and loaded your config +-- - **VeryLazy**triggered after `LazyDone` and processing `VimEnter` auto commands +-- - **LazyVimStarted**triggered after `UIEnter` when `require("lazy").stats().startuptime` has been calculated. +-- Useful to update the startuptime on your dashboard. diff --git a/lua/autocommands.lua b/lua/autocommands.lua index 49bc9e9..703665b 100644 --- a/lua/autocommands.lua +++ b/lua/autocommands.lua @@ -1,3 +1,14 @@ +-- Highlight when yanking (copying) text +-- Try it with `yap` in normal mode +-- See `:help vim.highlight.on_yank()` +vim.api.nvim_create_autocmd("TextYankPost", { + desc = "Highlight when yanking (copying) text", + group = vim.api.nvim_create_augroup("config-highlight-yank", { clear = true }), + callback = function() + vim.highlight.on_yank({ timeout = 300 }) + end, +}) + --function isEmpty() --return vim.api.nvim_buf_get_name(0) == "" --or vim.fn.filereadable(vim.api.nvim_buf_get_name(0)) == 0 diff --git a/lua/keymaps.lua b/lua/keymaps.lua index b88c22a..6e20189 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -1,3 +1,4 @@ +local util = require("util") -- Remap space as leader key vim.keymap.set("", "", "", { silent = true }) vim.g.mapleader = " " @@ -13,50 +14,54 @@ vim.g.maplocalleader = " " local nvx = { "n", "v", "x" } -require("util").keymaps({ - -- ============= - -- n/v/x (normal + visual modes) - -- ============= +util.keymaps({ + -- =========== + -- Basic + -- =========== + { "", 'echo "use h/j/k/l to move!"', mode = nvx }, + { "", 'echo "use h/j/k/l to move!"', mode = nvx }, + { "", 'echo "use h/j/k/l to move!"', mode = nvx }, + { "", 'echo "use h/j/k/l to move!"', mode = nvx }, { ";", ":", desc = "No shift to enter command mode with semicolon. Alias ; to :", mode = nvx }, - { "a", "ggVG", desc = "Select all", mode = nvx }, - { "w", "w", desc = "Save", mode = nvx }, - { - "q", - function() - -- Use to have this which always closed and quit ont he last screen: "confirm q" - -- Instead I want this behavior: - -- if only 1 screen is open then close all buffers, resulting in a blank unnamed buffer window similar to fresh session - -- else if more than 1 screen, confirm q to close that screen - -- Check the number of screens - if vim.fn.winnr("$") == 1 then - -- If only 1 screen is open then close all buffers, resulting in a blank unnamed buffer window similar to fresh session - vim.cmd("bufdo bd") - vim.cmd("SessionDelete") - else - -- If more than 1 screen, confirm q to close that screen - vim.cmd("confirm q") - end - end, - desc = "Quit", - mode = nvx, - }, - { "Q", "qa", desc = "Quit all", mode = nvx }, - -- { "Q", "qa", desc = "Quit all", mode = nvx }, { "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 }, - { "bq", "bp|bd #", desc = "Close current buffer only", mode = nvx }, - { "bn", "enew", desc = "Open a new buffer in current screen", mode = nvx }, - { "bt", "terminali", desc = "Open a terminal in current screen", mode = nvx }, - { "tn", "tabnew", desc = "Create new tab", mode = nvx }, - { "tq", "tabclose", desc = "Close current tab", mode = nvx }, + { "", "nohlsearch", desc = "Clear search on escape" }, + { "", "nohlsearch", desc = "Clear search on return" }, + { "|", "vsplit", desc = "Vertical Split" }, + { "\\", "split", desc = "Horizontal Split" }, + -- Buffers + { "b", "b#", desc = "Switch to last buffer", mode = nvx }, + { + "q", + function() + -- Custom close/quit + -- * if non empty buffer, we will simply open a new empty buffer unless + -- it is in the close always list + -- * if empty buffer, then we will quit this buffer + local close_always = { "quickfix", "help", "nofile" } + if + util.table_contains(close_always, vim.bo.buftype) + or (vim.api.nvim_buf_line_count(0) == 1 and vim.api.nvim_buf_get_lines(0, 0, 1, -1)[1] == "") + then + vim.cmd("silent confirm q") + else + vim.cmd("enew") + end + end, + desc = "Quit/Close current", + mode = nvx, + }, { "S", "set equalalwaysset noequalalways", @@ -67,68 +72,60 @@ require("util").keymaps({ { "", "j", desc = "Move window below current", mode = nvx }, { "", "k", desc = "Move window above current", mode = nvx }, { "", "l", desc = "Move window right current", mode = nvx }, - { "B", "b#", desc = "Switch to last buffer", mode = nvx }, + + -- Tabs + -- TODO revisit, do I even need these tab things? + { "tn", "tabnew", desc = "Create new tab", mode = nvx }, + { "tq", "tabclose", desc = "Close current tab", mode = nvx }, + { "H", "tabprevious", desc = "Move to previous tab" }, + { "L", "tabnext", desc = "Move to next tab" }, + + -- LSP/IDE/etc { "l", - function() - -- vim.cmd "SqlxFormat" - vim.lsp.buf.format() - end, + vim.lsp.buf.format, desc = "Reformat file", mode = nvx, }, - { - "ls", - "SqlxFormat", - desc = "Format sqlx queries in rust raw string literals.", - mode = nvx, - }, { "ld", - function() - vim.diagnostic.open_float() - end, + vim.diagnostic.open_float, desc = "Show diagnostic message", mode = nvx, }, { "ll", - function() - vim.diagnostic.setloclist() - end, - desc = "Show diagnostic list", + vim.diagnostic.setloclist, + desc = "Show diagnostics in quickfix list", mode = nvx, }, + -- ============= + -- ============= + -- ============= + -- ============= + -- ============= + -- ============= -- ============= -- normal mode -- ============= -- { "", "", desc = "" }, - { "H", "tabprevious", desc = "Move to previous tab" }, - { "L", "tabnext", desc = "Move to next tab" }, - { "|", "vsplit", desc = "Vertical Split" }, - { "\\", "split", desc = "Horizontal Split" }, - { "n", "nzzzv", desc = "Next search result centered" }, - { "N", "Nzzzv", desc = "Previous search result centered" }, - { "", ":noh", desc = "Clear search on escape" }, - { "", ":noh", desc = "Clear search on return" }, - { "", "zz", desc = "Vertical half page down and center cursor" }, - { "", "zz", desc = "Vertical half page up and center cursor" }, + + -- { "n", "nzzzv", desc = "Next search result centered" }, + -- { "N", "Nzzzv", desc = "Previous search result centered" }, + -- { "", "zz", desc = "Vertical half page down and center cursor" }, + -- { "", "zz", desc = "Vertical half page up and center cursor" }, { "J", "mzJ`z", desc = "Move line below onto this line" }, { "", "", desc = "Go back " }, { "]d", - function() - vim.diagnostic.goto_next() - end, - desc = "Go to next diagnostic", + vim.diagnostic.goto_next, + desc = "Go to next diagnostic message", }, { "[d", - function() - vim.diagnostic.goto_prev() - end, - desc = "Go to next diagnostic", + vim.diagnostic.goto_prev, + desc = "Go to previous diagnostic message", }, -- ============= diff --git a/lua/options.lua b/lua/options.lua index 567d4e9..2cc0c70 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -1,12 +1,21 @@ --- allow use of system keyboard --- vim.opt.clipboard = "unnamedplus" +-- Set to true if you have a Nerd Font installed and selected in the terminal +vim.g.have_nerd_font = true -- global status line vim.opt.laststatus = 3 +-- Don't show the mode, since it's already in the status line +vim.opt.showmode = false + -- allow use of mouse vim.opt.mouse = "a" +-- Decrease update time +vim.opt.updatetime = 250 +-- Decrease mapped sequence wait time +-- Displays which-key popup sooner +vim.opt.timeoutlen = 300 + -- line numbering, relative vim.opt.number = true vim.wo.number = true @@ -33,29 +42,45 @@ vim.opt.expandtab = true -- Dont use swap files, use undotree vim.opt.swapfile = false vim.opt.backup = false -vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir" +vim.opt.undodir = vim.fn.stdpath("state") .. "/undodir" vim.opt.undofile = true +-- Sets how neovim will display certain whitespace characters in the editor. +-- See `:help 'list'` +-- and `:help 'listchars'` +vim.opt.list = true +vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "␣" } +-- TODO REVISIT IF I WANT THESE + -- Search settings vim.opt.hlsearch = true vim.opt.incsearch = true +-- Preview substitutions live, as you type +-- TODO revisit, what does this actually do +vim.opt.inccommand = "split" + +-- Show which line your cursor is on +vim.opt.cursorline = true + -- split to the right or below always vim.opt.splitbelow = true vim.opt.splitright = true -- Set completeopt to have a better completion experience -vim.o.completeopt = "menuone,noselect" +vim.opt.completeopt = "menuone,noselect" vim.diagnostic.config({ float = { border = "single" }, }) +-- Minimal number of screen lines to keep above and below the cursor. +vim.opt.scrolloff = 10 + -- Turn on new diff vim.opt.diffopt:append("linematch:20") --- Set screen mode --- vim.o.noequalalways = true --- vim.o.equalalways = false +-- Don't resize panels when closing something it is annoying +vim.opt.equalalways = false -- enable colors for opacity changes -vim.o.termguicolors = true +vim.opt.termguicolors = true diff --git a/lua/plugins/editor_auto_save.lua b/lua/plugins/editor_auto_save.lua new file mode 100644 index 0000000..a52b42c --- /dev/null +++ b/lua/plugins/editor_auto_save.lua @@ -0,0 +1,18 @@ +return { + "Pocco81/auto-save.nvim", + event = "BufEnter", + opts = { + trigger_events = { "InsertLeave", "TextChanged", "TextChangedI", "BufLeave" }, + condition = function(buf) + local disallowed_filetypes = { "TelescopePrompt", "quickfix", "terminal" } + local utils = require("auto-save.utils.data") + if + vim.fn.getbufvar(buf, "&modifiable") == 1 + and utils.not_in(vim.fn.getbufvar(buf, "&filetype"), disallowed_filetypes) + then + return true + end + return false + end, + }, +} diff --git a/lua/plugins/editor_earl_retirement.lua b/lua/plugins/editor_earl_retirement.lua new file mode 100644 index 0000000..d8324f4 --- /dev/null +++ b/lua/plugins/editor_earl_retirement.lua @@ -0,0 +1,10 @@ +return { + "chrisgrieser/nvim-early-retirement", + config = true, + event = "VeryLazy", + opts = { + retirementAgeMins = 1, + notificationOnAutoClose = true, + -- deleteBufferWhenFileDeleted = true, + }, +} diff --git a/lua/plugins/editor_noice.lua b/lua/plugins/editor_noice.lua new file mode 100644 index 0000000..238e74b --- /dev/null +++ b/lua/plugins/editor_noice.lua @@ -0,0 +1,32 @@ +return { + "folke/noice.nvim", + event = "VeryLazy", + opts = { + cmdline = { + format = { + conceal = { + pattern = "^noh" + }, + }, + }, + lsp = { + -- override markdown rendering so that **cmp** and other plugins use **Treesitter** + override = { + ["vim.lsp.util.convert_input_to_markdown_lines"] = true, + ["vim.lsp.util.stylize_markdown"] = true, + ["cmp.entry.get_documentation"] = true, -- requires hrsh7th/nvim-cmp + }, + }, + }, + config = function(_, opts) + require("noice").setup(opts) + end, + dependencies = { + -- if you lazy-load any plugin below, make sure to add proper `module="..."` entries + "MunifTanjim/nui.nvim", + -- OPTIONAL: + -- `nvim-notify` is only needed, if you want to use the notification view. + -- If not available, we use `mini` as the fallback + "rcarriga/nvim-notify", + }, +} diff --git a/lua/plugins/editor_notify.lua b/lua/plugins/editor_notify.lua new file mode 100644 index 0000000..4ca989a --- /dev/null +++ b/lua/plugins/editor_notify.lua @@ -0,0 +1,27 @@ +return { + "rcarriga/nvim-notify", + -- dependencies = { "nvim-telescope/telescope.nvim", optional = true }, + lazy = false, + priority = 999, + opts = { + top_down = false, + timeout = 3000, + }, + config = function(_, opts) + require("notify").setup(opts) + vim.notify = require("notify") + + -- TODO move to telescope instead... + -- if package.loaded["telescope"] then + -- require("telescope").load_extension("notify") + -- require("util").keymaps({ + -- { + -- "fn", + -- "Telescope notify", + -- desc = "Telescope search notifications", + -- mode = { "n", "v", "x" }, + -- }, + -- }) + -- end + end, +} diff --git a/lua/plugins/editor_smooth_scroll.lua b/lua/plugins/editor_smooth_scroll.lua new file mode 100644 index 0000000..21cdc71 --- /dev/null +++ b/lua/plugins/editor_smooth_scroll.lua @@ -0,0 +1,15 @@ +return { + -- Smooth scrolling + "declancm/cinnamon.nvim", + event = "VeryLazy", + opts = { + extra_keymaps = true, + extended_keymaps = true, + -- override_keymaps = true, + max_length = 300, + default_delay = 2, + }, + config = function(_, opts) + require("cinnamon").setup(opts) + end, +} diff --git a/lua/plugins/catppuccin.lua b/lua/plugins/editor_theme_catppuccin.lua similarity index 91% rename from lua/plugins/catppuccin.lua rename to lua/plugins/editor_theme_catppuccin.lua index 8568992..d80aecc 100644 --- a/lua/plugins/catppuccin.lua +++ b/lua/plugins/editor_theme_catppuccin.lua @@ -1,5 +1,8 @@ return { "catppuccin/nvim", + -- load theme right away + lazy = false, + priority = 100, opts = { flavour = "mocha", -- latte, frappe, macchiato, mocha (default) color_overrides = {