Skip to content

Commit

Permalink
Register readable prefix for grouped keymap settings (ayamir#1134)
Browse files Browse the repository at this point in the history
* Use Nerd Font to replace the +prefix (It's just a demo)

* Move insert registration into bind.

* Fix unexpected shadow.

* format code.

* For tab instead of space.

* chore(ci): fix linting

* fix: works for buffer-related keymap by registering prefix immediately.

Signed-off-by: ayamir <[email protected]>

* chore(which-key): add more nerdfont for which-key prefix

* fix: works for <space> as prefix.

* refactor: update keymaps and defer register operation to shorten startup time.

* clean up.

* fixup: remove redundant code.

* perf: reduce number of register queue insertion.

Signed-off-by: ayamir <[email protected]>

* refactor: use the statical way to set group names.

* clean files.

Signed-off-by: ayamir <[email protected]>

---------

Signed-off-by: ayamir <[email protected]>
Co-authored-by: Chui <[email protected]>
Co-authored-by: CharlesChiuGit <[email protected]>
Co-authored-by: ayamir <[email protected]>
  • Loading branch information
4 people authored and husheng committed Jan 23, 2024
1 parent 94ddf03 commit 3834865
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 40 deletions.
2 changes: 1 addition & 1 deletion lua/core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ local load_core = function()

require("core.options")
require("core.mapping")
require("keymap")
require("core.event")
require("core.pack")
require("keymap")

local colorscheme = settings.colorscheme
local background = settings.background
Expand Down
33 changes: 23 additions & 10 deletions lua/keymap/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,34 @@ function mapping.lsp(buf)
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Next diagnostic"),
["n|<leader>ld"] = map_cr("Lspsaga show_line_diagnostics ++unfocus")
["n|<leader>lx"] = map_cr("Lspsaga show_line_diagnostics ++unfocus")
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Line diagnostic"),
["n|gs"] = map_callback(function()
vim.lsp.buf.signature_help()
end):with_desc("lsp: Signature help"),
["n|gr"] = map_cr("Lspsaga rename"):with_buffer(buf):with_desc("lsp: Rename in file range"),
["n|gR"] = map_cr("Lspsaga rename ++project"):with_buffer(buf):with_desc("lsp: Rename in project range"),
["n|K"] = map_cr("Lspsaga hover_doc"):with_buffer(buf):with_desc("lsp: Show doc"),
["nv|ga"] = map_cr("Lspsaga code_action"):with_buffer(buf):with_desc("lsp: Code action for cursor"),
["n|gd"] = map_cr("Glance definitions"):with_buffer(buf):with_desc("lsp: Preview definition"),
["n|gD"] = map_cr("Lspsaga goto_definition"):with_buffer(buf):with_desc("lsp: Goto definition"),
["n|gh"] = map_cr("Glance references"):with_buffer(buf):with_desc("lsp: Show reference"),
["n|<leader>ci"] = map_cr("Lspsaga incoming_calls"):with_buffer(buf):with_desc("lsp: Show incoming calls"),
["n|<leader>co"] = map_cr("Lspsaga outgoing_calls"):with_buffer(buf):with_desc("lsp: Show outgoing calls"),
["n|gr"] = map_cr("Lspsaga rename"):with_silent():with_buffer(buf):with_desc("lsp: Rename in file range"),
["n|gR"] = map_cr("Lspsaga rename ++project")
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Rename in project range"),
["n|K"] = map_cr("Lspsaga hover_doc"):with_silent():with_buffer(buf):with_desc("lsp: Show doc"),
["nv|ga"] = map_cr("Lspsaga code_action")
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Code action for cursor"),
["n|gd"] = map_cr("Glance definitions"):with_silent():with_buffer(buf):with_desc("lsp: Preview definition"),
["n|gD"] = map_cr("Lspsaga goto_definition"):with_silent():with_buffer(buf):with_desc("lsp: Goto definition"),
["n|gh"] = map_cr("Glance references"):with_silent():with_buffer(buf):with_desc("lsp: Show reference"),
["n|gci"] = map_cr("Lspsaga incoming_calls")
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Show incoming calls"),
["n|gco"] = map_cr("Lspsaga outgoing_calls")
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Show outgoing calls"),
}
bind.nvim_load_mapping(map)

Expand Down
6 changes: 3 additions & 3 deletions lua/keymap/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ local plug_map = {
:with_desc("edit: Toggle comment for block with selection"),

-- Plugin: diffview
["n|<leader>D"] = map_cr("DiffviewOpen"):with_silent():with_noremap():with_desc("git: Show diff"),
["n|<leader><leader>D"] = map_cr("DiffviewClose"):with_silent():with_noremap():with_desc("git: Close diff"),
["n|<leader>gd"] = map_cr("DiffviewOpen"):with_silent():with_noremap():with_desc("git: Show diff"),
["n|<leader>gD"] = map_cr("DiffviewClose"):with_silent():with_noremap():with_desc("git: Close diff"),

-- Plugin: vim-easy-align
["nx|gea"] = map_cr("EasyAlign"):with_desc("edit: Align with delimiter"),
Expand All @@ -68,7 +68,7 @@ local plug_map = {
["nv|<leader>j"] = map_cmd("<Cmd>HopLineMW<CR>"):with_noremap():with_desc("jump: Goto line"),
["nv|<leader>k"] = map_cmd("<Cmd>HopLineMW<CR>"):with_noremap():with_desc("jump: Goto line"),
["nv|<leader>c"] = map_cmd("<Cmd>HopChar1MW<CR>"):with_noremap():with_desc("jump: Goto one char"),
["nv|<leader>cc"] = map_cmd("<Cmd>HopChar2MW<CR>"):with_noremap():with_desc("jump: Goto two chars"),
["nv|<leader>C"] = map_cmd("<Cmd>HopChar2MW<CR>"):with_noremap():with_desc("jump: Goto two chars"),

-- Plugin: treehopper
["o|m"] = map_cu("lua require('tsht').nodes()"):with_silent():with_desc("jump: Operate across syntax tree"),
Expand Down
16 changes: 8 additions & 8 deletions lua/keymap/tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local plug_map = {
-- 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|<leader>G"] = map_cu("Git"):with_noremap():with_silent():with_desc("git: Open git-fugitive"),
["n|<leader>gG"] = map_cu("Git"):with_noremap():with_silent():with_desc("git: Open git-fugitive"),

-- Plugin: nvim-tree
["n|<C-n>"] = map_cr("NvimTreeToggle"):with_noremap():with_silent():with_desc("filetree: Toggle"),
Expand Down Expand Up @@ -59,7 +59,7 @@ local plug_map = {
:with_silent()
:with_desc("terminal: Toggle float"),
["t|<A-d>"] = map_cmd("<Cmd>ToggleTerm<CR>"):with_noremap():with_silent():with_desc("terminal: Toggle float"),
["n|<leader>g"] = map_callback(function()
["n|<leader>gg"] = map_callback(function()
_toggle_lazygit()
end)
:with_noremap()
Expand All @@ -68,23 +68,23 @@ local plug_map = {

-- Plugin: trouble
["n|gt"] = map_cr("TroubleToggle"):with_noremap():with_silent():with_desc("lsp: Toggle trouble list"),
["n|<leader>tr"] = map_cr("TroubleToggle lsp_references")
["n|<leader>ll"] = map_cr("TroubleToggle lsp_references")
:with_noremap()
:with_silent()
:with_desc("lsp: Show lsp references"),
["n|<leader>td"] = map_cr("TroubleToggle document_diagnostics")
["n|<leader>ld"] = map_cr("TroubleToggle document_diagnostics")
:with_noremap()
:with_silent()
:with_desc("lsp: Show document diagnostics"),
["n|<leader>tw"] = map_cr("TroubleToggle workspace_diagnostics")
["n|<leader>lw"] = map_cr("TroubleToggle workspace_diagnostics")
:with_noremap()
:with_silent()
:with_desc("lsp: Show workspace diagnostics"),
["n|<leader>tq"] = map_cr("TroubleToggle quickfix")
["n|<leader>lq"] = map_cr("TroubleToggle quickfix")
:with_noremap()
:with_silent()
:with_desc("lsp: Show quickfix list"),
["n|<leader>tl"] = map_cr("TroubleToggle loclist"):with_noremap():with_silent():with_desc("lsp: Show loclist"),
["n|<leader>lL"] = map_cr("TroubleToggle loclist"):with_noremap():with_silent():with_desc("lsp: Show loclist"),

-- Plugin: telescope
["n|<C-p>"] = map_callback(function()
Expand Down Expand Up @@ -123,7 +123,7 @@ local plug_map = {
:with_noremap()
:with_silent()
:with_desc("ui: Change colorscheme for current session"),
["n|<leader>fn"] = map_cu(":enew"):with_noremap():with_silent():with_desc("buffer: New"),
["n|<leader>bn"] = map_cu(":enew"):with_noremap():with_silent():with_desc("buffer: New"),
["n|<leader>fg"] = map_cu("Telescope git_files")
:with_noremap()
:with_silent()
Expand Down
16 changes: 8 additions & 8 deletions lua/keymap/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,42 +54,42 @@ function mapping.gitsigns(buf)
:with_buffer(buf)
:with_expr()
:with_desc("git: Goto prev hunk"),
["n|<leader>hs"] = bind.map_callback(function()
["n|<leader>gs"] = bind.map_callback(function()
actions.stage_hunk()
end)
:with_buffer(buf)
:with_desc("git: Stage hunk"),
["v|<leader>hs"] = bind.map_callback(function()
["v|<leader>gs"] = bind.map_callback(function()
actions.stage_hunk({ vim.fn.line("."), vim.fn.line("v") })
end)
:with_buffer(buf)
:with_desc("git: Stage hunk"),
["n|<leader>hu"] = bind.map_callback(function()
["n|<leader>gu"] = bind.map_callback(function()
actions.undo_stage_hunk()
end)
:with_buffer(buf)
:with_desc("git: Undo stage hunk"),
["n|<leader>hr"] = bind.map_callback(function()
["n|<leader>gr"] = bind.map_callback(function()
actions.reset_hunk()
end)
:with_buffer(buf)
:with_desc("git: Reset hunk"),
["v|<leader>hr"] = bind.map_callback(function()
["v|<leader>gr"] = bind.map_callback(function()
actions.reset_hunk({ vim.fn.line("."), vim.fn.line("v") })
end)
:with_buffer(buf)
:with_desc("git: Reset hunk"),
["n|<leader>hR"] = bind.map_callback(function()
["n|<leader>gR"] = bind.map_callback(function()
actions.reset_buffer()
end)
:with_buffer(buf)
:with_desc("git: Reset buffer"),
["n|<leader>hp"] = bind.map_callback(function()
["n|<leader>gp"] = bind.map_callback(function()
actions.preview_hunk()
end)
:with_buffer(buf)
:with_desc("git: Preview hunk"),
["n|<leader>hb"] = bind.map_callback(function()
["n|<leader>gb"] = bind.map_callback(function()
actions.blame_line({ full = true })
end)
:with_buffer(buf)
Expand Down
33 changes: 32 additions & 1 deletion lua/modules/configs/tool/which-key.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,39 @@ return function()
local icons = {
ui = require("modules.utils.icons").get("ui"),
misc = require("modules.utils.icons").get("misc"),
git = require("modules.utils.icons").get("git", true),
cmp = require("modules.utils.icons").get("cmp", true),
}

require("which-key").register({
["<leader>"] = {
b = {
name = icons.ui.Buffer .. " Buffer",
},
d = {
name = icons.ui.Bug .. " Debug",
},
f = {
name = icons.ui.Telescope .. " Fuzzy Find",
},
g = {
name = icons.git.Git .. "Git",
},
l = {
name = icons.misc.LspAvailable .. " Lsp",
},
n = {
name = icons.ui.FolderOpen .. " Nvim Tree",
},
p = {
name = icons.ui.Package .. " Package",
},
s = {
name = icons.cmp.tmux .. "Session",
},
},
})

require("modules.utils").load_plugin("which-key", {
plugins = {
presets = {
Expand All @@ -20,7 +51,7 @@ return function()
icons = {
breadcrumb = icons.ui.Separator,
separator = icons.misc.Vbar,
group = icons.misc.Add,
group = "",
},

window = {
Expand Down
8 changes: 0 additions & 8 deletions lua/modules/configs/ui/alpha.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,6 @@ return function()
require("telescope.builtin").find_files()
end,
}),
button("space f n", " File new", leader, nil, {
noremap = true,
silent = true,
nowait = true,
callback = function()
vim.api.nvim_command("enew")
end,
}),
button("space f w", " Word find", leader, nil, {
noremap = true,
silent = true,
Expand Down
4 changes: 3 additions & 1 deletion lua/modules/utils/icons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,18 @@ local data = {
BigCircle = "",
BigUnfilledCircle = "",
BookMark = "󰃃",
Buffer = "󰓩",
Bug = "",
Calendar = "",
Character = "",
Check = "󰄳",
ChevronRight = "",
Circle = "",
Close = "󰅖",
Close_alt = "",
CloudDownload = "",
Comment = "󰅺",
CodeAction = "󰌵",
Comment = "󰅺",
Dashboard = "",
Emoji = "󰱫",
EmptyFolder = "",
Expand Down

0 comments on commit 3834865

Please sign in to comment.