️ 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
+49 -2
View File
@@ -58,7 +58,15 @@ return {
},
{ -- Alternate
"ton/vim-alternate",
lazy = true,
ft = { "cpp", "h", "hpp", "c" },
keys = {
{ -- Toggle Alternate
"<leader>a",
"<cmd>Alternate<cr>",
desc = "Toggle Alternate",
},
},
},
{ -- Completion
"hrsh7th/nvim-cmp",
@@ -104,18 +112,57 @@ return {
},
{ -- Colorizer
"norcalli/nvim-colorizer.lua",
event = "InsertEnter",
event = "BufEnter",
config = function()
require("colorizer").setup()
end,
},
{ -- Substitute
"gbprod/substitute.nvim",
event = "InsertEnter",
lazy = true,
opts = {
yank_substituted_text = false,
preserve_cursor_position = true,
},
keys = {
{ -- Substitute operator in normal mode
"x",
function()
require("substitute").operator()
end,
desc = "Substitute operator",
},
{ -- Substitute line in normal mode
"xx",
function()
require("substitute").line()
end,
desc = "Substitute line",
},
{ -- Substitute end of line in normal mode
"X",
function()
require("substitute").eol()
end,
desc = "Substitute end of line",
},
{ -- Substitute visual selection in visual mode
"x",
function()
require("substitute").visual()
end,
desc = "Substitute visual selection",
mode = "x",
},
{
"<leader>r",
function()
require("substitute").visual()
end,
desc = "Substitute",
mode = "x",
},
},
},
{ -- mini.splitjoin
"echasnovski/mini.splitjoin",
+21 -3
View File
@@ -42,15 +42,14 @@ return {
},
{ -- indent-blankline
"lukas-reineke/indent-blankline.nvim",
lazy = true,
},
{ -- Outline
import = "lazyvim.plugins.extras.editor.outline",
},
{ -- Telescope
import = "lazyvim.plugins.extras.editor.telescope",
},
{ -- FoldNav
"domharries/foldnav.nvim",
lazy = true,
keys = {
{
"<C-h>",
@@ -80,6 +79,7 @@ return {
},
{ -- Which-Key
"folke/which-key.nvim",
lazy = true,
opts = {
preset = "modern",
win = {
@@ -118,12 +118,30 @@ return {
"tris203/precognition.nvim",
lazy = true,
opts = {},
keys = {
{
"zk",
function()
require("config.rootiest").toggle_precognition()
end,
desc = "Toggle Precognition",
},
},
},
{ -- Zen Mode
"folke/zen-mode.nvim",
--event = "VeryLazy",
lazy = true,
opts = {},
keys = {
{ -- Toggle ZenMode
"<leader>z",
function()
require("zen-mode").toggle()
end,
desc = "Toggle ZenMode",
},
},
},
{ -- SmoothCursor
"gen740/SmoothCursor.nvim",
+65
View File
@@ -15,6 +15,14 @@ return {
{ -- ToggleTerm
"akinsho/toggleterm.nvim",
event = "VeryLazy",
keys = {
{ -- Toggle Terminal
"<c-/>",
"<cmd>ToggleTerm<cr>",
desc = "Toggle Terminal",
mode = "n",
},
},
config = function()
require("toggleterm").setup({
-- size can be a number or function which is passed the current terminal
@@ -63,6 +71,36 @@ return {
local kit = string.find(term, "kitty")
return kit ~= nil
end,
keys = {
{
"<c-s-h>",
function()
require("kitty-navigator").navigateLeft()
end,
desc = "KittyNavigateLeft",
},
{
"<c-s-j>",
function()
require("kitty-navigator").navigateDown()
end,
desc = "KittyNavigateDown",
},
{
"<c-s-k>",
function()
require("kitty-navigator").navigateUp()
end,
desc = "KittyNavigateUp",
},
{
"<c-s-l>",
function()
require("kitty-navigator").navigateRight()
end,
desc = "KittyNavigateRight",
},
},
},
{ -- Kitty-Runner
"jghauser/kitty-runner.nvim",
@@ -87,10 +125,37 @@ return {
},
{
"NeViRAIDE/nekifoch.nvim",
lazy = true,
cmd = "Nekifoch",
opts = {
kitty_conf_path = vim.env.HOME .. "/.kittyoverrides",
},
keys = {
{
"<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",
function()
require("nekifoch.nui_set_font")()
end,
desc = "Set font family",
},
{
"<leader>u,s",
function()
require("nekifoch.nui_set_size")()
end,
desc = "Set font size",
},
},
cond = function() -- Using Kitty
local term = os.getenv("TERM") or ""
local kit = string.find(term, "kitty")
+9
View File
@@ -72,6 +72,15 @@ return {
"xiyaowong/transparent.nvim",
lazy = true,
config = true,
keys = {
{
"<leader>wt",
function()
require("transparent").toggle()
end,
desc = "Toggle Transparency",
},
},
},
{ -- Auto Dark Mode
"f-person/auto-dark-mode.nvim",
+109 -16
View File
@@ -21,10 +21,6 @@ local function get_fg_color(hlgroup)
end
return {
{ -- Project management
import = "lazyvim.plugins.extras.util.project",
opts = { manual_mode = false },
},
{ -- Chezmoi
import = "lazyvim.plugins.extras.util.chezmoi",
},
@@ -43,8 +39,16 @@ return {
},
{ -- Link following
"chrishrb/gx.nvim",
event = "VeryLazy",
lazy = true,
cmd = { "Browse" },
keys = {
{ -- Open URL/Link
"gx",
"<cmd>Browse<cr>",
mode = { "n", "x" },
desc = "Open URL/Link",
},
},
init = function()
vim.g.netrw_nogx = 1
end,
@@ -55,19 +59,42 @@ return {
"Pocco81/auto-save.nvim",
event = "BufEnter",
},
{ -- User is bored
"mikesmithgh/ugbi",
event = "InsertEnter",
},
{ -- Ripgrep substitute
"chrisgrieser/nvim-rip-substitute",
event = "InsertEnter",
cmd = "RipSubstitute",
keys = {
{ -- Rip Substitute
"<leader>fs",
function()
require("rip-substitute").sub()
end,
mode = { "n", "x" },
desc = "Rip Substitute",
},
},
},
{ -- Gist Tools
"Rawnly/gist.nvim",
event = "InsertEnter",
cmd = { "GistCreate", "GistCreateFromFile", "GistsList" },
lazy = true,
cmd = {
"GistCreate",
"GistCreateFromFile",
"GistsList",
},
keys = {
{ -- Create Gist
"<leader>gnc",
"<cmd>GistCreate<cr>",
desc = "Create Gist",
mode = { "n", "x" },
},
{ -- Find Gists
"<leader>gnf",
"<cmd>GistList<cr>",
desc = "Find Gists",
},
},
config = true,
},
{ -- Unception
@@ -78,10 +105,28 @@ return {
},
{ -- 🍎 Icon Picker
"ziontee113/icon-picker.nvim",
event = "InsertEnter",
lazy = true,
config = function()
require("icon-picker").setup({ disable_legacy_commands = true })
end,
keys = {
{ -- Pick Icon
"<leader>Ii",
"<cmd>IconPickerNormal<cr>",
desc = "Pick Icon",
},
{ -- Yank Icon
"<leader>Iy",
"<cmd>IconPickerYank<cr>",
desc = "Yank Icon",
},
{ -- Insert Icon in insert mode
"<C-i>",
"<cmd>IconPickerInsert<cr>",
desc = "Insert Icon",
mode = "i",
},
},
},
{ -- LazyGit
"kdheepak/lazygit.nvim",
@@ -93,13 +138,20 @@ return {
"LazyGitFilter",
"LazyGitFilterCurrentFile",
},
keys = {
{
"<leader>lg",
"<cmd>LazyGit<cr>",
desc = "LazyGit",
},
},
dependencies = {
"nvim-lua/plenary.nvim",
},
},
{ -- Codesnap
"mistricky/codesnap.nvim",
event = "InsertEnter",
lazy = true,
build = "make",
opts = {
save_path = "~/Pictures/Screenshots/",
@@ -110,6 +162,38 @@ return {
code_font_family = "Iosevka NF",
code_font_size = 12,
},
cmd = {
"CodeSnap",
"CodeSnapSave",
"CodeSnapHighlight",
"CodeSnapASCII",
},
keys = {
{ -- Save selected code snapshot into clipboard
"<leader>cy",
"<cmd>CodeSnap<cr>",
desc = "Save selected code snapshot into clipboard",
mode = "x",
},
{ -- Save selected code snapshot in ~/Pictures
"<leader>cs",
"<cmd>CodeSnapSave<cr>",
desc = "Save selected code snapshot in ~/Pictures",
mode = "x",
},
{ -- Highlight and snapshot selected code into clipboard
"<leader>ch",
"<cmd>CodeSnapHighlight<cr>",
desc = "Highlight and snapshot selected code into clipboard",
mode = "x",
},
{ -- Save ASCII code snapshot into clipboard
"<leader>ci",
"<cmd>CodeSnapASCII<cr>",
desc = "Save ASCII code snapshot into clipboard",
mode = "x",
},
},
},
{ -- Kulala
"mistweaverco/kulala.nvim",
@@ -120,7 +204,13 @@ return {
},
{ -- Thanks/github-stars
"jsongerber/thanks.nvim",
event = "VeryLazy",
lazy = true,
cmd = {
"ThanksAll",
"ThanksGithubAuth",
"ThanksGithubLogout",
"ThanksClearCache",
},
opts = {
star_on_install = false,
},
@@ -158,9 +248,12 @@ return {
opts = {},
keys = {
{
mode = { "i", "n" },
"<C-s>",
"<cmd>lua require('caps-word').toggle()<CR>",
function()
require("caps-word").toggle()
end,
desc = "Toggle CapsWord",
mode = { "i", "n" },
},
},
},