️ perf(lazy-load): delegate plugins to their cmd/keymaps

Increase performance: Allow plugins to only load with their commands and keymaps whenever possible
This commit is contained in:
2024-08-04 06:57:07 -04:00
parent 335fe93d8a
commit b622454835
9 changed files with 291 additions and 333 deletions
+6 -1
View File
@@ -2,10 +2,15 @@
-- -------------------------------- AUTOCMDS -----------------------------------
-- -----------------------------------------------------------------------------
local autogrp = vim.api.nvim_create_augroup
local autocmd = vim.api.nvim_create_autocmd
-- GIT CONFLICT MARKERS
-- if there are conflicts, jump to first conflict, highlight conflict markers,
-- and disable diagnostics (simplified version of `git-conflict.nvim`)
vim.api.nvim_create_autocmd({ "BufEnter", "FocusGained" }, {
autogrp("GitConflictMarkers", { clear = true })
autocmd({ "BufEnter", "FocusGained" }, {
group = "GitConflictMarkers",
callback = function(ctx)
local hlgroup = "DiagnosticVirtualTextInfo" -- CONFIG
+1 -10
View File
@@ -183,15 +183,6 @@ function M.setup_autocommands()
local autogrp = vim.api.nvim_create_augroup
local autocmd = vim.api.nvim_create_autocmd
autogrp("IndentHighlight", { clear = true })
-- Autocommand to trigger setup on FileType
-- autocmd("FileType", {
-- pattern = "*",
-- group = "IndentHighlight",
-- callback = function()
-- M.setup_indent_highlight()
-- M.setup_dashboard_highlight()
-- end,
-- })
-- List of filetypes to exclude
local excluded_filetypes = {
@@ -209,7 +200,7 @@ function M.setup_autocommands()
}
-- Autocommand to trigger setup on FileType
vim.api.nvim_create_autocmd("FileType", {
autocmd("FileType", {
group = "IndentHighlight",
callback = function()
local filetype = vim.bo.filetype
-274
View File
@@ -7,12 +7,6 @@
-- Initialize which-key
local wk = require("which-key")
wk.add({
{ -- Toggle Terminal
mode = "n",
"<c-/>",
":ToggleTerm<cr>",
desc = "Toggle Terminal",
},
{ -- Open LazyGit in terminal
"<leader>gt",
rhs = function()
@@ -26,42 +20,6 @@ wk.add({
lhs = "<leader>I",
group = "IconPicker",
icon = { icon = "󰥸", color = "orange" },
cond = function()
return pcall(require, "icon-picker")
end,
},
-- Pick Icon
{
mode = "n",
lhs = "<leader>Ii",
rhs = "<cmd>IconPickerNormal<cr>",
desc = "Pick Icon",
group = "IconPicker",
cond = function()
return pcall(require, "icon-picker")
end,
},
-- Yank Icon
{
mode = "n",
lhs = "<leader>Iy",
rhs = "<cmd>IconPickerYank<cr>",
desc = "Yank Icon",
group = "IconPicker",
cond = function()
return pcall(require, "icon-picker")
end,
},
-- Insert Icon in insert mode
{
mode = "i",
lhs = "<C-i>",
rhs = "<cmd>IconPickerInsert<cr>",
desc = "Insert Icon",
group = "IconPicker",
cond = function()
return pcall(require, "icon-picker")
end,
},
-- Gists group
{
@@ -69,29 +27,6 @@ wk.add({
lhs = "<leader>gn",
group = "Gists",
icon = { icon = "", color = "orange" },
cond = function()
return pcall(require, "gist")
end,
},
-- Create Gist
{
mode = { "n", "x" },
lhs = "<leader>gnc",
rhs = "<cmd>GistCreate<cr>",
desc = "Create Gist",
cond = function()
return pcall(require, "gist")
end,
},
-- Find Gists
{
mode = "n",
lhs = "<leader>gnf",
rhs = "<cmd>GistList<cr>",
desc = "Find Gists",
cond = function()
return pcall(require, "gist")
end,
},
{ -- Lazy group
"<leader>l",
@@ -112,140 +47,6 @@ wk.add({
group = "MiniMap",
icon = { icon = "", color = "yellow" },
},
-- Save selected code snapshot into clipboard
{
mode = "x",
lhs = "<leader>cy",
rhs = "<cmd>CodeSnap<cr>",
desc = "Save selected code snapshot into clipboard",
cond = function()
return pcall(require, "codesnap")
end,
},
-- Save selected code snapshot in ~/Pictures
{
mode = "x",
lhs = "<leader>cs",
rhs = "<cmd>CodeSnapSave<cr>",
desc = "Save selected code snapshot in ~/Pictures",
cond = function()
return pcall(require, "codesnap")
end,
},
-- Highlight and snapshot selected code into clipboard
{
mode = "x",
lhs = "<leader>ch",
rhs = "<cmd>CodeSnapHighlight<cr>",
desc = "Highlight and snapshot selected code into clipboard",
cond = function()
return pcall(require, "codesnap")
end,
},
-- Save ASCII code snapshot into clipboard
{
mode = "x",
lhs = "<leader>ci",
rhs = "<cmd>CodeSnapASCII<cr>",
desc = "Save ASCII code snapshot into clipboard",
cond = function()
return pcall(require, "codesnap")
end,
},
{
"gx",
"<cmd>Browse<cr>",
mode = { "n", "x" },
desc = "Open URL/Link",
},
{
"<leader>lg",
"<cmd>LazyGit<cr>",
desc = "LazyGit",
},
{
"<leader>fs",
rhs = function()
require("rip-substitute").sub()
end,
mode = { "n", "x" },
desc = "Rip Substitute",
},
{
"<c-s-h>",
rhs = function()
require("kitty-navigator").navigateLeft()
end,
desc = "KittyNavigateLeft",
cond = function() -- Using Kitty
return require("config.rootiest").using_kitty()
end,
},
{
"<c-s-j>",
rhs = function()
require("kitty-navigator").navigateDown()
end,
desc = "KittyNavigateDown",
cond = function() -- Using Kitty
return require("config.rootiest").using_kitty()
end,
},
{
"<c-s-k>",
rhs = function()
require("kitty-navigator").navigateUp()
end,
desc = "KittyNavigateUp",
cond = function() -- Using Kitty
return require("config.rootiest").using_kitty()
end,
},
{
"<c-s-l>",
rhs = function()
require("kitty-navigator").navigateRight()
end,
desc = "KittyNavigateRight",
cond = function() -- Using Kitty
return require("config.rootiest").using_kitty()
end,
},
{
"zk",
rhs = function()
require("config.rootiest").toggle_precognition()
end,
desc = "Toggle Precognition",
},
{
"<leader>a",
"<cmd>Alternate<cr>",
desc = "Toggle Alternate",
cond = function()
return (
vim.bo.filetype == "c"
or vim.bo.filetype == "h"
or vim.bo.filetype == "cpp"
or vim.bo.filetype == "hpp"
)
end,
},
{
"<leader>wt",
rhs = function()
require("transparent").toggle()
end,
desc = "Toggle Transparency",
},
{
mode = "x",
lhs = "<leader>r",
rhs = function()
require("substitute").visual()
end,
desc = "Substitute",
},
{
"yo",
rhs = function()
@@ -260,82 +61,7 @@ wk.add({
end,
desc = "Toggle Hardmode",
},
{ -- Toggle ZenMode
"<leader>z",
rhs = function()
require("zen-mode").toggle()
end,
desc = "Toggle ZenMode",
},
-- Substitute operator in normal mode
{
mode = "n",
lhs = "x",
rhs = function()
require("substitute").operator()
end,
desc = "Substitute operator",
cond = function()
return pcall(require, "substitute")
end,
},
-- Substitute line in normal mode
{
mode = "n",
lhs = "xx",
rhs = function()
require("substitute").line()
end,
desc = "Substitute line",
cond = function()
return pcall(require, "substitute")
end,
},
-- Substitute end of line in normal mode
{
mode = "n",
lhs = "X",
rhs = function()
require("substitute").eol()
end,
desc = "Substitute end of line",
cond = function()
return pcall(require, "substitute")
end,
},
-- Substitute visual selection in visual mode
{
mode = "x",
lhs = "x",
rhs = function()
require("substitute").visual()
end,
desc = "Substitute visual selection",
cond = function()
return pcall(require, "substitute")
end,
},
{ "<leader>u,", group = "Font" },
{ "<leader>u,l", "<cmd>Nekifoch list<cr>", desc = "Fonts list" },
{
"<leader>u,c",
"<cmd>Nekifoch check<cr>",
desc = "Check current font settings",
},
{
"<leader>u,f",
rhs = function()
require("nekifoch.nui_set_font")()
end,
desc = "Set font family",
},
{
"<leader>u,s",
rhs = function()
require("nekifoch.nui_set_size")()
end,
desc = "Set font size",
},
{ -- Yank buffer contents
"<leader>Y",
"<cmd>%y<cr>",
+31 -27
View File
@@ -110,31 +110,6 @@ function M.set_cursor_icons()
end
end
-- Evaluate dependencies and print warnings if needed
function M.eval_dependencies()
local function should_suppress_warnings()
return false
end
local function check_executable(executable)
if vim.fn.executable(executable) ~= 1 then
vim.api.nvim_notify(
executable .. " is not installed!",
vim.log.levels.WARN,
{}
)
end
end
if not should_suppress_warnings() then
local executables =
{ "lazygit", "gh", "rg", "fzf", "fd", "git", "luarocks" }
for _, executable in ipairs(executables) do
check_executable(executable)
end
end
end
-- Evaluate Neovide settings
function M.eval_neovide()
if vim.g.neovide then
@@ -158,11 +133,40 @@ function M.define_commands()
end, { force = true, desc = "Yank line without leading whitespace" })
end
function M.define_autocommands()
local autogrp = vim.api.nvim_create_augroup
local autocmd = vim.api.nvim_create_autocmd
autogrp("AutoSpellCorrections", { clear = true })
-- List of filetypes to exclude
local excluded_filetypes = {
"help",
"alpha",
"dashboard",
"neo-tree",
"Trouble",
"trouble",
"lazy",
"mason",
"notify",
"toggleterm",
"lazyterm",
}
-- Autocommand to trigger setup on FileType
autocmd("FileType", {
group = "AutoSpellCorrections",
callback = function()
local filetype = vim.bo.filetype
if not vim.tbl_contains(excluded_filetypes, filetype) then
M.define_autocorrections()
end
end,
})
end
function M.setup()
M.eval_dependencies()
M.eval_neovide()
M.define_autocorrections()
M.define_commands()
M.define_autocommands()
end
return M