--- Defaults to `{'n'}` --- @alias Mode 'n'|'v'|'Q'|'t'|'i'|'c' --- @alias Mapping string|fun(): nil --- @type table local keymap = { move_lines = { [''] = ':move-2i', [''] = ':move+i', modes = { 'i' }, }, half_screen_scroll = { [''] = 'zz', [''] = 'zz', }, clipboard_yank = { ['y'] = '"+y', modes = { 'n', 'v' }, }, terminal_escape = { [''] = '', modes = { 't' }, }, terminal = { ['t'] = function() OpenTerminal = OpenTerminal or nil local open_buf = vim.api.nvim_get_current_buf() if PreviousBuffer and open_buf == OpenTerminal then vim.api.nvim_set_current_buf(PreviousBuffer) PreviousBuffer = nil return end PreviousBuffer = open_buf if OpenTerminal then vim.api.nvim_set_current_buf(OpenTerminal) return end vim.cmd.term() OpenTerminal = vim.api.nvim_get_current_buf() vim.api.nvim_create_autocmd({ 'BufDelete' }, { callback = function() OpenTerminal = nil end, buffer = OpenTerminal, }) end, }, goto_last_buffer = { ['l'] = ':e#', }, goto_definition = { ['gd'] = vim.lsp.buf.declaration }, scratch_pad = { ['s'] = table.concat({ ':bo vs', ':enew', ':setlocal noswapfile', ':setlocal bufhidden=hide', ':set filetype=markdown', ':set syntax=markdown', '', }, ''), }, window_navigation = { [''] = 'q', [''] = '', [''] = '', [''] = '', [''] = '', }, } for _, tbl in pairs(keymap) do for key, value in pairs(tbl) do if key ~= 'modes' then local modes = tbl.modes --[[ @as Mode[] ]] or { 'n' } for _, mode in ipairs(modes) do --- @cast value Mapping vim.keymap.set(mode, key, value) end end end end