diff --git a/lua/keymap/completion.lua b/lua/keymap/completion.lua index 3a3cc0af4..634a6e961 100644 --- a/lua/keymap/completion.lua +++ b/lua/keymap/completion.lua @@ -2,15 +2,21 @@ local bind = require("keymap.bind") local map_cr = bind.map_cr local map_callback = bind.map_callback -local plug_map = { - ["n|"] = map_cr("FormatToggle"):with_noremap():with_silent():with_desc("formatter: Toggle format on save"), - ["n|"] = map_cr("Format"):with_noremap():with_silent():with_desc("formatter: Format buffer manually"), +local mappings = { + fmt = { + ["n|"] = map_cr("FormatToggle"):with_noremap():with_silent():with_desc("formatter: Toggle format on save"), + ["n|"] = map_cr("Format"):with_noremap():with_silent():with_desc("formatter: Format buffer manually"), + }, } -bind.nvim_load_mapping(plug_map) +bind.nvim_load_mapping(mappings.fmt) -local mapping = {} +--- The following code allows this file to be exported --- +--- for use with LSP lazy-loaded keymap bindings --- -function mapping.lsp(buf) +local M = {} + +---@param buf integer +function M.lsp(buf) local map = { -- LSP-related keymaps, ONLY effective in buffers with LSP(s) attached ["n|li"] = map_cr("LspInfo"):with_silent():with_buffer(buf):with_desc("lsp: Info"), @@ -82,4 +88,4 @@ function mapping.lsp(buf) end end -return mapping +return M diff --git a/lua/keymap/editor.lua b/lua/keymap/editor.lua index e14f4c4a6..8c8c8cd30 100644 --- a/lua/keymap/editor.lua +++ b/lua/keymap/editor.lua @@ -5,136 +5,136 @@ local map_cmd = bind.map_cmd local map_callback = bind.map_callback local et = bind.escape_termcode -local builtin_map = { - -- Builtin: save & quit - ["n|"] = map_cu("write"):with_noremap():with_silent():with_desc("edit: Save file"), - ["n|"] = map_cr("wq"):with_desc("edit: Save file and quit"), - ["n|"] = map_cr("q!"):with_desc("edit: Force quit"), +local mappings = { + builtins = { + -- Builtins: Save & Quit + ["n|"] = map_cu("write"):with_noremap():with_silent():with_desc("edit: Save file"), + ["n|"] = map_cr("wq"):with_desc("edit: Save file and quit"), + ["n|"] = map_cr("q!"):with_desc("edit: Force quit"), - -- Builtin: insert mode - ["i|"] = map_cmd("u"):with_noremap():with_desc("edit: Delete previous block"), - ["i|"] = map_cmd(""):with_noremap():with_desc("edit: Move cursor to left"), - ["i|"] = map_cmd("^i"):with_noremap():with_desc("edit: Move cursor to line start"), - ["i|"] = map_cmd(":w"):with_desc("edit: Save file"), - ["i|"] = map_cmd(":wq"):with_desc("edit: Save file and quit"), + -- Builtins: Insert mode + ["i|"] = map_cmd("u"):with_noremap():with_desc("edit: Delete previous block"), + ["i|"] = map_cmd(""):with_noremap():with_desc("edit: Move cursor to left"), + ["i|"] = map_cmd("^i"):with_noremap():with_desc("edit: Move cursor to line start"), + ["i|"] = map_cmd(":w"):with_desc("edit: Save file"), + ["i|"] = map_cmd(":wq"):with_desc("edit: Save file and quit"), - -- Builtin: command mode - ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Left"), - ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Right"), - ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Home"), - ["c|"] = map_cmd(""):with_noremap():with_desc("edit: End"), - ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Delete"), - ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Backspace"), - ["c|"] = map_cmd([[=expand("%:p:h") . "/" ]]) - :with_noremap() - :with_desc("edit: Complete path of current file"), + -- Builtins: Command mode + ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Left"), + ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Right"), + ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Home"), + ["c|"] = map_cmd(""):with_noremap():with_desc("edit: End"), + ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Delete"), + ["c|"] = map_cmd(""):with_noremap():with_desc("edit: Backspace"), + ["c|"] = map_cmd([[=expand("%:p:h") . "/" ]]) + :with_noremap() + :with_desc("edit: Complete path of current file"), - -- Builtin: visual mode - ["v|J"] = map_cmd(":m '>+1gv=gv"):with_desc("edit: Move this line down"), - ["v|K"] = map_cmd(":m '<-2gv=gv"):with_desc("edit: Move this line up"), - ["v|<"] = map_cmd(""] = map_cmd(">gv"):with_desc("edit: Increase indent"), + -- Builtins: Visual mode + ["v|J"] = map_cmd(":m '>+1gv=gv"):with_desc("edit: Move this line down"), + ["v|K"] = map_cmd(":m '<-2gv=gv"):with_desc("edit: Move this line up"), + ["v|<"] = map_cmd(""] = map_cmd(">gv"):with_desc("edit: Increase indent"), - -- Builtin: suckless - ["n|Y"] = map_cmd("y$"):with_desc("edit: Yank text to EOL"), - ["n|D"] = map_cmd("d$"):with_desc("edit: Delete text to EOL"), - ["n|n"] = map_cmd("nzzzv"):with_noremap():with_desc("edit: Next search result"), - ["n|N"] = map_cmd("Nzzzv"):with_noremap():with_desc("edit: Prev search result"), - ["n|J"] = map_cmd("mzJ`z"):with_noremap():with_desc("edit: Join next line"), - ["n|"] = map_cr("normal za"):with_noremap():with_silent():with_desc("edit: Toggle code fold"), - ["n|"] = map_callback(function() - _flash_esc_or_noh() - end) - :with_noremap() - :with_silent() - :with_desc("edit: Clear search highlight"), - ["n|o"] = map_cr("setlocal spell! spelllang=en_us"):with_desc("edit: Toggle spell check"), -} - -bind.nvim_load_mapping(builtin_map) - -local plug_map = { - -- Plugin: persisted.nvim - ["n|ss"] = map_cu("SessionSave"):with_noremap():with_silent():with_desc("session: Save"), - ["n|sl"] = map_cu("SessionLoad"):with_noremap():with_silent():with_desc("session: Load current"), - ["n|sd"] = map_cu("SessionDelete"):with_noremap():with_silent():with_desc("session: Delete"), + -- Builtins: "Suckless" - named after r/suckless + ["n|Y"] = map_cmd("y$"):with_desc("edit: Yank text to EOL"), + ["n|D"] = map_cmd("d$"):with_desc("edit: Delete text to EOL"), + ["n|n"] = map_cmd("nzzzv"):with_noremap():with_desc("edit: Next search result"), + ["n|N"] = map_cmd("Nzzzv"):with_noremap():with_desc("edit: Prev search result"), + ["n|J"] = map_cmd("mzJ`z"):with_noremap():with_desc("edit: Join next line"), + ["n|"] = map_cr("normal za"):with_noremap():with_silent():with_desc("edit: Toggle code fold"), + ["n|"] = map_callback(function() + _flash_esc_or_noh() + end) + :with_noremap() + :with_silent() + :with_desc("edit: Clear search highlight"), + ["n|o"] = map_cr("setlocal spell! spelllang=en_us"):with_desc("edit: Toggle spell check"), + }, + plugins = { + -- Plugin: persisted.nvim + ["n|ss"] = map_cu("SessionSave"):with_noremap():with_silent():with_desc("session: Save"), + ["n|sl"] = map_cu("SessionLoad"):with_noremap():with_silent():with_desc("session: Load current"), + ["n|sd"] = map_cu("SessionDelete"):with_noremap():with_silent():with_desc("session: Delete"), - -- Plugin: comment.nvim - ["n|gcc"] = map_callback(function() - return vim.v.count == 0 and et("(comment_toggle_linewise_current)") - or et("(comment_toggle_linewise_count)") - end) - :with_silent() - :with_noremap() - :with_expr() - :with_desc("edit: Toggle comment for line"), - ["n|gbc"] = map_callback(function() - return vim.v.count == 0 and et("(comment_toggle_blockwise_current)") - or et("(comment_toggle_blockwise_count)") - end) - :with_silent() - :with_noremap() - :with_expr() - :with_desc("edit: Toggle comment for block"), - ["n|gc"] = map_cmd("(comment_toggle_linewise)") - :with_silent() - :with_noremap() - :with_desc("edit: Toggle comment for line with operator"), - ["n|gb"] = map_cmd("(comment_toggle_blockwise)") - :with_silent() - :with_noremap() - :with_desc("edit: Toggle comment for block with operator"), - ["x|gc"] = map_cmd("(comment_toggle_linewise_visual)") - :with_silent() - :with_noremap() - :with_desc("edit: Toggle comment for line with selection"), - ["x|gb"] = map_cmd("(comment_toggle_blockwise_visual)") - :with_silent() - :with_noremap() - :with_desc("edit: Toggle comment for block with selection"), + -- Plugin: comment.nvim + ["n|gcc"] = map_callback(function() + return vim.v.count == 0 and et("(comment_toggle_linewise_current)") + or et("(comment_toggle_linewise_count)") + end) + :with_silent() + :with_noremap() + :with_expr() + :with_desc("edit: Toggle comment for line"), + ["n|gbc"] = map_callback(function() + return vim.v.count == 0 and et("(comment_toggle_blockwise_current)") + or et("(comment_toggle_blockwise_count)") + end) + :with_silent() + :with_noremap() + :with_expr() + :with_desc("edit: Toggle comment for block"), + ["n|gc"] = map_cmd("(comment_toggle_linewise)") + :with_silent() + :with_noremap() + :with_desc("edit: Toggle comment for line with operator"), + ["n|gb"] = map_cmd("(comment_toggle_blockwise)") + :with_silent() + :with_noremap() + :with_desc("edit: Toggle comment for block with operator"), + ["x|gc"] = map_cmd("(comment_toggle_linewise_visual)") + :with_silent() + :with_noremap() + :with_desc("edit: Toggle comment for line with selection"), + ["x|gb"] = map_cmd("(comment_toggle_blockwise_visual)") + :with_silent() + :with_noremap() + :with_desc("edit: Toggle comment for block with selection"), - -- Plugin: diffview.nvim - ["n|gd"] = map_cr("DiffviewOpen"):with_silent():with_noremap():with_desc("git: Show diff"), - ["n|gD"] = map_cr("DiffviewClose"):with_silent():with_noremap():with_desc("git: Close diff"), + -- Plugin: diffview.nvim + ["n|gd"] = map_cr("DiffviewOpen"):with_silent():with_noremap():with_desc("git: Show diff"), + ["n|gD"] = map_cr("DiffviewClose"):with_silent():with_noremap():with_desc("git: Close diff"), - -- Plugin: hop.nvim - ["nv|w"] = map_cmd("HopWordMW"):with_noremap():with_desc("jump: Goto word"), - ["nv|j"] = map_cmd("HopLineMW"):with_noremap():with_desc("jump: Goto line"), - ["nv|k"] = map_cmd("HopLineMW"):with_noremap():with_desc("jump: Goto line"), - ["nv|c"] = map_cmd("HopChar1MW"):with_noremap():with_desc("jump: Goto one char"), - ["nv|C"] = map_cmd("HopChar2MW"):with_noremap():with_desc("jump: Goto two chars"), + -- Plugin: hop.nvim + ["nv|w"] = map_cmd("HopWordMW"):with_noremap():with_desc("jump: Goto word"), + ["nv|j"] = map_cmd("HopLineMW"):with_noremap():with_desc("jump: Goto line"), + ["nv|k"] = map_cmd("HopLineMW"):with_noremap():with_desc("jump: Goto line"), + ["nv|c"] = map_cmd("HopChar1MW"):with_noremap():with_desc("jump: Goto one char"), + ["nv|C"] = map_cmd("HopChar2MW"):with_noremap():with_desc("jump: Goto two chars"), - -- Plugin: nvim-spectre - ["n|Ss"] = map_callback(function() - require("spectre").toggle() - end) - :with_silent() - :with_noremap() - :with_desc("editn: Toggle search & replace panel"), - ["n|Sp"] = map_callback(function() - require("spectre").open_visual({ select_word = true }) - end) - :with_silent() - :with_noremap() - :with_desc("editn: search&replace current word (project)"), - ["v|Sp"] = map_callback(function() - require("spectre").open_visual() - end) - :with_silent() - :with_noremap() - :with_desc("edit: search & replace current word (project)"), - ["n|Sf"] = map_callback(function() - require("spectre").open_file_search({ select_word = true }) - end) - :with_silent() - :with_noremap() - :with_desc("editn: search & replace current word (file)"), + -- Plugin: nvim-spectre + ["n|Ss"] = map_callback(function() + require("spectre").toggle() + end) + :with_silent() + :with_noremap() + :with_desc("editn: Toggle search & replace panel"), + ["n|Sp"] = map_callback(function() + require("spectre").open_visual({ select_word = true }) + end) + :with_silent() + :with_noremap() + :with_desc("editn: search&replace current word (project)"), + ["v|Sp"] = map_callback(function() + require("spectre").open_visual() + end) + :with_silent() + :with_noremap() + :with_desc("edit: search & replace current word (project)"), + ["n|Sf"] = map_callback(function() + require("spectre").open_file_search({ select_word = true }) + end) + :with_silent() + :with_noremap() + :with_desc("editn: search & replace current word (file)"), - -- Plugin: nvim-treehopper - ["o|m"] = map_cu("lua require('tsht').nodes()"):with_silent():with_desc("jump: Operate across syntax tree"), + -- Plugin: nvim-treehopper + ["o|m"] = map_cu("lua require('tsht').nodes()"):with_silent():with_desc("jump: Operate across syntax tree"), - -- Plugin: suda.vim - ["n|"] = map_cu("SudaWrite"):with_silent():with_noremap():with_desc("editn: Save file using sudo"), + -- Plugin: suda.vim + ["n|"] = map_cu("SudaWrite"):with_silent():with_noremap():with_desc("editn: Save file using sudo"), + }, } -bind.nvim_load_mapping(plug_map) +bind.nvim_load_mapping(mappings.builtins) +bind.nvim_load_mapping(mappings.plugins) diff --git a/lua/keymap/init.lua b/lua/keymap/init.lua index dfef620c9..26120272a 100644 --- a/lua/keymap/init.lua +++ b/lua/keymap/init.lua @@ -1,27 +1,42 @@ require("keymap.helpers") local bind = require("keymap.bind") local map_cr = bind.map_cr --- local map_cu = bind.map_cu --- local map_cmd = bind.map_cmd --- local map_callback = bind.map_callback -local plug_map = { - -- Package manager: lazy.nvim - ["n|ph"] = map_cr("Lazy"):with_silent():with_noremap():with_nowait():with_desc("package: Show"), - ["n|ps"] = map_cr("Lazy sync"):with_silent():with_noremap():with_nowait():with_desc("package: Sync"), - ["n|pu"] = map_cr("Lazy update"):with_silent():with_noremap():with_nowait():with_desc("package: Update"), - ["n|pi"] = map_cr("Lazy install"):with_silent():with_noremap():with_nowait():with_desc("package: Install"), - ["n|pl"] = map_cr("Lazy log"):with_silent():with_noremap():with_nowait():with_desc("package: Log"), - ["n|pc"] = map_cr("Lazy check"):with_silent():with_noremap():with_nowait():with_desc("package: Check"), - ["n|pd"] = map_cr("Lazy debug"):with_silent():with_noremap():with_nowait():with_desc("package: Debug"), - ["n|pp"] = map_cr("Lazy profile"):with_silent():with_noremap():with_nowait():with_desc("package: Profile"), - ["n|pr"] = map_cr("Lazy restore"):with_silent():with_noremap():with_nowait():with_desc("package: Restore"), - ["n|px"] = map_cr("Lazy clean"):with_silent():with_noremap():with_nowait():with_desc("package: Clean"), +local mappings = { + core = { + -- Package manager: lazy.nvim + ["n|ph"] = map_cr("Lazy"):with_silent():with_noremap():with_nowait():with_desc("package: Show"), + ["n|ps"] = map_cr("Lazy sync"):with_silent():with_noremap():with_nowait():with_desc("package: Sync"), + ["n|pu"] = map_cr("Lazy update") + :with_silent() + :with_noremap() + :with_nowait() + :with_desc("package: Update"), + ["n|pi"] = map_cr("Lazy install") + :with_silent() + :with_noremap() + :with_nowait() + :with_desc("package: Install"), + ["n|pl"] = map_cr("Lazy log"):with_silent():with_noremap():with_nowait():with_desc("package: Log"), + ["n|pc"] = map_cr("Lazy check"):with_silent():with_noremap():with_nowait():with_desc("package: Check"), + ["n|pd"] = map_cr("Lazy debug"):with_silent():with_noremap():with_nowait():with_desc("package: Debug"), + ["n|pp"] = map_cr("Lazy profile") + :with_silent() + :with_noremap() + :with_nowait() + :with_desc("package: Profile"), + ["n|pr"] = map_cr("Lazy restore") + :with_silent() + :with_noremap() + :with_nowait() + :with_desc("package: Restore"), + ["n|px"] = map_cr("Lazy clean"):with_silent():with_noremap():with_nowait():with_desc("package: Clean"), + }, } -bind.nvim_load_mapping(plug_map) +bind.nvim_load_mapping(mappings.core) --- Plugin keymaps +-- Builtin & Plugin keymaps require("keymap.completion") require("keymap.editor") require("keymap.lang") @@ -29,7 +44,7 @@ require("keymap.tool") require("keymap.ui") -- User keymaps -local ok, mappings = pcall(require, "user.keymap.init") +local ok, def = pcall(require, "user.keymap.init") if ok then - require("modules.utils.keymap").replace(mappings) + require("modules.utils.keymap").replace(def) end diff --git a/lua/keymap/lang.lua b/lua/keymap/lang.lua index aef337350..fc2fba9ed 100644 --- a/lua/keymap/lang.lua +++ b/lua/keymap/lang.lua @@ -1,17 +1,16 @@ local bind = require("keymap.bind") local map_cr = bind.map_cr --- local map_cu = bind.map_cu --- local map_cmd = bind.map_cmd --- local map_callback = bind.map_callback -local plug_map = { - -- Plugin render-markdown.nvim - ["n|"] = map_cr("RenderMarkdown toggle") - :with_noremap() - :with_silent() - :with_desc("tool: toggle markdown preview within nvim"), - -- Plugin MarkdownPreview - ["n|"] = map_cr("MarkdownPreviewToggle"):with_noremap():with_silent():with_desc("tool: Preview markdown"), +local mappings = { + plugins = { + -- Plugins: render-markdown.nvim + ["n|"] = map_cr("RenderMarkdown toggle") + :with_noremap() + :with_silent() + :with_desc("tool: toggle markdown preview within nvim"), + -- Plugins: MarkdownPreview + ["n|"] = map_cr("MarkdownPreviewToggle"):with_noremap():with_silent():with_desc("tool: Preview markdown"), + }, } -bind.nvim_load_mapping(plug_map) +bind.nvim_load_mapping(mappings.plugins) diff --git a/lua/keymap/tool.lua b/lua/keymap/tool.lua index 471e9b1a4..6be7780a7 100644 --- a/lua/keymap/tool.lua +++ b/lua/keymap/tool.lua @@ -6,200 +6,214 @@ local map_callback = bind.map_callback local vim_path = require("core.global").vim_path require("keymap.helpers") -local plug_map = { - -- Plugin: edgy - ["n|"] = map_callback(function() - require("edgy").toggle("left") - end) - :with_noremap() - :with_silent() - :with_desc("filetree: Toggle"), +local mappings = { + plugins = { + -- Plugin: edgy + ["n|"] = map_callback(function() + require("edgy").toggle("left") + end) + :with_noremap() + :with_silent() + :with_desc("filetree: Toggle"), - -- Plugin: vim-fugitive - ["n|gps"] = map_cr("G push"):with_noremap():with_silent():with_desc("git: Push"), - ["n|gpl"] = map_cr("G pull"):with_noremap():with_silent():with_desc("git: Pull"), - ["n|gG"] = map_cu("Git"):with_noremap():with_silent():with_desc("git: Open git-fugitive"), + -- Plugin: vim-fugitive + ["n|gps"] = map_cr("G push"):with_noremap():with_silent():with_desc("git: Push"), + ["n|gpl"] = map_cr("G pull"):with_noremap():with_silent():with_desc("git: Pull"), + ["n|gG"] = map_cu("Git"):with_noremap():with_silent():with_desc("git: Open git-fugitive"), - -- Plugin: nvim-tree - ["n|nf"] = map_cr("NvimTreeFindFile"):with_noremap():with_silent():with_desc("filetree: Find file"), - ["n|nr"] = map_cr("NvimTreeRefresh"):with_noremap():with_silent():with_desc("filetree: Refresh"), + -- Plugin: nvim-tree + ["n|nf"] = map_cr("NvimTreeFindFile"):with_noremap():with_silent():with_desc("filetree: Find file"), + ["n|nr"] = map_cr("NvimTreeRefresh"):with_noremap():with_silent():with_desc("filetree: Refresh"), - -- Plugin: sniprun - ["v|r"] = map_cr("SnipRun"):with_noremap():with_silent():with_desc("tool: Run code by range"), - ["n|r"] = map_cu([[%SnipRun]]):with_noremap():with_silent():with_desc("tool: Run code by file"), + -- Plugin: sniprun + ["v|r"] = map_cr("SnipRun"):with_noremap():with_silent():with_desc("tool: Run code by range"), + ["n|r"] = map_cu([[%SnipRun]]):with_noremap():with_silent():with_desc("tool: Run code by file"), - -- Plugin: toggleterm - ["t|"] = map_cmd([[]]):with_noremap():with_silent(), -- switch to normal mode in terminal. - ["n|"] = map_cr("ToggleTerm direction=horizontal") - :with_noremap() - :with_silent() - :with_desc("terminal: Toggle horizontal"), - ["i|"] = map_cmd("ToggleTerm direction=horizontal") - :with_noremap() - :with_silent() - :with_desc("terminal: Toggle horizontal"), - ["t|"] = map_cmd("ToggleTerm"):with_noremap():with_silent():with_desc("terminal: Toggle horizontal"), - ["n|"] = map_cr("ToggleTerm direction=vertical") - :with_noremap() - :with_silent() - :with_desc("terminal: Toggle vertical"), - ["i|"] = map_cmd("ToggleTerm direction=vertical") - :with_noremap() - :with_silent() - :with_desc("terminal: Toggle vertical"), - ["t|"] = map_cmd("ToggleTerm"):with_noremap():with_silent():with_desc("terminal: Toggle vertical"), - ["n|"] = map_cr("ToggleTerm direction=vertical") - :with_noremap() - :with_silent() - :with_desc("terminal: Toggle vertical"), - ["i|"] = map_cmd("ToggleTerm direction=vertical") - :with_noremap() - :with_silent() - :with_desc("terminal: Toggle vertical"), - ["t|"] = map_cmd("ToggleTerm"):with_noremap():with_silent():with_desc("terminal: Toggle vertical"), - ["n|"] = map_cr("ToggleTerm direction=float"):with_noremap():with_silent():with_desc("terminal: Toggle float"), - ["i|"] = map_cmd("ToggleTerm direction=float") - :with_noremap() - :with_silent() - :with_desc("terminal: Toggle float"), - ["t|"] = map_cmd("ToggleTerm"):with_noremap():with_silent():with_desc("terminal: Toggle float"), - ["n|gg"] = map_callback(function() - _toggle_lazygit() - end) - :with_noremap() - :with_silent() - :with_desc("git: Toggle lazygit"), + -- Plugin: toggleterm + ["t|"] = map_cmd([[]]):with_noremap():with_silent(), -- switch to normal mode in terminal. + ["n|"] = map_cr("ToggleTerm direction=horizontal") + :with_noremap() + :with_silent() + :with_desc("terminal: Toggle horizontal"), + ["i|"] = map_cmd("ToggleTerm direction=horizontal") + :with_noremap() + :with_silent() + :with_desc("terminal: Toggle horizontal"), + ["t|"] = map_cmd("ToggleTerm") + :with_noremap() + :with_silent() + :with_desc("terminal: Toggle horizontal"), + ["n|"] = map_cr("ToggleTerm direction=vertical") + :with_noremap() + :with_silent() + :with_desc("terminal: Toggle vertical"), + ["i|"] = map_cmd("ToggleTerm direction=vertical") + :with_noremap() + :with_silent() + :with_desc("terminal: Toggle vertical"), + ["t|"] = map_cmd("ToggleTerm") + :with_noremap() + :with_silent() + :with_desc("terminal: Toggle vertical"), + ["n|"] = map_cr("ToggleTerm direction=vertical") + :with_noremap() + :with_silent() + :with_desc("terminal: Toggle vertical"), + ["i|"] = map_cmd("ToggleTerm direction=vertical") + :with_noremap() + :with_silent() + :with_desc("terminal: Toggle vertical"), + ["t|"] = map_cmd("ToggleTerm"):with_noremap():with_silent():with_desc("terminal: Toggle vertical"), + ["n|"] = map_cr("ToggleTerm direction=float") + :with_noremap() + :with_silent() + :with_desc("terminal: Toggle float"), + ["i|"] = map_cmd("ToggleTerm direction=float") + :with_noremap() + :with_silent() + :with_desc("terminal: Toggle float"), + ["t|"] = map_cmd("ToggleTerm"):with_noremap():with_silent():with_desc("terminal: Toggle float"), + ["n|gg"] = map_callback(function() + _toggle_lazygit() + end) + :with_noremap() + :with_silent() + :with_desc("git: Toggle lazygit"), - -- Plugin: trouble - ["n|gt"] = map_cr("Trouble diagnostics toggle"):with_noremap():with_silent():with_desc("lsp: Toggle trouble list"), - ["n|lw"] = map_cr("Trouble diagnostics toggle") - :with_noremap() - :with_silent() - :with_desc("lsp: Show workspace diagnostics"), - ["n|lp"] = map_cr("Trouble project_diagnostics toggle") - :with_noremap() - :with_silent() - :with_desc("lsp: Show project diagnostics"), - ["n|ld"] = map_cr("Trouble diagnostics toggle filter.buf=0") - :with_noremap() - :with_silent() - :with_desc("lsp: Show document diagnostics"), + -- Plugin: trouble + ["n|gt"] = map_cr("Trouble diagnostics toggle") + :with_noremap() + :with_silent() + :with_desc("lsp: Toggle trouble list"), + ["n|lw"] = map_cr("Trouble diagnostics toggle") + :with_noremap() + :with_silent() + :with_desc("lsp: Show workspace diagnostics"), + ["n|lp"] = map_cr("Trouble project_diagnostics toggle") + :with_noremap() + :with_silent() + :with_desc("lsp: Show project diagnostics"), + ["n|ld"] = map_cr("Trouble diagnostics toggle filter.buf=0") + :with_noremap() + :with_silent() + :with_desc("lsp: Show document diagnostics"), - -- Plugin: telescope - ["n|"] = map_callback(function() - _command_panel() - end) - :with_noremap() - :with_silent() - :with_desc("tool: Toggle command panel"), - ["n|fc"] = map_callback(function() - _telescope_collections(require("telescope.themes").get_dropdown()) - end) - :with_noremap() - :with_silent() - :with_desc("tool: Open Telescope collections"), - ["n|ff"] = map_callback(function() - require("search").open({ collection = "file" }) - end) - :with_noremap() - :with_silent() - :with_desc("tool: Find files"), - ["n|fp"] = map_callback(function() - require("search").open({ collection = "pattern" }) - end) - :with_noremap() - :with_silent() - :with_desc("tool: Find patterns"), - ["v|fs"] = map_callback(function() - local opts = {} - if vim.fn.getcwd() == vim_path then - opts["additional_args"] = { "--no-ignore" } - end - require("telescope-live-grep-args.shortcuts").grep_visual_selection(opts) - end) - :with_noremap() - :with_silent() - :with_desc("tool: Find word under cursor"), - ["n|fg"] = map_callback(function() - require("search").open({ collection = "git" }) - end) - :with_noremap() - :with_silent() - :with_desc("tool: Locate Git objects"), - ["n|fd"] = map_callback(function() - require("search").open({ collection = "dossier" }) - end) - :with_noremap() - :with_silent() - :with_desc("tool: Retrieve dossiers"), - ["n|fm"] = map_callback(function() - require("search").open({ collection = "misc" }) - end) - :with_noremap() - :with_silent() - :with_desc("tool: Miscellaneous"), + -- Plugin: telescope + ["n|"] = map_callback(function() + _command_panel() + end) + :with_noremap() + :with_silent() + :with_desc("tool: Toggle command panel"), + ["n|fc"] = map_callback(function() + _telescope_collections(require("telescope.themes").get_dropdown()) + end) + :with_noremap() + :with_silent() + :with_desc("tool: Open Telescope collections"), + ["n|ff"] = map_callback(function() + require("search").open({ collection = "file" }) + end) + :with_noremap() + :with_silent() + :with_desc("tool: Find files"), + ["n|fp"] = map_callback(function() + require("search").open({ collection = "pattern" }) + end) + :with_noremap() + :with_silent() + :with_desc("tool: Find patterns"), + ["v|fs"] = map_callback(function() + local opts = {} + if vim.fn.getcwd() == vim_path then + opts["additional_args"] = { "--no-ignore" } + end + require("telescope-live-grep-args.shortcuts").grep_visual_selection(opts) + end) + :with_noremap() + :with_silent() + :with_desc("tool: Find word under cursor"), + ["n|fg"] = map_callback(function() + require("search").open({ collection = "git" }) + end) + :with_noremap() + :with_silent() + :with_desc("tool: Locate Git objects"), + ["n|fd"] = map_callback(function() + require("search").open({ collection = "dossier" }) + end) + :with_noremap() + :with_silent() + :with_desc("tool: Retrieve dossiers"), + ["n|fm"] = map_callback(function() + require("search").open({ collection = "misc" }) + end) + :with_noremap() + :with_silent() + :with_desc("tool: Miscellaneous"), - -- Plugin: dap - ["n|"] = map_callback(function() - _async_compile_and_debug() - end) - :with_noremap() - :with_silent() - :with_desc("debug: Run/Continue"), - ["n|"] = map_callback(function() - require("dap").terminate() - end) - :with_noremap() - :with_silent() - :with_desc("debug: Stop"), - ["n|"] = map_callback(function() - require("dap").toggle_breakpoint() - end) - :with_noremap() - :with_silent() - :with_desc("debug: Toggle breakpoint"), - ["n|"] = map_callback(function() - require("dap").step_into() - end) - :with_noremap() - :with_silent() - :with_desc("debug: Step into"), - ["n|"] = map_callback(function() - require("dap").step_out() - end) - :with_noremap() - :with_silent() - :with_desc("debug: Step out"), - ["n|"] = map_callback(function() - require("dap").step_over() - end) - :with_noremap() - :with_silent() - :with_desc("debug: Step over"), - ["n|db"] = map_callback(function() - require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: ")) - end) - :with_noremap() - :with_silent() - :with_desc("debug: Set breakpoint with condition"), - ["n|dc"] = map_callback(function() - require("dap").run_to_cursor() - end) - :with_noremap() - :with_silent() - :with_desc("debug: Run to cursor"), - ["n|dl"] = map_callback(function() - require("dap").run_last() - end) - :with_noremap() - :with_silent() - :with_desc("debug: Run last"), - ["n|do"] = map_callback(function() - require("dap").repl.open() - end) - :with_noremap() - :with_silent() - :with_desc("debug: Open REPL"), + -- Plugin: dap + ["n|"] = map_callback(function() + _async_compile_and_debug() + end) + :with_noremap() + :with_silent() + :with_desc("debug: Run/Continue"), + ["n|"] = map_callback(function() + require("dap").terminate() + end) + :with_noremap() + :with_silent() + :with_desc("debug: Stop"), + ["n|"] = map_callback(function() + require("dap").toggle_breakpoint() + end) + :with_noremap() + :with_silent() + :with_desc("debug: Toggle breakpoint"), + ["n|"] = map_callback(function() + require("dap").step_into() + end) + :with_noremap() + :with_silent() + :with_desc("debug: Step into"), + ["n|"] = map_callback(function() + require("dap").step_out() + end) + :with_noremap() + :with_silent() + :with_desc("debug: Step out"), + ["n|"] = map_callback(function() + require("dap").step_over() + end) + :with_noremap() + :with_silent() + :with_desc("debug: Step over"), + ["n|db"] = map_callback(function() + require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: ")) + end) + :with_noremap() + :with_silent() + :with_desc("debug: Set breakpoint with condition"), + ["n|dc"] = map_callback(function() + require("dap").run_to_cursor() + end) + :with_noremap() + :with_silent() + :with_desc("debug: Run to cursor"), + ["n|dl"] = map_callback(function() + require("dap").run_last() + end) + :with_noremap() + :with_silent() + :with_desc("debug: Run last"), + ["n|do"] = map_callback(function() + require("dap").repl.open() + end) + :with_noremap() + :with_silent() + :with_desc("debug: Open REPL"), + }, } -bind.nvim_load_mapping(plug_map) +bind.nvim_load_mapping(mappings.plugins) diff --git a/lua/keymap/ui.lua b/lua/keymap/ui.lua index 545ddc567..81ac66529 100644 --- a/lua/keymap/ui.lua +++ b/lua/keymap/ui.lua @@ -2,68 +2,91 @@ local bind = require("keymap.bind") local map_cr = bind.map_cr local map_cu = bind.map_cu local map_cmd = bind.map_cmd --- local map_callback = bind.map_callback -local builtin_map = { - -- Builtin: buffer - ["n|bn"] = map_cu("enew"):with_noremap():with_silent():with_desc("buffer: New"), +local mappings = { + builtins = { + -- Builtins: Buffer + ["n|bn"] = map_cu("enew"):with_noremap():with_silent():with_desc("buffer: New"), - -- Builtin: terminal - ["t|h"] = map_cmd("wincmd h"):with_silent():with_noremap():with_desc("window: Focus left"), - ["t|l"] = map_cmd("wincmd l"):with_silent():with_noremap():with_desc("window: Focus right"), - ["t|j"] = map_cmd("wincmd j"):with_silent():with_noremap():with_desc("window: Focus down"), - ["t|k"] = map_cmd("wincmd k"):with_silent():with_noremap():with_desc("window: Focus up"), + -- Builtins: Terminal + ["t|h"] = map_cmd("wincmd h"):with_silent():with_noremap():with_desc("window: Focus left"), + ["t|l"] = map_cmd("wincmd l"):with_silent():with_noremap():with_desc("window: Focus right"), + ["t|j"] = map_cmd("wincmd j"):with_silent():with_noremap():with_desc("window: Focus down"), + ["t|k"] = map_cmd("wincmd k"):with_silent():with_noremap():with_desc("window: Focus up"), - -- Builtin: tab - ["n|tn"] = map_cr("tabnew"):with_noremap():with_silent():with_desc("tab: Create a new tab"), - ["n|tk"] = map_cr("tabnext"):with_noremap():with_silent():with_desc("tab: Move to next tab"), - ["n|tj"] = map_cr("tabprevious"):with_noremap():with_silent():with_desc("tab: Move to previous tab"), - ["n|to"] = map_cr("tabonly"):with_noremap():with_silent():with_desc("tab: Only keep current tab"), -} - -bind.nvim_load_mapping(builtin_map) + -- Builtins: Tabpage + ["n|tn"] = map_cr("tabnew"):with_noremap():with_silent():with_desc("tab: Create a new tab"), + ["n|tk"] = map_cr("tabnext"):with_noremap():with_silent():with_desc("tab: Move to next tab"), + ["n|tj"] = map_cr("tabprevious"):with_noremap():with_silent():with_desc("tab: Move to previous tab"), + ["n|to"] = map_cr("tabonly"):with_noremap():with_silent():with_desc("tab: Only keep current tab"), + }, + plugins = { + -- Plugin: nvim-bufdel + ["n|"] = map_cr("BufDel"):with_noremap():with_silent():with_desc("buffer: Close current"), -local plug_map = { - -- Plugin: nvim-bufdel - ["n|"] = map_cr("BufDel"):with_noremap():with_silent():with_desc("buffer: Close current"), + -- Plugin: bufferline.nvim + ["n|"] = map_cr("BufferLineCycleNext"):with_noremap():with_silent():with_desc("buffer: Switch to next"), + ["n|"] = map_cr("BufferLineCyclePrev"):with_noremap():with_silent():with_desc("buffer: Switch to prev"), + ["n|"] = map_cr("BufferLineMoveNext") + :with_noremap() + :with_silent() + :with_desc("buffer: Move current to next"), + ["n|"] = map_cr("BufferLineMovePrev") + :with_noremap() + :with_silent() + :with_desc("buffer: Move current to prev"), + ["n|be"] = map_cr("BufferLineSortByExtension"):with_noremap():with_desc("buffer: Sort by extension"), + ["n|bd"] = map_cr("BufferLineSortByDirectory"):with_noremap():with_desc("buffer: Sort by directory"), + ["n|"] = map_cr("BufferLineGoToBuffer 1"):with_noremap():with_silent():with_desc("buffer: Goto buffer 1"), + ["n|"] = map_cr("BufferLineGoToBuffer 2"):with_noremap():with_silent():with_desc("buffer: Goto buffer 2"), + ["n|"] = map_cr("BufferLineGoToBuffer 3"):with_noremap():with_silent():with_desc("buffer: Goto buffer 3"), + ["n|"] = map_cr("BufferLineGoToBuffer 4"):with_noremap():with_silent():with_desc("buffer: Goto buffer 4"), + ["n|"] = map_cr("BufferLineGoToBuffer 5"):with_noremap():with_silent():with_desc("buffer: Goto buffer 5"), + ["n|"] = map_cr("BufferLineGoToBuffer 6"):with_noremap():with_silent():with_desc("buffer: Goto buffer 6"), + ["n|"] = map_cr("BufferLineGoToBuffer 7"):with_noremap():with_silent():with_desc("buffer: Goto buffer 7"), + ["n|"] = map_cr("BufferLineGoToBuffer 8"):with_noremap():with_silent():with_desc("buffer: Goto buffer 8"), + ["n|"] = map_cr("BufferLineGoToBuffer 9"):with_noremap():with_silent():with_desc("buffer: Goto buffer 9"), - -- Plugin: bufferline.nvim - ["n|"] = map_cr("BufferLineCycleNext"):with_noremap():with_silent():with_desc("buffer: Switch to next"), - ["n|"] = map_cr("BufferLineCyclePrev"):with_noremap():with_silent():with_desc("buffer: Switch to prev"), - ["n|"] = map_cr("BufferLineMoveNext"):with_noremap():with_silent():with_desc("buffer: Move current to next"), - ["n|"] = map_cr("BufferLineMovePrev"):with_noremap():with_silent():with_desc("buffer: Move current to prev"), - ["n|be"] = map_cr("BufferLineSortByExtension"):with_noremap():with_desc("buffer: Sort by extension"), - ["n|bd"] = map_cr("BufferLineSortByDirectory"):with_noremap():with_desc("buffer: Sort by directory"), - ["n|"] = map_cr("BufferLineGoToBuffer 1"):with_noremap():with_silent():with_desc("buffer: Goto buffer 1"), - ["n|"] = map_cr("BufferLineGoToBuffer 2"):with_noremap():with_silent():with_desc("buffer: Goto buffer 2"), - ["n|"] = map_cr("BufferLineGoToBuffer 3"):with_noremap():with_silent():with_desc("buffer: Goto buffer 3"), - ["n|"] = map_cr("BufferLineGoToBuffer 4"):with_noremap():with_silent():with_desc("buffer: Goto buffer 4"), - ["n|"] = map_cr("BufferLineGoToBuffer 5"):with_noremap():with_silent():with_desc("buffer: Goto buffer 5"), - ["n|"] = map_cr("BufferLineGoToBuffer 6"):with_noremap():with_silent():with_desc("buffer: Goto buffer 6"), - ["n|"] = map_cr("BufferLineGoToBuffer 7"):with_noremap():with_silent():with_desc("buffer: Goto buffer 7"), - ["n|"] = map_cr("BufferLineGoToBuffer 8"):with_noremap():with_silent():with_desc("buffer: Goto buffer 8"), - ["n|"] = map_cr("BufferLineGoToBuffer 9"):with_noremap():with_silent():with_desc("buffer: Goto buffer 9"), - - -- Plugin: smart-splits.nvim - ["n|"] = map_cu("SmartResizeLeft"):with_silent():with_noremap():with_desc("window: Resize -3 horizontally"), - ["n|"] = map_cu("SmartResizeDown"):with_silent():with_noremap():with_desc("window: Resize -3 vertically"), - ["n|"] = map_cu("SmartResizeUp"):with_silent():with_noremap():with_desc("window: Resize +3 vertically"), - ["n|"] = map_cu("SmartResizeRight"):with_silent():with_noremap():with_desc("window: Resize +3 horizontally"), - ["n|"] = map_cu("SmartCursorMoveLeft"):with_silent():with_noremap():with_desc("window: Focus left"), - ["n|"] = map_cu("SmartCursorMoveDown"):with_silent():with_noremap():with_desc("window: Focus down"), - ["n|"] = map_cu("SmartCursorMoveUp"):with_silent():with_noremap():with_desc("window: Focus up"), - ["n|"] = map_cu("SmartCursorMoveRight"):with_silent():with_noremap():with_desc("window: Focus right"), - ["n|Wh"] = map_cu("SmartSwapLeft"):with_silent():with_noremap():with_desc("window: Move window leftward"), - ["n|Wj"] = map_cu("SmartSwapDown"):with_silent():with_noremap():with_desc("window: Move window downward"), - ["n|Wk"] = map_cu("SmartSwapUp"):with_silent():with_noremap():with_desc("window: Move window upward"), - ["n|Wl"] = map_cu("SmartSwapRight"):with_silent():with_noremap():with_desc("window: Move window rightward"), + -- Plugin: smart-splits.nvim + ["n|"] = map_cu("SmartResizeLeft") + :with_silent() + :with_noremap() + :with_desc("window: Resize -3 horizontally"), + ["n|"] = map_cu("SmartResizeDown"):with_silent():with_noremap():with_desc("window: Resize -3 vertically"), + ["n|"] = map_cu("SmartResizeUp"):with_silent():with_noremap():with_desc("window: Resize +3 vertically"), + ["n|"] = map_cu("SmartResizeRight") + :with_silent() + :with_noremap() + :with_desc("window: Resize +3 horizontally"), + ["n|"] = map_cu("SmartCursorMoveLeft"):with_silent():with_noremap():with_desc("window: Focus left"), + ["n|"] = map_cu("SmartCursorMoveDown"):with_silent():with_noremap():with_desc("window: Focus down"), + ["n|"] = map_cu("SmartCursorMoveUp"):with_silent():with_noremap():with_desc("window: Focus up"), + ["n|"] = map_cu("SmartCursorMoveRight"):with_silent():with_noremap():with_desc("window: Focus right"), + ["n|Wh"] = map_cu("SmartSwapLeft") + :with_silent() + :with_noremap() + :with_desc("window: Move window leftward"), + ["n|Wj"] = map_cu("SmartSwapDown") + :with_silent() + :with_noremap() + :with_desc("window: Move window downward"), + ["n|Wk"] = map_cu("SmartSwapUp"):with_silent():with_noremap():with_desc("window: Move window upward"), + ["n|Wl"] = map_cu("SmartSwapRight") + :with_silent() + :with_noremap() + :with_desc("window: Move window rightward"), + }, } -bind.nvim_load_mapping(plug_map) +bind.nvim_load_mapping(mappings.builtins) +bind.nvim_load_mapping(mappings.plugins) + +--- The following code enables this file to be exported --- +--- for use with gitsigns lazy-loaded keymap bindings --- -local mapping = {} +local M = {} -function mapping.gitsigns(buf) +function M.gitsigns(buf) local actions = require("gitsigns.actions") local map = { ["n|]g"] = bind.map_callback(function() @@ -138,4 +161,4 @@ function mapping.gitsigns(buf) bind.nvim_load_mapping(map) end -return mapping +return M diff --git a/lua/modules/configs/completion/mason-lspconfig.lua b/lua/modules/configs/completion/mason-lspconfig.lua index 4e8bb74d5..9e2b18803 100644 --- a/lua/modules/configs/completion/mason-lspconfig.lua +++ b/lua/modules/configs/completion/mason-lspconfig.lua @@ -52,26 +52,30 @@ please REMOVE your LSP configuration (rust_analyzer.lua) from the `servers` dire end local ok, custom_handler = pcall(require, "user.configs.lsp-servers." .. lsp_name) - local predefined_ok, predefined = pcall(require, "completion.servers." .. lsp_name) + local default_ok, default_handler = pcall(require, "completion.servers." .. lsp_name) -- Use preset if there is no user definition if not ok then - ok, custom_handler = predefined_ok, predefined - else - if type(custom_handler) == "table" and type(predefined) == "table" then - custom_handler = vim.tbl_deep_extend("force", predefined, custom_handler) - end + ok, custom_handler = default_ok, default_handler end if not ok then -- Default to use factory config for server(s) that doesn't include a spec nvim_lsp[lsp_name].setup(opts) + return elseif type(custom_handler) == "function" then --- Case where language server requires its own setup --- Make sure to call require("lspconfig")[lsp_name].setup() in the function --- See `clangd.lua` for example. custom_handler(opts) elseif type(custom_handler) == "table" then - nvim_lsp[lsp_name].setup(vim.tbl_deep_extend("force", opts, custom_handler)) + nvim_lsp[lsp_name].setup( + vim.tbl_deep_extend( + "force", + opts, + type(default_handler) == "table" and default_handler or {}, + custom_handler + ) + ) else vim.notify( string.format( diff --git a/lua/modules/utils/init.lua b/lua/modules/utils/init.lua index cedac6634..35a3d74ab 100644 --- a/lua/modules/utils/init.lua +++ b/lua/modules/utils/init.lua @@ -29,7 +29,7 @@ local M = {} ---@field crust string ---@field none "NONE" ----@type nil|table +---@type nil|palette local palette = nil -- Indicates if autocmd for refreshing the builtin palette has already been registered @@ -56,43 +56,38 @@ local function init_palette() }) end - local fallback_palette = { - rosewater = "#DC8A78", - flamingo = "#DD7878", - mauve = "#CBA6F7", - pink = "#F5C2E7", - red = "#E95678", - maroon = "#B33076", - peach = "#FF8700", - yellow = "#F7BB3B", - green = "#AFD700", - sapphire = "#36D0E0", - blue = "#61AFEF", - sky = "#04A5E5", - teal = "#B5E8E0", - lavender = "#7287FD", - - text = "#F2F2BF", - subtext1 = "#BAC2DE", - subtext0 = "#A6ADC8", - overlay2 = "#C3BAC6", - overlay1 = "#988BA2", - overlay0 = "#6E6B6B", - surface2 = "#6E6C7E", - surface1 = "#575268", - surface0 = "#302D41", - - base = "#1D1536", - mantle = "#1C1C19", - crust = "#161320", - } - if not palette then - if vim.g.colors_name == nil or (vim.g.colors_name ~= nil and not vim.g.colors_name:find("catppuccin")) then - palette = fallback_palette - else - palette = require("catppuccin.palettes").get_palette() - end + palette = (vim.g.colors_name or ""):find("catppuccin") and require("catppuccin.palettes").get_palette() + or { + rosewater = "#DC8A78", + flamingo = "#DD7878", + mauve = "#CBA6F7", + pink = "#F5C2E7", + red = "#E95678", + maroon = "#B33076", + peach = "#FF8700", + yellow = "#F7BB3B", + green = "#AFD700", + sapphire = "#36D0E0", + blue = "#61AFEF", + sky = "#04A5E5", + teal = "#B5E8E0", + lavender = "#7287FD", + + text = "#F2F2BF", + subtext1 = "#BAC2DE", + subtext0 = "#A6ADC8", + overlay2 = "#C3BAC6", + overlay1 = "#988BA2", + overlay0 = "#6E6B6B", + surface2 = "#6E6C7E", + surface1 = "#575268", + surface0 = "#302D41", + + base = "#1D1536", + mantle = "#1C1C19", + crust = "#161320", + } palette = vim.tbl_extend("force", { none = "NONE" }, palette, require("core.settings").palette_overwrite) end