From 136d75b54343c03f08c356d796d00349894d8c73 Mon Sep 17 00:00:00 2001 From: Solomon Laing Date: Fri, 1 Dec 2023 18:53:11 +1030 Subject: [PATCH] updates to integrate with code better --- .config/nvim/init.lua | 15 +- .config/nvim/lua/lazyvim/config/init.lua | 36 +- .config/nvim/lua/lazyvim/init.lua | 42 +- .config/nvim/lua/lazyvim/plugins/cmp.lua | 141 ++++-- .config/nvim/lua/lazyvim/plugins/utility.lua | 400 +++++++-------- .config/nvim/lua/lazyvim/plugins/whichkey.lua | 462 +++++++++--------- .config/nvim/lua/lazyvim/utils/init.lua | 198 ++++---- 7 files changed, 670 insertions(+), 624 deletions(-) diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 60c394e..1cdf6bf 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,2 +1,13 @@ -require("lazyvim") -- my config based on folkes LazyVim starter --- require("chris") -- my config based on Christian Chiarullis work +if not vim.g.vscode then + require("lazyvim") -- my config based on folkes LazyVim starter + -- require("chris") -- my config based on Christian Chiarullis work + return +end + +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +-- Add some vscode specific keymaps +vim.keymap.set("n", "", "Find") +vim.keymap.set("n", "/", [[call VSCodeNotify('workbench.action.findInFiles')]]) +vim.keymap.set("n", "ss", [[call VSCodeNotify('workbench.action.gotoSymbol')]]) diff --git a/.config/nvim/lua/lazyvim/config/init.lua b/.config/nvim/lua/lazyvim/config/init.lua index 981710f..940dfac 100644 --- a/.config/nvim/lua/lazyvim/config/init.lua +++ b/.config/nvim/lua/lazyvim/config/init.lua @@ -1,27 +1,27 @@ local M = {} local function load(name) - local Util = require("lazy.core.util") - -- always load lazyvim, then user file - for _, mod in ipairs({ "lazyvim.config." .. name, "config." .. name }) do - Util.try(function() - require(mod) - end, { - msg = "Failed loading " .. mod, - on_error = function(msg) - local modpath = require("lazy.core.cache").find(mod) - if modpath then - Util.error(msg) - end - end, - }) - end + local Util = require("lazy.core.util") + -- always load lazyvim, then user file + for _, mod in ipairs({ "lazyvim.config." .. name, "config." .. name }) do + Util.try(function() + require(mod) + end, { + msg = "Failed loading " .. mod, + on_error = function(msg) + local modpath = require("lazy.core.cache").find(mod) + if modpath then + Util.error(msg) + end + end, + }) + end end M.setup = function() - load("options") - load("autocmds") - load("keymaps") + load("options") + load("autocmds") + load("keymaps") end return M diff --git a/.config/nvim/lua/lazyvim/init.lua b/.config/nvim/lua/lazyvim/init.lua index 313327a..05b3376 100644 --- a/.config/nvim/lua/lazyvim/init.lua +++ b/.config/nvim/lua/lazyvim/init.lua @@ -1,14 +1,14 @@ local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.loop.fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", - lazypath, - }) + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", + lazypath, + }) end -- map leader and register keymap for Lazy. @@ -20,24 +20,10 @@ vim.opt.rtp:prepend(vim.env.LAZY or lazypath) require("lazyvim.config").setup() -if not vim.g.vscode then - require("lazy").setup({ - spec = "lazyvim.plugins", - defaults = { lazy = true, version = false }, - checker = { enabled = true }, - }) -end +require("lazy").setup({ + spec = "lazyvim.plugins", + defaults = { lazy = true, version = false }, + checker = { enabled = true }, +}) --- This might not be best, but it allows for easy resetting -ColorMe = function() - local colorscheme = "gruvbox-material" - - local okay, _ = pcall(vim.cmd, "colorscheme " .. colorscheme) - - if not okay then - vim.notify("Colorscheme " .. colorscheme .. " not found!") - vim.cmd("colorsheme habamax") - end -end - -ColorMe() +require("lazyvim.utils").setColorscheme() diff --git a/.config/nvim/lua/lazyvim/plugins/cmp.lua b/.config/nvim/lua/lazyvim/plugins/cmp.lua index 491330e..370f8a2 100644 --- a/.config/nvim/lua/lazyvim/plugins/cmp.lua +++ b/.config/nvim/lua/lazyvim/plugins/cmp.lua @@ -1,56 +1,89 @@ return { - { - "hrsh7th/nvim-cmp", - event = "InsertEnter", - dependencies = { - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-path", - "hrsh7th/cmp-emoji", - "hrsh7th/cmp-buffer", - "saadparwaiz1/cmp_luasnip", - }, - config = function() - local cmp = require("cmp") - cmp.setup({ - completion = { - completeopt = "menu,menuone,noinsert", - }, - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.abort(), - [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), - [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), - }), - sources = cmp.config.sources({ - { name = "nvim_lsp" }, - { name = "luasnip" }, - { name = "path" }, - { name = "emoji" }, - { name = "buffer" }, - }), - formatting = { - format = function(_, item) - local icons = require("lazyvim.config.icons").kind - if icons[item.kind] then - item.kind = icons[item.kind] .. " " .. item.kind - end - return item - end, - }, - experimental = { - ghost_text = { - hl_group = "LspCodeLens", - }, - }, - }) - end, - }, + { + "hrsh7th/nvim-cmp", + event = "InsertEnter", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-path", + "hrsh7th/cmp-emoji", + "hrsh7th/cmp-buffer", + "saadparwaiz1/cmp_luasnip", + { + "zbirenbaum/copilot-cmp", + dependencies = "copilot.lua", + opts = {}, + config = function(_, opts) + local copilot_cmp = require("copilot_cmp") + copilot_cmp.setup(opts) + -- attach cmp source whenever copilot attaches + -- fixes lazy-loading issues with the copilot cmp source + require("lazyvim.utils").on_attach(function(client) + if client.name == "copilot" then + copilot_cmp._on_insert_enter({}) + end + end) + end, + }, + }, + config = function() + local cmp = require("cmp") + cmp.setup({ + completion = { + completeopt = "menu,menuone,noinsert", + }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), + [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "path" }, + { name = "emoji" }, + { name = "buffer" }, + { name = "copilot" }, + }), + formatting = { + format = function(_, item) + local icons = require("lazyvim.config.icons").kind + if icons[item.kind] then + item.kind = icons[item.kind] .. " " .. item.kind + end + return item + end, + }, + experimental = { + ghost_text = { + hl_group = "LspCodeLens", + }, + }, + }) + end, + }, + { + "zbirenbaum/copilot-cmp", + dependencies = "copilot.lua", + opts = {}, + config = function(_, opts) + local copilot_cmp = require("copilot_cmp") + copilot_cmp.setup(opts) + -- attach cmp source whenever copilot attaches + -- fixes lazy-loading issues with the copilot cmp source + require("lazyvim.utils").on_attach(function(client) + if client.name == "copilot" then + copilot_cmp._on_insert_enter({}) + end + end) + end, + } } diff --git a/.config/nvim/lua/lazyvim/plugins/utility.lua b/.config/nvim/lua/lazyvim/plugins/utility.lua index cdfd9f6..6cb05bf 100644 --- a/.config/nvim/lua/lazyvim/plugins/utility.lua +++ b/.config/nvim/lua/lazyvim/plugins/utility.lua @@ -1,212 +1,212 @@ local icons = require("lazyvim.config.icons") return { - { - "nvim-lua/plenary.nvim", - }, - { - "RRethy/vim-illuminate", - event = "BufReadPost", - config = function() - require("illuminate").configure({ delay = 200 }) - end, + { + "nvim-lua/plenary.nvim", + }, + { + "RRethy/vim-illuminate", + event = "BufReadPost", + config = function() + require("illuminate").configure({ delay = 200 }) + end, -- stylua: ignore keys = { { "]]", function() require("illuminate").goto_next_reference(false) end, desc = "Next Reference", }, { "[[", function() require("illuminate").goto_prev_reference(false) end, desc = "Prev Reference" }, }, - }, - { - "nvim-lua/popup.nvim", - }, - { - "folke/neodev.nvim", - }, - -- { - -- "rcarriga/nvim-notify", - -- opts = { - -- -- Animation style (see below for details) - -- stages = "static", - -- - -- -- Render function for notifications. See notify-render() - -- render = "default", - -- - -- -- Default timeout for notifications - -- timeout = 2000, - -- - -- -- For stages that change opacity this is treated as the highlight behind the window - -- -- Set this to either a highlight group or an RGB hex value e.g. "#000000" - -- background_colour = "Normal", - -- - -- -- Minimum width for notification windows - -- minimum_width = 10, - -- - -- -- Icons for the different levels - -- icons = { - -- ERROR = icons.diagnostics.Error, - -- WARN = icons.diagnostics.Warning, - -- INFO = icons.diagnostics.Information, - -- DEBUG = icons.ui.Bug, - -- TRACE = icons.ui.Pencil, - -- }, - -- }, - -- }, - { - "echasnovski/mini.bufremove", - event = "VeryLazy", + }, + { + "nvim-lua/popup.nvim", + }, + { + "folke/neodev.nvim", + }, + -- { + -- "rcarriga/nvim-notify", + -- opts = { + -- -- Animation style (see below for details) + -- stages = "static", + -- + -- -- Render function for notifications. See notify-render() + -- render = "default", + -- + -- -- Default timeout for notifications + -- timeout = 2000, + -- + -- -- For stages that change opacity this is treated as the highlight behind the window + -- -- Set this to either a highlight group or an RGB hex value e.g. "#000000" + -- background_colour = "Normal", + -- + -- -- Minimum width for notification windows + -- minimum_width = 10, + -- + -- -- Icons for the different levels + -- icons = { + -- ERROR = icons.diagnostics.Error, + -- WARN = icons.diagnostics.Warning, + -- INFO = icons.diagnostics.Information, + -- DEBUG = icons.ui.Bug, + -- TRACE = icons.ui.Pencil, + -- }, + -- }, + -- }, + { + "echasnovski/mini.bufremove", + event = "VeryLazy", -- stylua: ignore keys = { - { "bd", function() require("mini.bufremove").delete(0, false) end, desc = "Delete Buffer" }, - { "bD", function() require("mini.bufremove").delete(0, true) end, desc = "Delete Buffer (Force)" }, + { "bd", function() require("mini.bufremove").delete(0, false) end, desc = "Delete Buffer" }, + { "bD", function() require("mini.bufremove").delete(0, true) end, desc = "Delete Buffer (Force)" }, }, - }, - -- { - -- "ghillb/cybu.nvim", - -- event = "VeryLazy", - -- keys = { - -- { "bl", "CybuNext", desc = "Next Buffer" }, - -- { "bh", "CybuPrev", desc = "Prev Buffer" }, - -- }, - -- opts = { - -- position = { - -- relative_to = "win", -- win, editor, cursor - -- anchor = "topright", -- topleft, topcenter, topright, - -- -- centerleft, center, centerright, - -- -- bottomleft, bottomcenter, bottomright - -- -- vertical_offset = 10, -- vertical offset from anchor in lines - -- -- horizontal_offset = 0, -- vertical offset from anchor in columns - -- -- max_win_height = 5, -- height of cybu window in lines - -- -- max_win_width = 0.5, -- integer for absolute in columns - -- -- float for relative to win/editor width - -- }, - -- display_time = 1750, -- time the cybu window is displayed - -- style = { - -- separator = " ", -- string used as separator - -- prefix = "…", -- string used as prefix for truncated paths - -- padding = 1, -- left & right padding in number of spaces - -- hide_buffer_id = true, - -- devicons = { - -- enabled = true, -- enable or disable web dev icons - -- colored = true, -- enable color for web dev icons - -- }, - -- }, - -- }, - -- }, - { - "mbbill/undotree", - cmd = { "UndotreeToggle" }, - }, - { - "MunifTanjim/nui.nvim", - }, - { - "kyazdani42/nvim-web-devicons", - }, - { - "lukas-reineke/indent-blankline.nvim", - opts = {}, - }, - { - "windwp/nvim-autopairs", - event = "VeryLazy", - opts = { - disable_filetype = { "TelescopePrompt", "spectre_panel" }, - ignored_next_char = "[%w%.*]", -- don't place autopairs when cursor sits infront of any character. - }, - config = function(_, opts) - require("nvim-autopairs").setup(opts) - end, - }, - { - "preservim/vim-markdown", - }, - { - "nacro90/numb.nvim", - event = "BufEnter", - config = function() - require("numb").setup({ - show_numbers = true, -- enable 'number' for the window while peeking - show_cursorline = true, -- enable 'cursorline' for window wdile peeking - }) - end, - }, - { - "junegunn/vim-slash", - }, - { - "folke/zen-mode.nvim", - cmd = { "ZenMode" }, - config = function() - require("zen-mode").setup({ - window = { - backdrop = 1, - height = 0.9, - width = 80, - options = { - signcolumn = "no", - number = false, - relativenumber = false, - cursorline = true, - cursorcolumn = false, -- disable cursor column - }, - }, - plugins = { - gitsigns = { enabled = false }, - tmux = { enabled = false }, - twilight = { enabled = false }, - }, - on_open = function() - vim.g.cmp_active = false - vim.cmd([[LspStop]]) - vim.opt.sidescrolloff = 0 - end, - on_close = function() - vim.g.cmp_active = true - vim.cmd([[LspStart]]) - vim.opt.sidescrolloff = 8 - end, - }) - end, - }, - { - "echasnovski/mini.surround", - keys = { "gz" }, - opts = { - mappings = { - add = "gza", -- Add surrounding in Normal and Visual modes - delete = "gzd", -- Delete surrounding - find = "gzf", -- Find surrounding (to the right) - find_left = "gzF", -- Find surrounding (to the left) - highlight = "gzh", -- Highlight surrounding - replace = "gzr", -- Replace surrounding - update_n_lines = "gzn", -- Update `n_lines` - }, - }, - config = function(_, opts) - -- use gz mappings instead of s to prevent conflict with leap - require("mini.surround").setup(opts) - end, - }, - { - "danymat/neogen", - event = "BufEnter", - config = function() - require("neogen").setup({ - enabled = true, - input_after_comment = true, - }) - end, - }, - { - "SmiteshP/nvim-navic", - init = function() - vim.g.navic_silence = true - require("lazyvim.utils").on_attach(function(client, buffer) - if client.server_capabilities.documentSymbolProvider then - require("nvim-navic").attach(client, buffer) - end - end) - end, - opts = { separator = " ", highlight = true, depth_limit = 5 }, - }, + }, + -- { + -- "ghillb/cybu.nvim", + -- event = "VeryLazy", + -- keys = { + -- { "bl", "CybuNext", desc = "Next Buffer" }, + -- { "bh", "CybuPrev", desc = "Prev Buffer" }, + -- }, + -- opts = { + -- position = { + -- relative_to = "win", -- win, editor, cursor + -- anchor = "topright", -- topleft, topcenter, topright, + -- -- centerleft, center, centerright, + -- -- bottomleft, bottomcenter, bottomright + -- -- vertical_offset = 10, -- vertical offset from anchor in lines + -- -- horizontal_offset = 0, -- vertical offset from anchor in columns + -- -- max_win_height = 5, -- height of cybu window in lines + -- -- max_win_width = 0.5, -- integer for absolute in columns + -- -- float for relative to win/editor width + -- }, + -- display_time = 1750, -- time the cybu window is displayed + -- style = { + -- separator = " ", -- string used as separator + -- prefix = "…", -- string used as prefix for truncated paths + -- padding = 1, -- left & right padding in number of spaces + -- hide_buffer_id = true, + -- devicons = { + -- enabled = true, -- enable or disable web dev icons + -- colored = true, -- enable color for web dev icons + -- }, + -- }, + -- }, + -- }, + { + "mbbill/undotree", + cmd = { "UndotreeToggle" }, + }, + { + "MunifTanjim/nui.nvim", + }, + { + "kyazdani42/nvim-web-devicons", + }, + { + "lukas-reineke/indent-blankline.nvim", + opts = {}, + }, + { + "windwp/nvim-autopairs", + event = "VeryLazy", + opts = { + disable_filetype = { "TelescopePrompt", "spectre_panel" }, + ignored_next_char = "[%w%.*]", -- don't place autopairs when cursor sits infront of any character. + }, + config = function(_, opts) + require("nvim-autopairs").setup(opts) + end, + }, + { + "preservim/vim-markdown", + }, + { + "nacro90/numb.nvim", + event = "BufEnter", + config = function() + require("numb").setup({ + show_numbers = true, -- enable 'number' for the window while peeking + show_cursorline = true, -- enable 'cursorline' for window wdile peeking + }) + end, + }, + { + "junegunn/vim-slash", + }, + { + "folke/zen-mode.nvim", + cmd = { "ZenMode" }, + config = function() + require("zen-mode").setup({ + window = { + backdrop = 1, + height = 0.9, + width = 80, + options = { + signcolumn = "no", + number = false, + relativenumber = false, + cursorline = true, + cursorcolumn = false, -- disable cursor column + }, + }, + plugins = { + gitsigns = { enabled = false }, + tmux = { enabled = false }, + twilight = { enabled = false }, + }, + on_open = function() + vim.g.cmp_active = false + vim.cmd([[LspStop]]) + vim.opt.sidescrolloff = 0 + end, + on_close = function() + vim.g.cmp_active = true + vim.cmd([[LspStart]]) + vim.opt.sidescrolloff = 8 + end, + }) + end, + }, + { + "echasnovski/mini.surround", + keys = { "gz" }, + opts = { + mappings = { + add = "gza", -- Add surrounding in Normal and Visual modes + delete = "gzd", -- Delete surrounding + find = "gzf", -- Find surrounding (to the right) + find_left = "gzF", -- Find surrounding (to the left) + highlight = "gzh", -- Highlight surrounding + replace = "gzr", -- Replace surrounding + update_n_lines = "gzn", -- Update `n_lines` + }, + }, + config = function(_, opts) + -- use gz mappings instead of s to prevent conflict with leap + require("mini.surround").setup(opts) + end, + }, + { + "danymat/neogen", + event = "BufEnter", + config = function() + require("neogen").setup({ + enabled = true, + input_after_comment = true, + }) + end, + }, + { + "SmiteshP/nvim-navic", + init = function() + vim.g.navic_silence = true + require("lazyvim.utils").on_attach(function(client, buffer) + if client.server_capabilities.documentSymbolProvider then + require("nvim-navic").attach(client, buffer) + end + end) + end, + opts = { separator = " ", highlight = true, depth_limit = 5 }, + }, } diff --git a/.config/nvim/lua/lazyvim/plugins/whichkey.lua b/.config/nvim/lua/lazyvim/plugins/whichkey.lua index 6ec2b6a..d337655 100644 --- a/.config/nvim/lua/lazyvim/plugins/whichkey.lua +++ b/.config/nvim/lua/lazyvim/plugins/whichkey.lua @@ -1,247 +1,251 @@ return { - { - "folke/which-key.nvim", - event = "VeryLazy", - opts = { - plugins = { - -- marks = true, -- shows a list of your marks on ' and ` - -- registers = true, -- shows your registers on " in NORMAL or in INSERT mode - spelling = { - enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions - suggestions = 20, -- how many suggestions should be shown in the list? - }, - }, - key_labels = { - -- override the label used to display some keys. It doesn't effect WK in any other way. - [""] = "SPC", - }, - icons = { - breadcrumb = "»", -- symbol used in the command line area that shows your active key combo - separator = "➜", -- symbol used between a key and it's label - group = "+", -- symbol prepended to a group - }, - popup_mappings = { - scroll_down = "", -- binding to scroll down inside the popup - scroll_up = "", -- binding to scroll up inside the popup - }, - window = { - border = "rounded", -- none, single, double, shadow - position = "bottom", -- bottom, top - margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left] - padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left] - winblend = 0, - }, - layout = { - height = { min = 4, max = 25 }, -- min and max height of the columns - width = { min = 20, max = 50 }, -- min and max width of the columns - spacing = 3, -- spacing between columns - align = "center", -- align columns left, center or right - }, - }, - config = function(_, opts) - local whichkey = require("which-key") - local utils = require("lazyvim.utils") + { + "folke/which-key.nvim", + event = "VeryLazy", + opts = { + plugins = { + -- marks = true, -- shows a list of your marks on ' and ` + -- registers = true, -- shows your registers on " in NORMAL or in INSERT mode + spelling = { + enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions + suggestions = 20, -- how many suggestions should be shown in the list? + }, + }, + key_labels = { + -- override the label used to display some keys. It doesn't effect WK in any other way. + [""] = "SPC", + }, + icons = { + breadcrumb = "»", -- symbol used in the command line area that shows your active key combo + separator = "➜", -- symbol used between a key and it's label + group = "+", -- symbol prepended to a group + }, + popup_mappings = { + scroll_down = "", -- binding to scroll down inside the popup + scroll_up = "", -- binding to scroll up inside the popup + }, + window = { + border = "rounded", -- none, single, double, shadow + position = "bottom", -- bottom, top + margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left] + padding = { 2, 2, 2, 2 }, -- extra window padding [top, right, bottom, left] + winblend = 0, + }, + layout = { + height = { min = 4, max = 25 }, -- min and max height of the columns + width = { min = 20, max = 50 }, -- min and max width of the columns + spacing = 3, -- spacing between columns + align = "center", -- align columns left, center or right + }, + }, + config = function(_, opts) + local whichkey = require("which-key") + local utils = require("lazyvim.utils") - whichkey.setup(opts) + whichkey.setup(opts) - local leader_opts = { - mode = { "n", "v" }, -- NORMAL/VISUAL mode - buffer = nil, -- Global mappings - prefix = "", - silent = true, -- use 'silent' - noremap = true, -- use 'noremap' - nowait = true, -- use 'nowait' - } + local leader_opts = { + mode = { "n", "v" }, -- NORMAL/VISUAL mode + buffer = nil, -- Global mappings + prefix = "", + silent = true, -- use 'silent' + noremap = true, -- use 'noremap' + nowait = true, -- use 'nowait' + } - whichkey.register({ - mode = { "n", "v" }, - ["g"] = { name = "+goto" }, - ["m"] = { name = "+harpoon" }, - ["]"] = { name = "+next" }, - ["["] = { name = "+previous" }, - }) + whichkey.register({ + mode = { "n", "v" }, + ["g"] = { name = "+goto" }, + ["m"] = { name = "+harpoon" }, + ["]"] = { name = "+next" }, + ["["] = { name = "+previous" }, + }) - local leader_mappings = { - b = { name = "+buffer" }, - r = { name = "+replace" }, - s = { name = "+search" }, - h = { name = "+help" }, - gh = { name = "+hunks" }, - t = { name = "+todo" }, - N = { name = "+noice" }, + local leader_mappings = { + b = { name = "+buffer" }, + r = { name = "+replace" }, + s = { name = "+search" }, + h = { name = "+help" }, + gh = { name = "+hunks" }, + t = { name = "+todo" }, + N = { name = "+noice" }, - e = { "NvimTreeToggle", "Explorer" }, - Z = { "ZenMode", "Zen" }, - u = { "UndotreeToggle", "Undo Tree" }, - ["'"] = { "close", "Close split" }, + Z = { "ZenMode", "Zen" }, + u = { "UndotreeToggle", "Undo Tree" }, + ["'"] = { "close", "Close split" }, - n = { - name = "+neorg", - n = { "Neorg", "Open Neorg" }, - c = { "Neorg toggle-concealer", "Toggle Concealer" }, - t = { "Neorg tangle current-file", "Tangle Current File" }, - j = { "Neorg journal", "Open Neorg Journal" }, - w = { - function() - require("lazyvim.utils.neorg").workspace_switcher() - end, - "Workspace Switcher", - }, - }, + c = { + name = "+copilot", + c = { "Copilot", "Start Copilot" }, + }, - f = { - name = "+file", - n = { "enew", "New File" }, - }, + n = { + name = "+neorg", + n = { "Neorg", "Open Neorg" }, + c = { "Neorg toggle-concealer", "Toggle Concealer" }, + t = { "Neorg tangle current-file", "Tangle Current File" }, + j = { "Neorg journal", "Open Neorg Journal" }, + w = { + function() + require("lazyvim.utils.neorg").workspace_switcher() + end, + "Workspace Switcher", + }, + }, - q = { - name = "+quit", - q = { "wq", "Save and Quit Current" }, - a = { "wqa", "Save and Quit all" }, - }, + f = { + name = "+file", + n = { "enew", "New File" }, + }, - l = { - name = "+lsp", - l = { "lopen", "Open Location List" }, - q = { "copen", "Open Quickfix List" }, - }, + q = { + name = "+quit", + q = { "wq", "Save and Quit Current" }, + a = { "wqa", "Save and Quit all" }, + }, - c = { - name = "Compiler", - c = { "w! | !compiler %", "Compile File" }, - b = { "w! | !pandoc % -t beamer -o presentation.pdf", "Beamer Presentation" }, - p = { "!opout %", "Preview Document" }, - }, + l = { + name = "+lsp", + l = { "lopen", "Open Location List" }, + q = { "copen", "Open Quickfix List" }, + }, - w = { - name = "+window", - w = { "p", "Other window" }, - d = { "c", "Delete Window" }, - h = { "s", "Split Below" }, - v = { "v", "Split Right" }, - }, + C = { + name = "+compiler", + c = { "w! | !compiler %", "Compile File" }, + b = { "w! | !pandoc % -t beamer -o presentation.pdf", "Beamer Presentation" }, + p = { "!opout %", "Preview Document" }, + }, - o = { - name = "+option", - f = { - function() - require("lazyvim.plugins.lsp.format").toggle() - end, - "Toggle format on save", - }, - s = { - function() - utils.toggle("spell") - end, - "Toggle spelling", - }, - w = { - function() - utils.toggle("wrap") - end, - "Toggle word wrap", - }, - n = { - function() - utils.toggle("relativenumber", true) - utils.toggle("number") - end, - "Toggle line numbers", - }, - d = { - function() - utils.toggle_diagnostics() - end, - "Toggle Diagnostics", - }, - c = { - function() - local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3 - utils.toggle("conceallevel", false, { 0, conceallevel }) - end, - "Toggle conceal", - }, - h = { - function() - local sidescrolloff = vim.o.sidescrolloff > 0 and vim.o.sidescrolloff or 8 - utils.toggle("sidescrolloff", false, { 0, sidescrolloff }) - end, - "Toggle side scroll off", - }, - }, + w = { + name = "+window", + w = { "p", "Other window" }, + d = { "c", "Delete Window" }, + h = { "s", "Split Below" }, + v = { "v", "Split Right" }, + }, - g = { - name = "+git", - g = { - function() - utils.float_term({ "lazygit" }) - end, - "Lazygit (cwd)", - }, - G = { - function() - utils.float_term({ "lazygit" }, { cwd = utils.get_root() }) - end, - "Lazygit (root dir)", - }, - }, + o = { + name = "+option", + f = { + function() + require("lazyvim.plugins.lsp.format").toggle() + end, + "Toggle format on save", + }, + s = { + function() + utils.toggle("spell") + end, + "Toggle spelling", + }, + w = { + function() + utils.toggle("wrap") + end, + "Toggle word wrap", + }, + n = { + function() + utils.toggle("relativenumber", true) + utils.toggle("number") + end, + "Toggle line numbers", + }, + d = { + function() + utils.toggle_diagnostics() + end, + "Toggle Diagnostics", + }, + c = { + function() + local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3 + utils.toggle("conceallevel", false, { 0, conceallevel }) + end, + "Toggle conceal", + }, + h = { + function() + local sidescrolloff = vim.o.sidescrolloff > 0 and vim.o.sidescrolloff or 8 + utils.toggle("sidescrolloff", false, { 0, sidescrolloff }) + end, + "Toggle side scroll off", + }, + }, - z = { - name = "+zk", - I = { "ZkIndex", "Index Notebook" }, - n = { - "+new", - n = { "ZkNew { title = vim.fn.input('Title: ') }", "New Note (zk dir)" }, - N = { - "ZkNew { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }", - "New Note (cwd)", - }, - t = { - "ZkNewFromTitleSelection { title = vim.fn.input('Title: ') }", - "New, Title from selection (zk dir)", - }, - T = { - "ZkNewFromTitleSelection { dir = vim.fn.expand('%:p:h') title = vim.fn.input('Title: ') }", - "New, Title from selection (cwd)", - }, - c = { - "ZkNewFromContentSelection { title = vim.fn.input('Title: ') }", - "New, Content from selection (zk dir)", - }, - C = { - "ZkNewFromContentSelection { dir = vim.fn.expand('%:p:h') title = vim.fn.input('Title: ') }", - "New, Content from selection (cwd)", - }, - }, - c = { "ZkCd", "cd 'root'" }, - s = { "ZkNotes", "List Notes" }, - b = { "ZkBacklinks", "Backlinks" }, - l = { "ZkLinks", "Links" }, - j = { - "ZkNew { dir = 'journal', date = 'today', title = vim.fn.input('Title: ') }", - "New Journal", - }, - i = { - { "ZkInsertLink", "Insert Link" }, - }, - }, + g = { + name = "+git", + g = { + function() + utils.float_term({ "lazygit" }) + end, + "Lazygit (cwd)", + }, + G = { + function() + utils.float_term({ "lazygit" }, { cwd = utils.get_root() }) + end, + "Lazygit (root dir)", + }, + }, - -- TODO: Add dap back into the project, bashbunni's dotfiles are a good resource. - -- d = { - -- name = "Debug", - -- b = { "lua require'dap'.toggle_breakpoint()", "Breakpoint" }, - -- c = { "lua require'dap'.continue()", "Continue" }, - -- i = { "lua require'dap'.step_into()", "Into" }, - -- o = { "lua require'dap'.step_over()", "Over" }, - -- O = { "lua require'dap'.step_out()", "Out" }, - -- r = { "lua require'dap'.repl.toggle()", "Repl" }, - -- l = { "lua require'dap'.run_last()", "Last" }, - -- u = { "lua require'dapui'.toggle()", "UI" }, - -- x = { "lua require'dap'.terminate()", "Exit" }, - -- }, - } + z = { + name = "+zk", + I = { "ZkIndex", "Index Notebook" }, + n = { + "+new", + n = { "ZkNew { title = vim.fn.input('Title: ') }", "New Note (zk dir)" }, + N = { + "ZkNew { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }", + "New Note (cwd)", + }, + t = { + "ZkNewFromTitleSelection { title = vim.fn.input('Title: ') }", + "New, Title from selection (zk dir)", + }, + T = { + "ZkNewFromTitleSelection { dir = vim.fn.expand('%:p:h') title = vim.fn.input('Title: ') }", + "New, Title from selection (cwd)", + }, + c = { + "ZkNewFromContentSelection { title = vim.fn.input('Title: ') }", + "New, Content from selection (zk dir)", + }, + C = { + "ZkNewFromContentSelection { dir = vim.fn.expand('%:p:h') title = vim.fn.input('Title: ') }", + "New, Content from selection (cwd)", + }, + }, + c = { "ZkCd", "cd 'root'" }, + s = { "ZkNotes", "List Notes" }, + b = { "ZkBacklinks", "Backlinks" }, + l = { "ZkLinks", "Links" }, + j = { + "ZkNew { dir = 'journal', date = 'today', title = vim.fn.input('Title: ') }", + "New Journal", + }, + i = { + { "ZkInsertLink", "Insert Link" }, + }, + }, - whichkey.register(leader_mappings, leader_opts) - end, - }, + -- TODO: Add dap back into the project, bashbunni's dotfiles are a good resource. + -- d = { + -- name = "Debug", + -- b = { "lua require'dap'.toggle_breakpoint()", "Breakpoint" }, + -- c = { "lua require'dap'.continue()", "Continue" }, + -- i = { "lua require'dap'.step_into()", "Into" }, + -- o = { "lua require'dap'.step_over()", "Over" }, + -- O = { "lua require'dap'.step_out()", "Out" }, + -- r = { "lua require'dap'.repl.toggle()", "Repl" }, + -- l = { "lua require'dap'.run_last()", "Last" }, + -- u = { "lua require'dapui'.toggle()", "UI" }, + -- x = { "lua require'dap'.terminate()", "Exit" }, + -- }, + } + + whichkey.register(leader_mappings, leader_opts) + end, + }, } diff --git a/.config/nvim/lua/lazyvim/utils/init.lua b/.config/nvim/lua/lazyvim/utils/init.lua index 87651f6..98c202f 100644 --- a/.config/nvim/lua/lazyvim/utils/init.lua +++ b/.config/nvim/lua/lazyvim/utils/init.lua @@ -4,13 +4,13 @@ M.root_patterns = { ".git", "/lua" } ---@param on_attach fun(client, buffer) function M.on_attach(on_attach) - vim.api.nvim_create_autocmd("LspAttach", { - callback = function(args) - local buffer = args.buf - local client = vim.lsp.get_client_by_id(args.data.client_id) - on_attach(client, buffer) - end, - }) + vim.api.nvim_create_autocmd("LspAttach", { + callback = function(args) + local buffer = args.buf + local client = vim.lsp.get_client_by_id(args.data.client_id) + on_attach(client, buffer) + end, + }) end -- returns the root directory based on: @@ -20,113 +20,125 @@ end -- * root pattern of cwd ---@return string function M.get_root() - ---@type string? - local path = vim.api.nvim_buf_get_name(0) - path = path ~= "" and vim.loop.fs_realpath(path) or nil - ---@type string[] - local roots = {} - if path then - for _, client in pairs(vim.lsp.get_active_clients({ bufnr = 0 })) do - local workspace = client.config.workspace_folders - local paths = workspace - and vim.tbl_map(function(ws) - return vim.uri_to_fname(ws.uri) - end, workspace) - or client.config.root_dir and { client.config.root_dir } - or {} - for _, p in ipairs(paths) do - local r = vim.loop.fs_realpath(p) - if path:find(r, 1, true) then - roots[#roots + 1] = r - end - end - end - end - table.sort(roots, function(a, b) - return #a > #b - end) - ---@type string? - local root = roots[1] - if not root then - path = path and vim.fs.dirname(path) or vim.loop.cwd() - ---@type string? - root = vim.fs.find(M.root_patterns, { path = path, upward = true })[1] - root = root and vim.fs.dirname(root) or vim.loop.cwd() - end - ---@cast root string - return root + ---@type string? + local path = vim.api.nvim_buf_get_name(0) + path = path ~= "" and vim.loop.fs_realpath(path) or nil + ---@type string[] + local roots = {} + if path then + for _, client in pairs(vim.lsp.get_active_clients({ bufnr = 0 })) do + local workspace = client.config.workspace_folders + local paths = workspace + and vim.tbl_map(function(ws) + return vim.uri_to_fname(ws.uri) + end, workspace) + or client.config.root_dir and { client.config.root_dir } + or {} + for _, p in ipairs(paths) do + local r = vim.loop.fs_realpath(p) + if path:find(r, 1, true) then + roots[#roots + 1] = r + end + end + end + end + table.sort(roots, function(a, b) + return #a > #b + end) + ---@type string? + local root = roots[1] + if not root then + path = path and vim.fs.dirname(path) or vim.loop.cwd() + ---@type string? + root = vim.fs.find(M.root_patterns, { path = path, upward = true })[1] + root = root and vim.fs.dirname(root) or vim.loop.cwd() + end + ---@cast root string + return root end ---@param silent boolean? ---@param values? {[1]:any, [2]:any}function function M.toggle(option, silent, values) - if values then - if vim.opt_local[option]:get() == values[1] then - vim.opt_local[option] = values[2] - else - vim.opt_local[option] = values[1] - end - return vim.notify( - "Set " .. option .. " to " .. vim.opt_local[option]:get(), - vim.log.levels.INFO, - { title = "Option" } - ) - end - vim.opt_local[option] = not vim.opt_local[option]:get() - if not silent then - vim.notify( - (vim.opt_local[option]:get() and "Enabled" or "Disabled") .. " " .. option, - vim.log.levels.INFO, - { title = "Option" } - ) - end + if values then + if vim.opt_local[option]:get() == values[1] then + vim.opt_local[option] = values[2] + else + vim.opt_local[option] = values[1] + end + return vim.notify( + "Set " .. option .. " to " .. vim.opt_local[option]:get(), + vim.log.levels.INFO, + { title = "Option" } + ) + end + vim.opt_local[option] = not vim.opt_local[option]:get() + if not silent then + vim.notify( + (vim.opt_local[option]:get() and "Enabled" or "Disabled") .. " " .. option, + vim.log.levels.INFO, + { title = "Option" } + ) + end end local enabled = true function M.toggle_diagnostics() - enabled = not enabled - if enabled then - vim.diagnostic.enable() - vim.notify("Enabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" }) - else - vim.diagnostic.disable() - vim.notify("Disabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" }) - end + enabled = not enabled + if enabled then + vim.diagnostic.enable() + vim.notify("Enabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" }) + else + vim.diagnostic.disable() + vim.notify("Disabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" }) + end end function M.smart_quit() - local bufnr = vim.api.nvim_get_current_buf() - local modified = vim.api.nvim_buf_get_option(bufnr, "modified") - if modified then - vim.ui.input({ - prompt = "You have unsaved changes. Quit anyway? (y/n) ", - }, function(input) - if input == "y" then - vim.cmd("q!") - end - end) - else - vim.cmd("q!") - end + local bufnr = vim.api.nvim_get_current_buf() + local modified = vim.api.nvim_buf_get_option(bufnr, "modified") + if modified then + vim.ui.input({ + prompt = "You have unsaved changes. Quit anyway? (y/n) ", + }, function(input) + if input == "y" then + vim.cmd("q!") + end + end) + else + vim.cmd("q!") + end end function M.isempty(s) - return s == nil or s == "" + return s == nil or s == "" end function M.get_buf_option(opt) - local status_ok, buf_option = pcall(vim.api.nvim_buf_get_option, 0, opt) - if not status_ok then - return nil - else - return buf_option - end + local status_ok, buf_option = pcall(vim.api.nvim_buf_get_option, 0, opt) + if not status_ok then + return nil + else + return buf_option + end end function M.telescope(builtin, opts) - return function() - require("telescope.builtin")[builtin](vim.tbl_deep_extend("force", { cwd = M.get_root() }, opts or {})) - end + return function() + require("telescope.builtin")[builtin](vim.tbl_deep_extend("force", { cwd = M.get_root() }, opts or {})) + end +end + +-- This might not be best, but it allows for easy resetting +function M.setColorscheme(scheme) + local colorscheme = scheme or "gruvbox-material" + + local okay, _ = pcall(vim.cmd, "colorscheme " .. colorscheme) + + if not okay then + vim.notify("Colorscheme " .. colorscheme .. " not found!") + vim.cmd("colorsheme habamax") + end end return M