fix keymaps, lazy load pass trying to reduce startup time, shaved ~35ms

This commit is contained in:
Martin Larsson 2026-04-12 02:31:00 +02:00
parent 8b38a13192
commit f5efed19c7
11 changed files with 295 additions and 218 deletions

View file

@ -35,7 +35,8 @@ local function toggle_terminal()
vim.api.nvim_command("startinsert") vim.api.nvim_command("startinsert")
end end
vim.keymap.set("n", "<leader>t", function()
utils.set_keymap_list({{ "<leader>t", function()
toggle_terminal() toggle_terminal()
require("window_management").autosize_windows() require("window_management").autosize_windows()
end) end }})

View file

@ -30,10 +30,6 @@
"rev": "8b54c59bcb23366645ae10edca6edfb9d3a0853e", "rev": "8b54c59bcb23366645ae10edca6edfb9d3a0853e",
"src": "https://github.com/b0o/incline.nvim" "src": "https://github.com/b0o/incline.nvim"
}, },
"live-rename.nvim": {
"rev": "3a3cddf23b89a17992f9ca67afc5858077769462",
"src": "https://github.com/saecki/live-rename.nvim"
},
"logger.nvim": { "logger.nvim": {
"rev": "63dd10c9b9a159fd6cfe08435d9606384ff103c5", "rev": "63dd10c9b9a159fd6cfe08435d9606384ff103c5",
"src": "https://github.com/rmagatti/logger.nvim" "src": "https://github.com/rmagatti/logger.nvim"
@ -63,7 +59,7 @@
"src": "https://github.com/MunifTanjim/nui.nvim" "src": "https://github.com/MunifTanjim/nui.nvim"
}, },
"nvim-dap": { "nvim-dap": {
"rev": "2a8799ad91a1495c6bdf753f9b2179b3ff0f5bba", "rev": "45a69eba683a2c448dd9ecfc4de89511f0646b5f",
"src": "https://github.com/mfussenegger/nvim-dap" "src": "https://github.com/mfussenegger/nvim-dap"
}, },
"nvim-dap-go": { "nvim-dap-go": {
@ -75,7 +71,7 @@
"src": "https://github.com/LiadOz/nvim-dap-repl-highlights" "src": "https://github.com/LiadOz/nvim-dap-repl-highlights"
}, },
"nvim-dap-ui": { "nvim-dap-ui": {
"rev": "f5b6673f374626515401c5bc51b005f784a4f252", "rev": "1a66cabaa4a4da0be107d5eda6d57242f0fe7e49",
"src": "https://github.com/rcarriga/nvim-dap-ui" "src": "https://github.com/rcarriga/nvim-dap-ui"
}, },
"nvim-dap-virtual-text": { "nvim-dap-virtual-text": {
@ -94,6 +90,10 @@
"rev": "57e1fa7638e753efbd62e5aa53b82b08a80fed7e", "rev": "57e1fa7638e753efbd62e5aa53b82b08a80fed7e",
"src": "https://github.com/LarssonMartin1998/nvim-norrsken" "src": "https://github.com/LarssonMartin1998/nvim-norrsken"
}, },
"nvim-rephrase": {
"rev": "3391726e2768fd241e89d032f8523ea053099387",
"src": "git@github.com:LarssonMartin1998/nvim-rephrase"
},
"nvim-treesitter": { "nvim-treesitter": {
"rev": "7caec274fd19c12b55902a5b795100d21531391f", "rev": "7caec274fd19c12b55902a5b795100d21531391f",
"src": "https://github.com/nvim-treesitter/nvim-treesitter", "src": "https://github.com/nvim-treesitter/nvim-treesitter",

View file

@ -3,47 +3,27 @@ local function gh(repo)
end end
vim.pack.add({ vim.pack.add({
-- Mini suite -- Foundational
gh("LarssonMartin1998/mini.nvim"), gh("LarssonMartin1998/mini.nvim"),
{ src = gh("nvim-treesitter/nvim-treesitter"), version = "main" },
-- Colorscheme -- Colorscheme
gh("rktjmp/lush.nvim"), gh("rktjmp/lush.nvim"),
gh("LarssonMartin1998/nvim-norrsken"), gh("LarssonMartin1998/nvim-norrsken"),
-- Treesitter
{ src = gh("nvim-treesitter/nvim-treesitter"), version = "main" },
gh("nvim-treesitter/nvim-treesitter-context"),
gh("nvim-treesitter/nvim-treesitter-textobjects"),
-- Completion
gh("rafamadriz/friendly-snippets"),
{ src = gh("L3MON4D3/LuaSnip"), version = vim.version.range("2.x") },
{ src = gh("saghen/blink.cmp"), version = vim.version.range("1.x") },
-- UI -- UI
gh("nvim-lualine/lualine.nvim"), gh("nvim-lualine/lualine.nvim"),
gh("b0o/incline.nvim"), gh("b0o/incline.nvim"),
gh("kosayoda/nvim-lightbulb"),
gh("rachartier/tiny-glimmer.nvim"),
gh("rachartier/tiny-inline-diagnostic.nvim"),
-- DAP -- Motions
gh("mfussenegger/nvim-dap"), gh("mawkler/demicolon.nvim"),
gh("rcarriga/nvim-dap-ui"), gh("nvim-treesitter/nvim-treesitter-textobjects"),
gh("nvim-neotest/nvim-nio"),
gh("LiadOz/nvim-dap-repl-highlights"),
gh("theHamsta/nvim-dap-virtual-text"),
gh("Weissle/persistent-breakpoints.nvim"),
gh("leoluz/nvim-dap-go"),
-- Misc -- Misc
gh("OXY2DEV/markview.nvim"), gh("OXY2DEV/markview.nvim"),
gh("MunifTanjim/nui.nvim"), gh("MunifTanjim/nui.nvim"),
gh("xzbdmw/colorful-menu.nvim"),
}) })
require("colorful-menu").setup({})
vim.cmd.packadd("nvim.undotree") vim.cmd.packadd("nvim.undotree")
vim.api.nvim_create_user_command("VimPackClean", function() vim.api.nvim_create_user_command("VimPackClean", function()

View file

@ -45,10 +45,16 @@ vim.schedule(function()
}) })
end) end)
require("treesitter-context").setup({ vim.api.nvim_create_autocmd("CursorMoved", {
once = true,
callback = function()
vim.pack.add({ "https://github.com/nvim-treesitter/nvim-treesitter-context" })
require("treesitter-context").setup({
max_lines = 2, max_lines = 2,
multiline_threshold = 3, multiline_threshold = 3,
trim_scope = "inner", trim_scope = "inner",
})
end,
}) })
-- Textobject helpers -- Textobject helpers

