From 3ddc6a03255a7d7ca1fe27a3ab36d7c3b4e120af Mon Sep 17 00:00:00 2001 From: chilly Date: Mon, 29 Sep 2025 13:39:30 +0800 Subject: [PATCH] wrap the keymap settings in autocmd --- lua/lazyvim/plugins/extras/lang/tex.lua | 1016 ++++++++++++----------- 1 file changed, 512 insertions(+), 504 deletions(-) diff --git a/lua/lazyvim/plugins/extras/lang/tex.lua b/lua/lazyvim/plugins/extras/lang/tex.lua index e32f92ed..66187547 100644 --- a/lua/lazyvim/plugins/extras/lang/tex.lua +++ b/lua/lazyvim/plugins/extras/lang/tex.lua @@ -30,510 +30,518 @@ return { vim.g.vimtex_quickfix_method = vim.fn.executable("pplatex") == 1 and "pplatex" or "latexlog" vim.g.vimtex_mappings_enabled = false - local wk = require("which-key") - wk.add({ - -- buffer = ev.buf, -- e.g. ev.buf or similar - { - "l", - group = "VimTeX", - icon = { icon = "", color = "green" }, - mode = "nx", - }, - { - mode = "n", - { - "ll", - "(vimtex-compile)", - desc = "Compile", - icon = { icon = "", color = "green" }, - }, - { - "lL", - "(vimtex-compile-selected)", - desc = "Compile selected", - icon = { icon = "", color = "green" }, - mode = "nx", - }, - { - "li", - "(vimtex-info)", - desc = "Information", - icon = { icon = "", color = "purple" }, - }, - { - "lI", - "(vimtex-info-full)", - desc = "Full information", - icon = { icon = "󰙎", color = "purple" }, - }, - { - "lt", - "(vimtex-toc-open)", - desc = "Table of Contents", - icon = { icon = "󰠶", color = "purple" }, - }, - { - "lT", - "(vimtex-toc-toggle)", - desc = "Toggle table of Contents", - icon = { icon = "󰠶", color = "purple" }, - }, - { - "lq", - "(vimtex-log)", - desc = "Log", - icon = { icon = "", color = "purple" }, - }, - { - "lv", - "(vimtex-view)", - desc = "View", - icon = { icon = "", color = "green" }, - }, - { - "lr", - "(vimtex-reverse-search)", - desc = "Reverse search", - icon = { icon = "", color = "purple" }, - }, - { - "lk", - "(vimtex-stop)", - desc = "Stop", - icon = { icon = "", color = "red" }, - }, - { - "lK", - "(vimtex-stop-all)", - desc = "Stop all", - icon = { icon = "󰓛", color = "red" }, - }, - { - "le", - "(vimtex-errors)", - desc = "Errors", - icon = { icon = "", color = "red" }, - }, - { - "lo", - "(vimtex-compile-output)", - desc = "Compile output", - icon = { icon = "", color = "purple" }, - }, - { - "lg", - "(vimtex-status)", - desc = "Status", - icon = { icon = "󱖫", color = "purple" }, - }, - { - "lG", - "(vimtex-status-full)", - desc = "Full status", - icon = { icon = "󱖫", color = "purple" }, - }, - { - "lc", - "(vimtex-clean)", - desc = "Clean", - icon = { icon = "󰃢", color = "orange" }, - }, - { - "lh", - "VimtexClearCache ALL", - desc = "Clear all cache", - icon = { icon = "󰃢", color = "grey" }, - }, - { - "lC", - "(vimtex-clean-full)", - desc = "Full clean", - icon = { icon = "󰃢", color = "red" }, - }, - { - "lx", - "(vimtex-reload)", - desc = "Reload", - icon = { icon = "󰑓", color = "green" }, - }, - { - "lX", - "(vimtex-reload-state)", - desc = "Reload state", - icon = { icon = "󰑓", color = "cyan" }, - }, - { - "lm", - "(vimtex-imaps-list)", - desc = "Input mappings", - icon = { icon = "", color = "purple" }, - }, - { - "ls", - "(vimtex-toggle-main)", - desc = "Toggle main", - icon = { icon = "󱪚", color = "green" }, - }, - { - "la", - "(vimtex-context-menu)", - desc = "Context menu", - icon = { icon = "󰮫", color = "purple" }, - }, - { - "ds", - group = "+surrounding", - icon = { icon = "󰗅", color = "green" }, - }, - { - "dse", - "(vimtex-env-delete)", - desc = "environment", - icon = { icon = "", color = "red" }, - }, - { - "dsc", - "(vimtex-cmd-delete)", - desc = "command", - icon = { icon = "", color = "red" }, - }, - { - "ds$", - "(vimtex-env-delete-math)", - desc = "math", - icon = { icon = "󰿈", color = "red" }, - }, - { - "dsd", - "(vimtex-delim-delete)", - desc = "delimeter", - icon = { icon = "󰅩", color = "red" }, - }, - { - "cs", - group = "+surrounding", - icon = { icon = "󰗅", color = "green" }, - }, - { - "cse", - "(vimtex-env-change)", - desc = "environment", - icon = { icon = "", color = "blue" }, - }, - { - "csc", - "(vimtex-cmd-change)", - desc = "command", - icon = { icon = "", color = "blue" }, - }, - { - "cs$", - "(vimtex-env-change-math)", - desc = "math environment", - icon = { icon = "󰿈", color = "blue" }, - }, - { - "csd", - "(vimtex-delim-change-math)", - desc = "delimeter", - icon = { icon = "󰅩", color = "blue" }, - }, - { - "ts", - group = "+surrounding", - icon = { icon = "󰗅", color = "green" }, - mode = "nx", - }, - { - "tsf", - "(vimtex-cmd-toggle-frac)", - desc = "fraction", - icon = { icon = "󱦒", color = "yellow" }, - mode = "nx", - }, - { - "tsc", - "(vimtex-cmd-toggle-star)", - desc = "command", - icon = { icon = "", color = "yellow" }, - }, - { - "tse", - "(vimtex-env-toggle-star)", - desc = "environment", - icon = { icon = "", color = "yellow" }, - }, - { - "ts$", - "(vimtex-env-toggle-math)", - desc = "math environment", - icon = { icon = "󰿈", color = "yellow" }, - }, - { - "tsb", - "(vimtex-env-toggle-break)", - desc = "break", - icon = { icon = "󰿈", color = "yellow" }, - }, - { - "", - "(vimtex-env-surround-line)", - desc = "Surround line with environment", - icon = { icon = "", color = "purple" }, - }, - { - "", - "(vimtex-env-surround-visual)", - desc = "Surround selection with environment", - icon = { icon = "", color = "purple" }, - mode = "x", - }, - { - "tsd", - "(vimtex-delim-toggle-modifier)", - desc = "delimeter", - icon = { icon = "󰅩", color = "yellow" }, - mode = "nx", - }, - { - "tsD", - "(vimtex-delim-toggle-modifier-reverse)", - desc = "revers surrounding delimeter", - icon = { icon = "󰅩", color = "yellow" }, - mode = "nx", - }, - { - "", - "(vimtex-cmd-create)", - desc = "Create command", - icon = { icon = "󰅩", color = "green" }, - mode = "nxi", - }, - { - "]]", - "(vimtex-delim-close)", - desc = "Close delimeter", - icon = { icon = "󰅩", color = "green" }, - mode = "i", - }, - { - "", - "(vimtex-delim-add-modifiers)", - desc = "Add \\left and \\right", - icon = { icon = "󰅩", color = "green" }, - mode = "n", - }, - }, - { - mode = "xo", - { - "ac", - "(vimtex-ac)", - desc = "command", - icon = { icon = "", color = "orange" }, - }, - { - "ic", - "(vimtex-ic)", - desc = "command", - icon = { icon = "", color = "orange" }, - }, - { - "ad", - "(vimtex-ad)", - desc = "delimiter", - icon = { icon = "󰅩", color = "orange" }, - }, - { - "id", - "(vimtex-id)", - desc = "delimiter", - icon = { icon = "󰅩", color = "orange" }, - }, - { - "ae", - "(vimtex-ae)", - desc = "environment", - icon = { icon = "", color = "orange" }, - }, - { - "ie", - "(vimtex-ie)", - desc = "environment", - icon = { icon = "", color = "orange" }, - }, - { - "a$", - "(vimtex-a$)", - desc = "math", - icon = { icon = "󰿈", color = "orange" }, - }, - { - "i$", - "(vimtex-i$)", - desc = "math", - icon = { icon = "󰿈", color = "orange" }, - }, - { - "aP", - "(vimtex-aP)", - desc = "section", - icon = { icon = "󰚟", color = "orange" }, - }, - { - "iP", - "(vimtex-iP)", - desc = "section", - icon = { icon = "󰚟", color = "orange" }, - }, - { - "am", - "(vimtex-am)", - desc = "item", - icon = { icon = "", color = "orange" }, - }, - { - "im", - "(vimtex-im)", - desc = "item", - icon = { icon = "", color = "orange" }, - }, - }, - { - mode = "nxo", - { - "%", - "(vimtex-%)", - desc = "Matching pair", - icon = { icon = "󰐱", color = "cyan" }, - }, - { - "]]", - "(vimtex-]])", - desc = "Next end of a section", - icon = { icon = "󰚟", color = "cyan" }, - }, - { - "][", - "(vimtex-][)", - desc = "Next beginning of a section", - icon = { icon = "󰚟", color = "cyan" }, - }, - { - "[]", - "(vimtex-[])", - desc = "Previous end of a section", - icon = { icon = "󰚟", color = "cyan" }, - }, - { - "[[", - "(vimtex-[[)", - desc = "Previous beginning of a section", - icon = { icon = "󰚟", color = "cyan" }, - }, - { - "]m", - "(vimtex-]m)", - desc = "Next start of an environment", - icon = { icon = "", color = "cyan" }, - }, - { - "]M", - "(vimtex-]M)", - desc = "Next end of an environment", - icon = { icon = "", color = "cyan" }, - }, - { - "[m", - "(vimtex-[m)", - desc = "Previous start of an environment", - icon = { icon = "", color = "cyan" }, - }, - { - "[M", - "(vimtex-[M)", - desc = "Previous end of an environment", - icon = { icon = "", color = "cyan" }, - }, - { - "]n", - "(vimtex-]n)", - desc = "Next start of math", - icon = { icon = "󰿈", color = "cyan" }, - }, - { - "]N", - "(vimtex-]N)", - desc = "Next end of math", - icon = { icon = "󰿈", color = "cyan" }, - }, - { - "[n", - "(vimtex-[n)", - desc = "Previous start of math", - icon = { icon = "󰿈", color = "cyan" }, - }, - { - "[N", - "(vimtex-[N)", - desc = "Previous end of math", - icon = { icon = "󰿈", color = "cyan" }, - }, - { - "]r", - "(vimtex-]r)", - desc = "Next start of frame environment", - icon = { icon = "󰹉", color = "cyan" }, - }, - { - "]R", - "(vimtex-]R)", - desc = "Next end of frame environment", - icon = { icon = "󰹉", color = "cyan" }, - }, - { - "[r", - "(vimtex-[r)", - desc = "Previous start of frame environment", - icon = { icon = "󰹉", color = "cyan" }, - }, - { - "[R", - "(vimtex-[R)", - desc = "Previous end of frame environment", - icon = { icon = "󰹉", color = "cyan" }, - }, - { - "]/", - "(vimtex-]/)", - desc = "Next start of a comment", - icon = { icon = "", color = "cyan" }, - }, - { - "]*", - "(vimtex-]star)", - desc = "Next end of a comment", - icon = { icon = "", color = "cyan" }, - }, - { - "[/", - "(vimtex-[/)", - desc = "Previous start of a comment", - icon = { icon = "", color = "cyan" }, - }, - { - "[*", - "(vimtex-[star)", - desc = "Previous end of a comment", - icon = { icon = "", color = "cyan" }, - }, - }, - { - "K", - "(vimtex-doc-package)", - desc = "See package documentation", - icon = { icon = "󱔗", color = "azure" }, - }, + + local augroup = vim.api.nvim_create_augroup("vimtexConfig", {}) + vim.api.nvim_create_autocmd("FileType", { + pattern = "tex", + group = augroup, + callback = function(event) + local wk = require("which-key") + wk.add({ + buffer = event.buf, + { + "l", + group = "VimTeX", + icon = { icon = "", color = "green" }, + mode = "nx", + }, + { + mode = "n", + { + "ll", + "(vimtex-compile)", + desc = "Compile", + icon = { icon = "", color = "green" }, + }, + { + "lL", + "(vimtex-compile-selected)", + desc = "Compile selected", + icon = { icon = "", color = "green" }, + mode = "nx", + }, + { + "li", + "(vimtex-info)", + desc = "Information", + icon = { icon = "", color = "purple" }, + }, + { + "lI", + "(vimtex-info-full)", + desc = "Full information", + icon = { icon = "󰙎", color = "purple" }, + }, + { + "lt", + "(vimtex-toc-open)", + desc = "Table of Contents", + icon = { icon = "󰠶", color = "purple" }, + }, + { + "lT", + "(vimtex-toc-toggle)", + desc = "Toggle table of Contents", + icon = { icon = "󰠶", color = "purple" }, + }, + { + "lq", + "(vimtex-log)", + desc = "Log", + icon = { icon = "", color = "purple" }, + }, + { + "lv", + "(vimtex-view)", + desc = "View", + icon = { icon = "", color = "green" }, + }, + { + "lr", + "(vimtex-reverse-search)", + desc = "Reverse search", + icon = { icon = "", color = "purple" }, + }, + { + "lk", + "(vimtex-stop)", + desc = "Stop", + icon = { icon = "", color = "red" }, + }, + { + "lK", + "(vimtex-stop-all)", + desc = "Stop all", + icon = { icon = "󰓛", color = "red" }, + }, + { + "le", + "(vimtex-errors)", + desc = "Errors", + icon = { icon = "", color = "red" }, + }, + { + "lo", + "(vimtex-compile-output)", + desc = "Compile output", + icon = { icon = "", color = "purple" }, + }, + { + "lg", + "(vimtex-status)", + desc = "Status", + icon = { icon = "󱖫", color = "purple" }, + }, + { + "lG", + "(vimtex-status-full)", + desc = "Full status", + icon = { icon = "󱖫", color = "purple" }, + }, + { + "lc", + "(vimtex-clean)", + desc = "Clean", + icon = { icon = "󰃢", color = "orange" }, + }, + { + "lh", + "VimtexClearCache ALL", + desc = "Clear all cache", + icon = { icon = "󰃢", color = "grey" }, + }, + { + "lC", + "(vimtex-clean-full)", + desc = "Full clean", + icon = { icon = "󰃢", color = "red" }, + }, + { + "lx", + "(vimtex-reload)", + desc = "Reload", + icon = { icon = "󰑓", color = "green" }, + }, + { + "lX", + "(vimtex-reload-state)", + desc = "Reload state", + icon = { icon = "󰑓", color = "cyan" }, + }, + { + "lm", + "(vimtex-imaps-list)", + desc = "Input mappings", + icon = { icon = "", color = "purple" }, + }, + { + "ls", + "(vimtex-toggle-main)", + desc = "Toggle main", + icon = { icon = "󱪚", color = "green" }, + }, + { + "la", + "(vimtex-context-menu)", + desc = "Context menu", + icon = { icon = "󰮫", color = "purple" }, + }, + { + "ds", + group = "+surrounding", + icon = { icon = "󰗅", color = "green" }, + }, + { + "dse", + "(vimtex-env-delete)", + desc = "environment", + icon = { icon = "", color = "red" }, + }, + { + "dsc", + "(vimtex-cmd-delete)", + desc = "command", + icon = { icon = "", color = "red" }, + }, + { + "ds$", + "(vimtex-env-delete-math)", + desc = "math", + icon = { icon = "󰿈", color = "red" }, + }, + { + "dsd", + "(vimtex-delim-delete)", + desc = "delimeter", + icon = { icon = "󰅩", color = "red" }, + }, + { + "cs", + group = "+surrounding", + icon = { icon = "󰗅", color = "green" }, + }, + { + "cse", + "(vimtex-env-change)", + desc = "environment", + icon = { icon = "", color = "blue" }, + }, + { + "csc", + "(vimtex-cmd-change)", + desc = "command", + icon = { icon = "", color = "blue" }, + }, + { + "cs$", + "(vimtex-env-change-math)", + desc = "math environment", + icon = { icon = "󰿈", color = "blue" }, + }, + { + "csd", + "(vimtex-delim-change-math)", + desc = "delimeter", + icon = { icon = "󰅩", color = "blue" }, + }, + { + "ts", + group = "+surrounding", + icon = { icon = "󰗅", color = "green" }, + mode = "nx", + }, + { + "tsf", + "(vimtex-cmd-toggle-frac)", + desc = "fraction", + icon = { icon = "󱦒", color = "yellow" }, + mode = "nx", + }, + { + "tsc", + "(vimtex-cmd-toggle-star)", + desc = "command", + icon = { icon = "", color = "yellow" }, + }, + { + "tse", + "(vimtex-env-toggle-star)", + desc = "environment", + icon = { icon = "", color = "yellow" }, + }, + { + "ts$", + "(vimtex-env-toggle-math)", + desc = "math environment", + icon = { icon = "󰿈", color = "yellow" }, + }, + { + "tsb", + "(vimtex-env-toggle-break)", + desc = "break", + icon = { icon = "󰿈", color = "yellow" }, + }, + { + "", + "(vimtex-env-surround-line)", + desc = "Surround line with environment", + icon = { icon = "", color = "purple" }, + }, + { + "", + "(vimtex-env-surround-visual)", + desc = "Surround selection with environment", + icon = { icon = "", color = "purple" }, + mode = "x", + }, + { + "tsd", + "(vimtex-delim-toggle-modifier)", + desc = "delimeter", + icon = { icon = "󰅩", color = "yellow" }, + mode = "nx", + }, + { + "tsD", + "(vimtex-delim-toggle-modifier-reverse)", + desc = "revers surrounding delimeter", + icon = { icon = "󰅩", color = "yellow" }, + mode = "nx", + }, + { + "", + "(vimtex-cmd-create)", + desc = "Create command", + icon = { icon = "󰅩", color = "green" }, + mode = "nxi", + }, + { + "]]", + "(vimtex-delim-close)", + desc = "Close delimeter", + icon = { icon = "󰅩", color = "green" }, + mode = "i", + }, + { + "", + "(vimtex-delim-add-modifiers)", + desc = "Add \\left and \\right", + icon = { icon = "󰅩", color = "green" }, + mode = "n", + }, + }, + { + mode = "xo", + { + "ac", + "(vimtex-ac)", + desc = "command", + icon = { icon = "", color = "orange" }, + }, + { + "ic", + "(vimtex-ic)", + desc = "command", + icon = { icon = "", color = "orange" }, + }, + { + "ad", + "(vimtex-ad)", + desc = "delimiter", + icon = { icon = "󰅩", color = "orange" }, + }, + { + "id", + "(vimtex-id)", + desc = "delimiter", + icon = { icon = "󰅩", color = "orange" }, + }, + { + "ae", + "(vimtex-ae)", + desc = "environment", + icon = { icon = "", color = "orange" }, + }, + { + "ie", + "(vimtex-ie)", + desc = "environment", + icon = { icon = "", color = "orange" }, + }, + { + "a$", + "(vimtex-a$)", + desc = "math", + icon = { icon = "󰿈", color = "orange" }, + }, + { + "i$", + "(vimtex-i$)", + desc = "math", + icon = { icon = "󰿈", color = "orange" }, + }, + { + "aP", + "(vimtex-aP)", + desc = "section", + icon = { icon = "󰚟", color = "orange" }, + }, + { + "iP", + "(vimtex-iP)", + desc = "section", + icon = { icon = "󰚟", color = "orange" }, + }, + { + "am", + "(vimtex-am)", + desc = "item", + icon = { icon = "", color = "orange" }, + }, + { + "im", + "(vimtex-im)", + desc = "item", + icon = { icon = "", color = "orange" }, + }, + }, + { + mode = "nxo", + { + "%", + "(vimtex-%)", + desc = "Matching pair", + icon = { icon = "󰐱", color = "cyan" }, + }, + { + "]]", + "(vimtex-]])", + desc = "Next end of a section", + icon = { icon = "󰚟", color = "cyan" }, + }, + { + "][", + "(vimtex-][)", + desc = "Next beginning of a section", + icon = { icon = "󰚟", color = "cyan" }, + }, + { + "[]", + "(vimtex-[])", + desc = "Previous end of a section", + icon = { icon = "󰚟", color = "cyan" }, + }, + { + "[[", + "(vimtex-[[)", + desc = "Previous beginning of a section", + icon = { icon = "󰚟", color = "cyan" }, + }, + { + "]m", + "(vimtex-]m)", + desc = "Next start of an environment", + icon = { icon = "", color = "cyan" }, + }, + { + "]M", + "(vimtex-]M)", + desc = "Next end of an environment", + icon = { icon = "", color = "cyan" }, + }, + { + "[m", + "(vimtex-[m)", + desc = "Previous start of an environment", + icon = { icon = "", color = "cyan" }, + }, + { + "[M", + "(vimtex-[M)", + desc = "Previous end of an environment", + icon = { icon = "", color = "cyan" }, + }, + { + "]n", + "(vimtex-]n)", + desc = "Next start of math", + icon = { icon = "󰿈", color = "cyan" }, + }, + { + "]N", + "(vimtex-]N)", + desc = "Next end of math", + icon = { icon = "󰿈", color = "cyan" }, + }, + { + "[n", + "(vimtex-[n)", + desc = "Previous start of math", + icon = { icon = "󰿈", color = "cyan" }, + }, + { + "[N", + "(vimtex-[N)", + desc = "Previous end of math", + icon = { icon = "󰿈", color = "cyan" }, + }, + { + "]r", + "(vimtex-]r)", + desc = "Next start of frame environment", + icon = { icon = "󰹉", color = "cyan" }, + }, + { + "]R", + "(vimtex-]R)", + desc = "Next end of frame environment", + icon = { icon = "󰹉", color = "cyan" }, + }, + { + "[r", + "(vimtex-[r)", + desc = "Previous start of frame environment", + icon = { icon = "󰹉", color = "cyan" }, + }, + { + "[R", + "(vimtex-[R)", + desc = "Previous end of frame environment", + icon = { icon = "󰹉", color = "cyan" }, + }, + { + "]/", + "(vimtex-]/)", + desc = "Next start of a comment", + icon = { icon = "", color = "cyan" }, + }, + { + "]*", + "(vimtex-]star)", + desc = "Next end of a comment", + icon = { icon = "", color = "cyan" }, + }, + { + "[/", + "(vimtex-[/)", + desc = "Previous start of a comment", + icon = { icon = "", color = "cyan" }, + }, + { + "[*", + "(vimtex-[star)", + desc = "Previous end of a comment", + icon = { icon = "", color = "cyan" }, + }, + }, + { + "K", + "(vimtex-doc-package)", + desc = "See package documentation", + icon = { icon = "󱔗", color = "azure" }, + }, + }) + end, }) end, keys = {