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/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