From 5b883ca903ad2ecd5815bb86cf78ac949c6a3664 Mon Sep 17 00:00:00 2001 From: AngelontheRoad Date: Mon, 4 Nov 2024 18:41:30 +0800 Subject: [PATCH] chores: rearrange wm & editor keymaps and corresponding plugin --- lua/core/init.lua | 1 - lua/core/mapping.lua | 65 ----------------- lua/keymap/editor.lua | 69 ++++++++++++++----- lua/keymap/ui.lua | 40 ++++++++++- lua/modules/configs/{editor => ui}/splits.lua | 0 lua/modules/plugins/editor.lua | 5 -- lua/modules/plugins/ui.lua | 5 ++ 7 files changed, 93 insertions(+), 92 deletions(-) delete mode 100644 lua/core/mapping.lua rename lua/modules/configs/{editor => ui}/splits.lua (100%) diff --git a/lua/core/init.lua b/lua/core/init.lua index 85ba8bff3..f579ef004 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -104,7 +104,6 @@ local load_core = function() shell_config() require("core.options") - require("core.mapping") require("core.event") require("core.pack") require("keymap") diff --git a/lua/core/mapping.lua b/lua/core/mapping.lua deleted file mode 100644 index 351216925..000000000 --- a/lua/core/mapping.lua +++ /dev/null @@ -1,65 +0,0 @@ -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 core_map = { - -- Suckless - ["n|"] = map_cr("normal za"):with_noremap():with_silent():with_desc("edit: Toggle code fold"), - ["n|"] = map_cu("write"):with_noremap():with_silent():with_desc("edit: Save file"), - ["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_callback(function() - _flash_esc_or_noh() - end) - :with_noremap() - :with_silent() - :with_desc("edit: Clear search highlight"), - ["n|"] = map_cmd("h"):with_noremap():with_desc("window: Focus left"), - ["n|"] = map_cmd("l"):with_noremap():with_desc("window: Focus right"), - ["n|"] = map_cmd("j"):with_noremap():with_desc("window: Focus down"), - ["n|"] = map_cmd("k"):with_noremap():with_desc("window: Focus up"), - ["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"), - ["n|"] = map_cr("vertical resize -3"):with_silent():with_desc("window: Resize -3 vertically"), - ["n|"] = map_cr("vertical resize +3"):with_silent():with_desc("window: Resize +3 vertically"), - ["n|"] = map_cr("resize -3"):with_silent():with_desc("window: Resize -3 horizontally"), - ["n|"] = map_cr("resize +3"):with_silent():with_desc("window: Resize +3 horizontally"), - ["n|"] = map_cr("wq"):with_desc("edit: Save file and quit"), - ["n|"] = map_cr("q!"):with_desc("edit: Force quit"), - ["n|o"] = map_cr("setlocal spell! spelllang=en_us"):with_desc("edit: Toggle spell check"), - ["n|bn"] = map_cu("enew"):with_noremap():with_silent():with_desc("buffer: New"), - ["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"), - -- 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"), - -- 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"), - -- 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"), -} - -bind.nvim_load_mapping(core_map) diff --git a/lua/keymap/editor.lua b/lua/keymap/editor.lua index 9b0271cee..e14f4c4a6 100644 --- a/lua/keymap/editor.lua +++ b/lua/keymap/editor.lua @@ -5,15 +5,60 @@ 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"), + + -- 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"), + + -- 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"), + + -- 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"), + + -- 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 + -- 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: nvim-bufdel - ["n|"] = map_cr("BufDel"):with_noremap():with_silent():with_desc("buffer: Close current"), - -- Plugin: comment.nvim ["n|gcc"] = map_callback(function() return vim.v.count == 0 and et("(comment_toggle_linewise_current)") @@ -59,20 +104,6 @@ local plug_map = { ["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: 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: nvim-spectre ["n|Ss"] = map_callback(function() require("spectre").toggle() @@ -102,7 +133,7 @@ local plug_map = { -- Plugin: nvim-treehopper ["o|m"] = map_cu("lua require('tsht').nodes()"):with_silent():with_desc("jump: Operate across syntax tree"), - -- Plugin suda.vim + -- Plugin: suda.vim ["n|"] = map_cu("SudaWrite"):with_silent():with_noremap():with_desc("editn: Save file using sudo"), } diff --git a/lua/keymap/ui.lua b/lua/keymap/ui.lua index 77df22d2a..545ddc567 100644 --- a/lua/keymap/ui.lua +++ b/lua/keymap/ui.lua @@ -1,10 +1,32 @@ 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_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"), + + -- 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"), + + -- 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) + 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"), @@ -21,6 +43,20 @@ local plug_map = { ["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"), } bind.nvim_load_mapping(plug_map) diff --git a/lua/modules/configs/editor/splits.lua b/lua/modules/configs/ui/splits.lua similarity index 100% rename from lua/modules/configs/editor/splits.lua rename to lua/modules/configs/ui/splits.lua diff --git a/lua/modules/plugins/editor.lua b/lua/modules/plugins/editor.lua index ce5767d65..204ff047d 100644 --- a/lua/modules/plugins/editor.lua +++ b/lua/modules/plugins/editor.lua @@ -88,11 +88,6 @@ editor["nvim-pack/nvim-spectre"] = { lazy = true, cmd = "Spectre", } -editor["mrjones2014/smart-splits.nvim"] = { - lazy = true, - event = { "CursorHoldI", "CursorHold" }, - config = require("editor.splits"), -} ---------------------------------------------------------------------- --  :treesitter related plugins -- diff --git a/lua/modules/plugins/ui.lua b/lua/modules/plugins/ui.lua index 1f567b7a9..6877d3cae 100644 --- a/lua/modules/plugins/ui.lua +++ b/lua/modules/plugins/ui.lua @@ -51,6 +51,11 @@ ui["folke/paint.nvim"] = { event = { "CursorHold", "CursorHoldI" }, config = require("ui.paint"), } +ui["mrjones2014/smart-splits.nvim"] = { + lazy = true, + event = { "CursorHoldI", "CursorHold" }, + config = require("ui.splits"), +} ui["folke/todo-comments.nvim"] = { lazy = true, event = { "CursorHold", "CursorHoldI" },