-- ┌─────────────────┐ -- │ Custom mappings │ -- └─────────────────┘ -- -- This file contains definitions of custom general and Leader mappings. -- General mappings =========================================================== -- Use this section to add custom general mappings. See `:h vim.keymap.set()`. -- An example helper to create a Normal mode mapping local nmap = function(lhs, rhs, desc) -- See `:h vim.keymap.set()` vim.keymap.set('n', lhs, rhs, { desc = desc }) end -- stylua: ignore start -- The next part (until `-- stylua: ignore end`) is aligned manually for easier -- reading. Consider preserving this or remove `-- stylua` lines to autoformat. -- Leader mappings ============================================================ -- Neovim has the concept of a Leader key (see `:h `). It is a configurable -- key that is primarily used for "workflow" mappings (opposed to text editing). -- Like "open file explorer", "create scratch buffer", "pick from buffers". -- -- In 'plugin/10_options.lua' is set to , i.e. press -- whenever there is a suggestion to press . -- -- Create a global table with information about Leader groups in certain modes. -- This is used to provide 'mini.clue' with extra clues. -- Add an entry if you create a new group. _G.Config.leader_group_clues = { { mode = 'n', keys = 'b', desc = '+Buffer' }, { mode = 'n', keys = 'e', desc = '+Explore/Edit' }, { mode = 'n', keys = 'f', desc = '+Pick' }, { mode = 'n', keys = 'g', desc = '+Git' }, { mode = 'n', keys = 'l', desc = '+Language' }, { mode = 'n', keys = 'm', desc = '+Map' }, { mode = 'n', keys = 'o', desc = '+Other' }, { mode = 'n', keys = 's', desc = '+Session' }, { mode = 'x', keys = 'g', desc = '+Git' }, { mode = 'x', keys = 'z', desc = '+Notes' }, } -- Helpers for a more concise `` mappings. -- Most of the mappings use `...` string as a right hand side (RHS) in -- an attempt to be more concise yet descriptive. See `:h `. -- This approach also doesn't require the underlying commands/functions to exist -- during mapping creation: a "lazy loading" approach to improve startup time. local nmap_leader = function(suffix, rhs, desc) vim.keymap.set('n', '' .. suffix, rhs, { desc = desc }) end local xmap_leader = function(suffix, rhs, desc) vim.keymap.set('x', '' .. suffix, rhs, { desc = desc }) end local vmap_leader = function(suffix, rhs, desc) vim.keymap.set('v', '' .. suffix, rhs, { desc = desc }) end -- b is for 'Buffer'. Common usage: -- - `bs` - create scratch (temporary) buffer -- - `ba` - navigate to the alternative buffer -- - `bw` - wipeout (fully delete) current buffer local new_scratch_buffer = function() vim.api.nvim_win_set_buf(0, vim.api.nvim_create_buf(true, true)) end nmap_leader('ba', 'b#', 'Alternate') nmap_leader('bk', 'lua MiniBufremove.delete()', 'Kill') nmap_leader('bK', 'lua MiniBufremove.delete(0, true)', 'KIIIILLL!') nmap_leader('bs', new_scratch_buffer, 'Scratch') nmap_leader('bw', 'write', 'Write') -- e is for 'Explore' and 'Edit'. Common usage: -- - `ed` - open explorer at current working directory -- - `ef` - open directory of current file (needs to be present on disk) -- - `ei` - edit 'init.lua' -- - All mappings that use `edit_plugin_file` - edit 'plugin/' config files local edit_plugin_file = function(filename) return string.format('edit %s/plugin/%s', vim.fn.stdpath('config'), filename) end local explore_at_file = 'lua MiniFiles.open(vim.api.nvim_buf_get_name(0))' local explore_quickfix = function() for _, win_id in ipairs(vim.api.nvim_tabpage_list_wins(0)) do if vim.fn.getwininfo(win_id)[1].quickfix == 1 then return vim.cmd('cclose') end end vim.cmd('copen') end nmap_leader('ed', 'lua MiniFiles.open()', 'Directory') nmap_leader('ef', explore_at_file, 'File directory') nmap_leader('ei', 'edit $MYVIMRC', 'init.lua') nmap_leader('ek', edit_plugin_file('20_keymaps.lua'), 'Keymaps config') nmap_leader('em', edit_plugin_file('30_mini.lua'), 'MINI config') nmap_leader('en', 'lua MiniNotify.show_history()', 'Notifications') nmap_leader('eo', edit_plugin_file('10_options.lua'), 'Options config') nmap_leader('ep', edit_plugin_file('40_plugins.lua'), 'Plugins config') nmap_leader('eq', explore_quickfix, 'Quickfix') -- f is for 'Fuzzy Find'. Common usage: -- - `ff` - find files; for best performance requires `ripgrep` -- - `fg` - find inside files; requires `ripgrep` -- - `fh` - find help tag -- - `fr` - resume latest picker -- - `fv` - all visited paths; requires 'mini.visits' -- -- All these use 'mini.pick'. See `:h MiniPick-overview` for an overview. local pick_workspace_symbols_live = 'Pick lsp scope="workspace_symbol_live"' nmap_leader('f/', 'Pick history scope="/"', '"/" history') nmap_leader('f:', 'Pick history scope=":"', '":" history') nmap_leader('', 'Pick buffers', 'Buffers') nmap_leader('w', 'w!', 'Write buffer') nmap_leader('fd', 'Pick diagnostic scope="all"', 'Diagnostic workspace') nmap_leader('fD', 'Pick diagnostic scope="current"', 'Diagnostic buffer') nmap_leader('ff', 'Pick files', 'Files') nmap_leader('fg', 'Pick grep_live', 'Grep live') nmap_leader('fG', 'Pick grep pattern=""', 'Grep current word') nmap_leader('fh', 'Pick help', 'Help tags') nmap_leader('fH', 'Pick hl_groups', 'Highlight groups') nmap_leader('fl', 'Pick buf_lines scope="all"', 'Lines (all)') nmap_leader('fL', 'Pick buf_lines scope="current"', 'Lines (buf)') nmap_leader('fr', 'Pick resume', 'Resume') nmap_leader('fR', 'Pick lsp scope="references"', 'References (LSP)') nmap_leader('fs', pick_workspace_symbols_live, 'Symbols workspace (live)') nmap_leader('fS', 'Pick lsp scope="document_symbol"', 'Symbols document') -- g is for Git nmap_leader('gg', 'Neogit', 'Open neogit') nmap_leader('gb', 'Gitsigns toggle_current_line_blame', 'Git blame') -- l is for 'Language'. Common usage: -- - `ld` - show more diagnostic details in a floating window -- - `lr` - perform rename via LSP -- - `ls` - navigate to source definition of symbol under cursor nmap_leader('la', 'lua vim.lsp.buf.code_action()', 'Actions') nmap_leader('ld', 'lua vim.diagnostic.open_float()', 'Diagnostic popup') nmap_leader('lf', 'lua vim.lsp.buf.format()', 'Format') nmap_leader('li', 'lua vim.lsp.buf.implementation()', 'Implementation') nmap_leader('lh', 'lua vim.lsp.buf.hover()', 'Hover') nmap_leader('lr', 'lua vim.lsp.buf.rename()', 'Rename') nmap_leader('lR', 'lua vim.lsp.buf.references()', 'References') nmap_leader('ls', 'lua vim.lsp.buf.definition()', 'Source definition') nmap_leader('lt', 'lua vim.lsp.buf.type_definition()', 'Type definition') -- d is for DAP Debugging nmap_leader('dd', 'DapViewToggle', 'Open DAP') nmap_leader('ds', 'DapContinue', 'Start or Continue') nmap_leader('db', 'DapToggleBreakpoint', 'Toggle Breakpoint') nmap_leader('di', 'DapStepInto', 'Toggle Breakpoint') nmap_leader('db', 'DapToggleBreakpoint', 'Toggle Breakpoint') -- o is for 'Other'. Common usage: -- - `oz` - toggle between "zoomed" and regular view of current buffer nmap_leader('ot', 'lua MiniTrailspace.trim()', 'Trim trailspace') nmap_leader('oz', 'lua MiniMisc.zoom()', 'Zoom toggle') nmap_leader('om', 'Mason', 'Open Mason') nmap_leader('ou', 'DepsUpdate', 'Update plugins') nmap_leader('or', 'Pick registers', 'Yank from register') -- stylua: ignore end