From d2ab7879342f25db8e7728cd30a95364909f3f2b Mon Sep 17 00:00:00 2001 From: Benjamin Chaussé Date: Wed, 17 Jul 2024 18:01:57 -0400 Subject: Optimize startup time --- lua/core/init.lua | 18 ++++++ lua/plugins/cmp.lua | 1 + lua/plugins/colorscheme.lua | 2 +- lua/plugins/dadbod.lua | 4 ++ lua/plugins/harpoon.lua | 130 +++++++++++++++++++++++++------------------- lua/plugins/lsp.lua | 27 +++++---- 6 files changed, 116 insertions(+), 66 deletions(-) diff --git a/lua/core/init.lua b/lua/core/init.lua index 5326e40..f9caf4a 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -44,6 +44,24 @@ vim.api.nvim_create_autocmd({ "BufWritePre" }, { end, }) +-- Auto cd to git root of project (good for harpoon) +local function is_git_repo() + local git_dir = vim.fn.systemlist("git rev-parse --show-toplevel") + if vim.v.shell_error ~= 0 then + return false + end + return git_dir[1] +end + +local function cd_to_git_root() + local git_root = is_git_repo() + if git_root then + vim.cmd("tcd " .. git_root) + end +end + +cd_to_git_root() + -- Quickly compile and preview files vim.keymap.set("n", "c", "make") vim.keymap.set("n", "o", "!opout %") diff --git a/lua/plugins/cmp.lua b/lua/plugins/cmp.lua index e079910..fc296fa 100644 --- a/lua/plugins/cmp.lua +++ b/lua/plugins/cmp.lua @@ -1,5 +1,6 @@ return { "hrsh7th/nvim-cmp", + event = "InsertEnter", dependencies = { { "hrsh7th/cmp-nvim-lsp" }, { "hrsh7th/cmp-buffer" }, diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua index 5aeec35..60e4fbf 100644 --- a/lua/plugins/colorscheme.lua +++ b/lua/plugins/colorscheme.lua @@ -76,7 +76,7 @@ return { { "neanias/everforest-nvim", version = false, - priority = 1000, + enable = false, config = function() require("everforest").setup({ background = "hard", diff --git a/lua/plugins/dadbod.lua b/lua/plugins/dadbod.lua index 2e71f4a..f3ef317 100644 --- a/lua/plugins/dadbod.lua +++ b/lua/plugins/dadbod.lua @@ -4,4 +4,8 @@ return { "kristijanhusak/vim-dadbod-ui", "kristijanhusak/vim-dadbod-completion", }, + cmd = { + "DBUI", + "DBUIToggle", + }, } diff --git a/lua/plugins/harpoon.lua b/lua/plugins/harpoon.lua index 3fb4661..52d91ba 100644 --- a/lua/plugins/harpoon.lua +++ b/lua/plugins/harpoon.lua @@ -5,59 +5,79 @@ return { "nvim-lua/plenary.nvim", "nvim-telescope/telescope.nvim", }, - config = function() - -- Cd to git root on startup to retain harpoons wherever vim starts - local function is_git_repo() - local git_dir = vim.fn.systemlist("git rev-parse --show-toplevel") - if vim.v.shell_error ~= 0 then - return false - end - return git_dir[1] - end - - local function cd_to_git_root() - local git_root = is_git_repo() - if git_root then - vim.cmd("tcd " .. git_root) - end - end - - cd_to_git_root() - - local harpoon = require("harpoon") - - harpoon:setup() - - -- harpoon keybindings - vim.keymap.set("n", "a", function() - harpoon:list():add() - end) - -- vim.keymap.set("n", "", function() toggle_telescope(harpoon:list()) end, {desc = "Open harpoon window"} ) - vim.keymap.set("n", "", function() - harpoon.ui:toggle_quick_menu(harpoon:list()) - end) - - vim.keymap.set("n", "", function() - harpoon:list():select(1) - end) - vim.keymap.set("n", "", function() - harpoon:list():select(2) - end) - vim.keymap.set("n", "", function() - harpoon:list():select(3) - end) - vim.keymap.set("n", "", function() - harpoon:list():select(4) - end) - vim.keymap.set("n", "", function() - harpoon:list():select(5) - end) - - vim.keymap.set("n", "", function() - harpoon:list():prev() - end) - vim.keymap.set("n", "", function() - harpoon:list():next() - end) - end, + opts = {}, + keys = { + { -- Add Harpoon + "a", + function() + require("harpoon"):list():add() + end, + mode = "n", + desc = "Add Harpoon", + }, + { -- Edit Harpoons + "", + function() + require("harpoon").ui:toggle_quick_menu(require("harpoon"):list()) + end, + mode = "n", + desc = "Edit Harpoons", + }, + { -- Select Harpoon 1 + "", + function() + require("harpoon"):list():select(1) + end, + mode = "n", + desc = "Select Harpoon 1", + }, + { -- Select Harpoon 2 + "", + function() + require("harpoon"):list():select(2) + end, + mode = "n", + desc = "Select Harpoon 2", + }, + { -- Select Harpoon 3 + "", + function() + require("harpoon"):list():select(3) + end, + mode = "n", + desc = "Select Harpoon 3", + }, + { -- Select Harpoon 4 + "", + function() + require("harpoon"):list():select(4) + end, + mode = "n", + desc = "Select Harpoon 4", + }, + { -- Select Harpoon 5 + "", + function() + require("harpoon"):list():select(5) + end, + mode = "n", + desc = "Select Harpoon 5", + }, + { -- Select Previous Harpoon + "", + function() + require("harpoon"):list():prev() + end, + mode = "n", + desc = "Select Previous Harpoon", + }, + { -- Select Next Harpoon + "", + function() + require("harpoon"):list():next() + end, + mode = "n", + desc = "Select Next Harpoon", + }, + }, } diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index 5dc67cb..4a5e6b9 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -1,9 +1,14 @@ return { { - "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", dependencies = { - "williamboman/mason-lspconfig.nvim", + "williamboman/mason.nvim", }, + event = { "BufReadPre", "BufNewFile" }, + }, + { + "williamboman/mason.nvim", + cmd = "Mason", config = function() local mason = require("mason") local mlsp = require("mason-lspconfig") @@ -40,23 +45,24 @@ return { }, { "neovim/nvim-lspconfig", - veryLazy = true, + event = { "BufReadPre", "BufNewFile" }, dependencies = { "hrsh7th/nvim-cmp", "hrsh7th/cmp-nvim-lsp", "nvim-telescope/telescope.nvim", }, config = function() - -- Use icons in the sidebar - local signs = { Error = "", Warn = "", Hint = "󰈈", Info = "" } - for type, icon in pairs(signs) do - local hl = "DiagnosticSign" .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) - end -- Hide inline virtual text and use only the icons for debbuging/tips vim.diagnostic.config({ virtual_text = false, - signs = true, + signs = { + text = { + [vim.diagnostic.severity.ERROR] = "", + [vim.diagnostic.severity.WARN] = "", + [vim.diagnostic.severity.HINT] = "󰈈", + [vim.diagnostic.severity.INFO] = "", + }, + }, underline = true, }) @@ -220,6 +226,7 @@ return { }, { "zapling/mason-conform.nvim", + event = { "BufReadPre", "BufNewFile" }, dependencies = { "williamboman/mason.nvim", "stevearc/conform.nvim", -- cgit v1.2.3