View file

@ -1,13 +1,18 @@
local ls = require("luasnip") local function gh(repo)
require("luasnip.loaders.from_vscode").lazy_load() return "https://github.com/" .. repo
ls.filetype_extend("typescriptreact", { "html" }) end
ls.filetype_extend("javascriptreact", { "html" })
ls.config.set_config({
enable_autosnippets = false,
store_selection_keys = false,
})
require("blink.cmp").setup({ vim.api.nvim_create_autocmd("ModeChanged", {
once = true,
callback = function()
vim.pack.add({
gh("rafamadriz/friendly-snippets"),
{ src = gh("L3MON4D3/LuaSnip"), version = vim.version.range("2.x") },
{ src = gh("saghen/blink.cmp"), version = vim.version.range("1.x") },
gh("xzbdmw/colorful-menu.nvim"),
})
require("blink.cmp").setup({
keymap = { preset = "super-tab" }, keymap = { preset = "super-tab" },
appearance = { appearance = {
nerd_font_variant = "mono", nerd_font_variant = "mono",
@ -40,4 +45,16 @@ require("blink.cmp").setup({
default = { "lsp", "path", "snippets", "buffer" }, default = { "lsp", "path", "snippets", "buffer" },
}, },
fuzzy = { implementation = "prefer_rust_with_warning" }, fuzzy = { implementation = "prefer_rust_with_warning" },
})
require("colorful-menu").setup({})
end,
})
local ls = require("luasnip")
require("luasnip.loaders.from_vscode").lazy_load()
ls.filetype_extend("typescriptreact", { "html" })
ls.filetype_extend("javascriptreact", { "html" })
ls.config.set_config({
enable_autosnippets = false,
store_selection_keys = false,
}) })

View file

@ -1,8 +1,5 @@
vim.schedule(function() require("demicolon").setup({
vim.pack.add({ "https://github.com/mawkler/demicolon.nvim" })
require("demicolon").setup({
keymaps = { keymaps = {
repeat_motions = "stateful", repeat_motions = "stateful",
}, },
}) })
end)

View file

@ -1,9 +1,14 @@
vim.schedule(function() local function gh(repo)
vim.pack.add({ return "https://github.com/" .. repo
"https://github.com/rmagatti/logger.nvim", end
"https://github.com/rmagatti/goto-preview",
})
vim.api.nvim_create_autocmd("LspAttach", {
once = true,
callback = function()
vim.pack.add({
gh("https://github.com/rmagatti/goto-preview"),
gh("rmagatti/logger.nvim")
})
require("goto-preview").setup({ require("goto-preview").setup({
border = { "", "", "", "", "", "", "", "" }, border = { "", "", "", "", "", "", "", "" },
focus_on_open = true, focus_on_open = true,
@ -12,10 +17,10 @@ vim.schedule(function()
vim_ui_input = false, vim_ui_input = false,
}) })
local utils = require("utils") require("utils").set_keymap_list({
utils.set_keymap_list({
{ "gp", function() require("goto-preview").goto_preview_definition() end }, { "gp", function() require("goto-preview").goto_preview_definition() end },
{ "gy", function() require("goto-preview").goto_preview_type_definition() end }, { "gy", function() require("goto-preview").goto_preview_type_definition() end },
{ "<Leader>q", function() require("goto-preview").close_all_win() end }, { "<Leader>q", function() require("goto-preview").close_all_win() end },
}) })
end) end,
})

View file

@ -3,12 +3,37 @@ local inlay_hints_handler = require("inlay_hints_handler")
local is_debug_mode_active = false local is_debug_mode_active = false
local dap = require("dap") local function gh(repo)
return "https://github.com/" .. repo
end
require("nvim-dap-repl-highlights").setup({}) vim.api.nvim_create_autocmd("BufReadPost", {
require("nvim-dap-virtual-text").setup({}) once = true,
require("persistent-breakpoints").setup({ load_breakpoints_event = { "BufReadPost" } }) callback = function()
require("dapui").setup({ vim.pack.add({
gh("Weissle/persistent-breakpoints.nvim"),
})
require("persistent-breakpoints").setup({
load_breakpoints_event = { "BufReadPost" },
})
end,
})
local function setup_dap()
vim.pack.add({
gh("mfussenegger/nvim-dap"),
gh("rcarriga/nvim-dap-ui"),
gh("nvim-neotest/nvim-nio"),
gh("LiadOz/nvim-dap-repl-highlights"),
gh("theHamsta/nvim-dap-virtual-text"),
gh("leoluz/nvim-dap-go"),
})
local dap = require("dap")
require("nvim-dap-repl-highlights").setup({})
require("nvim-dap-virtual-text").setup({})
require("dapui").setup({
controls = { enabled = false }, controls = { enabled = false },
layouts = { layouts = {
{ {
@ -20,15 +45,22 @@ require("dapui").setup({
size = 15, size = 15,
}, },
}, },
}) })
require("dap-go").setup({}) require("dap-go").setup({})
dap.adapters.codelldb = require("dap.codelldb") dap.adapters.codelldb = require("dap.codelldb")
local virtual_text = require("nvim-dap-virtual-text/virtual_text") for _, sign in ipairs({
local breakpoint_api = require("persistent-breakpoints.api") { "DapBreakpoint", { text = "🛑", texthl = "", linehl = "", numhl = "" } },
{ "DapBreakpointRejected", { text = "🔵", texthl = "", linehl = "", numhl = "" } },
{ "DapBreakpointCondition", { text = "🟥", texthl = "", linehl = "", numhl = "" } },
}) do
vim.fn.sign_define(unpack(sign))
end
local stepping_keymaps = { local virtual_text = require("nvim-dap-virtual-text/virtual_text")
local stepping_keymaps = {
{ "<F10>", function() dap.step_over() end }, { "<F10>", function() dap.step_over() end },
{ "<F11>", function() dap.step_into() end }, { "<F11>", function() dap.step_into() end },
{ "<F12>", function() dap.step_out() end }, { "<F12>", function() dap.step_out() end },
@ -45,53 +77,74 @@ local stepping_keymaps = {
}) })
end, end,
}, },
} }
for _, sign in ipairs({ local function enter_debug_mode()
{ "DapBreakpoint", { text = "🛑", texthl = "", linehl = "", numhl = "" } },
{ "DapBreakpointRejected", { text = "🔵", texthl = "", linehl = "", numhl = "" } },
{ "DapBreakpointCondition", { text = "🟥", texthl = "", linehl = "", numhl = "" } },
}) do
vim.fn.sign_define(unpack(sign))
end
local function enter_debug_mode()
if is_debug_mode_active then return end if is_debug_mode_active then return end
utils.set_keymap_list(stepping_keymaps) utils.set_keymap_list(stepping_keymaps)
is_debug_mode_active = true is_debug_mode_active = true
inlay_hints_handler.disable() inlay_hints_handler.disable()
require("dapui").open() require("dapui").open()
end end
local function exit_debug_mode() local function exit_debug_mode()
if not is_debug_mode_active then return end if not is_debug_mode_active then return end
utils.del_keymap_list(stepping_keymaps) utils.del_keymap_list(stepping_keymaps)
is_debug_mode_active = false is_debug_mode_active = false
inlay_hints_handler.restore() inlay_hints_handler.restore()
virtual_text.clear_virtual_text() virtual_text.clear_virtual_text()
require("dapui").close() require("dapui").close()
end end
for _, request in ipairs({ "attach", "launch" }) do for _, request in ipairs({ "attach", "launch" }) do
dap.listeners.before[request]["dapui_config"] = enter_debug_mode dap.listeners.before[request]["dapui_config"] = enter_debug_mode
end end
for _, event in ipairs({ "event_terminated", "event_exited" }) do for _, event in ipairs({ "event_terminated", "event_exited" }) do
dap.listeners.after[event]["dapui_config"] = exit_debug_mode dap.listeners.after[event]["dapui_config"] = exit_debug_mode
end
end end
local function dap_stop() local function with_dap(fn)
dap.terminate() return function(...)
dap.close() setup_dap()
exit_debug_mode() return fn(...)
end
end end
utils.set_keymap_list({ utils.set_keymap_list({
{ "<leader>dr", dap.continue }, {
{ "<leader>bt", breakpoint_api.toggle_breakpoint }, "<leader>dr",
{ "<leader>bc", breakpoint_api.set_conditional_breakpoint }, with_dap(function()
{ "<leader>br", breakpoint_api.clear_all_breakpoints }, require("dap").continue()
{ "<leader>ds", dap_stop }, end),
},
{
"<leader>bt",
function()
require("persistent-breakpoints.api").toggle_breakpoint()
end,
},
{
"<leader>bc",
function()
require("persistent-breakpoints.api").set_conditional_breakpoint()
end,
},
{
"<leader>br",
function()
require("persistent-breakpoints.api").clear_all_breakpoints()
end,
},
{
"<leader>ds",
with_dap(function()
local dap = require("dap")
dap.terminate()
dap.close()
end),
},
}) })
vim.api.nvim_create_user_command("LaunchTemplate", function() vim.api.nvim_create_user_command("LaunchTemplate", function()

View file

@ -1,4 +1,8 @@
require("nvim-lightbulb").setup({ vim.api.nvim_create_autocmd("LspAttach", {
once = true,
callback = function()
vim.pack.add({ "https://github.com/kosayoda/nvim-lightbulb" })
require("nvim-lightbulb").setup({
hide_in_unfocused_buffer = true, hide_in_unfocused_buffer = true,
code_lenses = false, -- 0.12 shows code lenses as virtual lines natively code_lenses = false, -- 0.12 shows code lenses as virtual lines natively
sign = { enabled = true }, sign = { enabled = true },
@ -6,4 +10,6 @@ require("nvim-lightbulb").setup({
float = { enabled = false }, float = { enabled = false },
status_text = { enabled = false }, status_text = { enabled = false },
autocmd = { enabled = true, updatetime = 25 }, autocmd = { enabled = true, updatetime = 25 },
})
end,
}) })

View file

@ -1,4 +1,8 @@
require("tiny-glimmer").setup({ vim.api.nvim_create_autocmd("CursorMoved", {
once = true,
callback = function()
vim.pack.add({ "https://github.com/rachartier/tiny-glimmer.nvim" })
require("tiny-glimmer").setup({
refresh_interval_ms = 6, refresh_interval_ms = 6,
overwrite = { overwrite = {
auto_map = true, auto_map = true,
@ -21,4 +25,6 @@ require("tiny-glimmer").setup({
to_color = "Folded", to_color = "Folded",
}, },
}, },
})
end,
}) })

View file

@ -1,4 +1,8 @@
require("tiny-inline-diagnostic").setup({ vim.api.nvim_create_autocmd("LspAttach", {
once = true,
callback = function()
vim.pack.add({ "https://github.com/rachartier/tiny-inline-diagnostic.nvim" })
require("tiny-inline-diagnostic").setup({
preset = "modern", preset = "modern",
transparent_bg = false, transparent_bg = false,
transparent_cursorline = false, transparent_cursorline = false,
@ -8,4 +12,6 @@ require("tiny-inline-diagnostic").setup({
always_show = true, always_show = true,
}, },
}, },
})
end,
}) })