Skip to content

Commit

Permalink
fix(keymap): apply follow-up changes to related files (#1396)
Browse files Browse the repository at this point in the history
Follow-up for #1395 to apply the same structure & comment tweaks to other defs
too

Signed-off-by: Jint-lzxy <[email protected]>
  • Loading branch information
Jint-lzxy authored Jan 19, 2025
1 parent 5b785f7 commit 8cb3f92
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 226 deletions.
20 changes: 13 additions & 7 deletions lua/keymap/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ local map_cr = bind.map_cr
local map_cmd = bind.map_cmd
local map_callback = bind.map_callback

local plug_map = {
["n|<A-f>"] = map_cmd("<Cmd>FormatToggle<CR>"):with_noremap():with_desc("formatter: Toggle format on save"),
["n|<A-S-f>"] = map_cmd("<Cmd>Format<CR>"):with_noremap():with_desc("formatter: Format buffer manually"),
local mappings = {
fmt = {
["n|<A-f>"] = map_cmd("<Cmd>FormatToggle<CR>"):with_noremap():with_desc("formatter: Toggle format on save"),
["n|<A-S-f>"] = map_cmd("<Cmd>Format<CR>"):with_noremap():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|<leader>li"] = map_cr("LspInfo"):with_silent():with_buffer(buf):with_desc("lsp: Info"),
Expand Down Expand Up @@ -83,4 +89,4 @@ function mapping.lsp(buf)
end
end

return mapping
return M
53 changes: 34 additions & 19 deletions lua/keymap/init.lua
Original file line number Diff line number Diff line change
@@ -1,35 +1,50 @@
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|<leader>ph"] = map_cr("Lazy"):with_silent():with_noremap():with_nowait():with_desc("package: Show"),
["n|<leader>ps"] = map_cr("Lazy sync"):with_silent():with_noremap():with_nowait():with_desc("package: Sync"),
["n|<leader>pu"] = map_cr("Lazy update"):with_silent():with_noremap():with_nowait():with_desc("package: Update"),
["n|<leader>pi"] = map_cr("Lazy install"):with_silent():with_noremap():with_nowait():with_desc("package: Install"),
["n|<leader>pl"] = map_cr("Lazy log"):with_silent():with_noremap():with_nowait():with_desc("package: Log"),
["n|<leader>pc"] = map_cr("Lazy check"):with_silent():with_noremap():with_nowait():with_desc("package: Check"),
["n|<leader>pd"] = map_cr("Lazy debug"):with_silent():with_noremap():with_nowait():with_desc("package: Debug"),
["n|<leader>pp"] = map_cr("Lazy profile"):with_silent():with_noremap():with_nowait():with_desc("package: Profile"),
["n|<leader>pr"] = map_cr("Lazy restore"):with_silent():with_noremap():with_nowait():with_desc("package: Restore"),
["n|<leader>px"] = map_cr("Lazy clean"):with_silent():with_noremap():with_nowait():with_desc("package: Clean"),
local mappings = {
core = {
-- Package manager: lazy.nvim
["n|<leader>ph"] = map_cr("Lazy"):with_silent():with_noremap():with_nowait():with_desc("package: Show"),
["n|<leader>ps"] = map_cr("Lazy sync"):with_silent():with_noremap():with_nowait():with_desc("package: Sync"),
["n|<leader>pu"] = map_cr("Lazy update")
:with_silent()
:with_noremap()
:with_nowait()
:with_desc("package: Update"),
["n|<leader>pi"] = map_cr("Lazy install")
:with_silent()
:with_noremap()
:with_nowait()
:with_desc("package: Install"),
["n|<leader>pl"] = map_cr("Lazy log"):with_silent():with_noremap():with_nowait():with_desc("package: Log"),
["n|<leader>pc"] = map_cr("Lazy check"):with_silent():with_noremap():with_nowait():with_desc("package: Check"),
["n|<leader>pd"] = map_cr("Lazy debug"):with_silent():with_noremap():with_nowait():with_desc("package: Debug"),
["n|<leader>pp"] = map_cr("Lazy profile")
:with_silent()
:with_noremap()
:with_nowait()
:with_desc("package: Profile"),
["n|<leader>pr"] = map_cr("Lazy restore")
:with_silent()
:with_noremap()
:with_nowait()
:with_desc("package: Restore"),
["n|<leader>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")
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
23 changes: 11 additions & 12 deletions lua/keymap/lang.lua
Original file line number Diff line number Diff line change
@@ -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|<F1>"] = map_cr("RenderMarkdown toggle")
:with_noremap()
:with_silent()
:with_desc("tool: toggle markdown preview within nvim"),
-- Plugin MarkdownPreview
["n|<F12>"] = map_cr("MarkdownPreviewToggle"):with_noremap():with_silent():with_desc("tool: Preview markdown"),
local mappings = {
plugins = {
-- Plugins: render-markdown.nvim
["n|<F1>"] = map_cr("RenderMarkdown toggle")
:with_noremap()
:with_silent()
:with_desc("tool: toggle markdown preview within nvim"),
-- Plugins: MarkdownPreview
["n|<F12>"] = map_cr("MarkdownPreviewToggle"):with_noremap():with_silent():with_desc("tool: Preview markdown"),
},
}

bind.nvim_load_mapping(plug_map)
bind.nvim_load_mapping(mappings.plugins)
Loading

0 comments on commit 8cb3f92

Please sign in to comment.