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 mappings = { builtins = { -- Builtins: Buffer ["n|bn"] = map_cu("enew"):with_noremap():with_silent():with_desc("buffer: New"), -- 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"), -- 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"), -- 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"), }, } 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 M = {} function M.gitsigns(bufnr) local gitsigns = require("gitsigns") local map = { ["n|]g"] = map_callback(function() if vim.wo.diff then return "]g" end vim.schedule(function() gitsigns.nav_hunk("next") end) return "" end) :with_buffer(bufnr) :with_noremap() :with_expr() :with_desc("git: Goto next hunk"), ["n|[g"] = map_callback(function() if vim.wo.diff then return "[g" end vim.schedule(function() gitsigns.nav_hunk("prev") end) return "" end) :with_buffer(bufnr) :with_noremap() :with_expr() :with_desc("git: Goto prev hunk"), ["n|gs"] = map_callback(function() gitsigns.stage_hunk() end) :with_buffer(bufnr) :with_noremap() :with_desc("git: Toggle staging/unstaging of hunk"), ["v|gs"] = map_callback(function() gitsigns.stage_hunk({ vim.fn.line("."), vim.fn.line("v") }) end) :with_buffer(bufnr) :with_noremap() :with_desc("git: Toggle staging/unstaging of selected hunk"), ["n|gr"] = map_callback(function() gitsigns.reset_hunk() end) :with_buffer(bufnr) :with_noremap() :with_desc("git: Reset hunk"), ["v|gr"] = map_callback(function() gitsigns.reset_hunk({ vim.fn.line("."), vim.fn.line("v") }) end) :with_buffer(bufnr) :with_noremap() :with_desc("git: Reset hunk"), ["n|gR"] = map_callback(function() gitsigns.reset_buffer() end) :with_buffer(bufnr) :with_noremap() :with_desc("git: Reset buffer"), ["n|gp"] = map_callback(function() gitsigns.preview_hunk() end) :with_buffer(bufnr) :with_noremap() :with_desc("git: Preview hunk"), ["n|gb"] = map_callback(function() gitsigns.blame_line({ full = true }) end) :with_buffer(bufnr) :with_noremap() :with_desc("git: Blame line"), -- Text objects ["ox|ih"] = map_callback(function() gitsigns.select_hunk() end) :with_buffer(bufnr) :with_noremap(), } bind.nvim_load_mapping(map) end return M