-- ┌─────────────────┐ -- │ 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 -- Paste linewise before/after current line -- Usage: `yiw` to yank a word and `]p` to put it on the next line. nmap('[p', 'exe "put! " . v:register', 'Paste Above') nmap(']p', 'exe "put " . v:register', 'Paste Below') -- Many general mappings are created by 'mini.basics'. See 'plugin/30_mini.lua' -- 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 = '+Find' }, { 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 = 'n', keys = 't', desc = '+Terminal' }, { mode = 'x', keys = 'g', desc = '+Git' }, { mode = 'x', keys = 'l', desc = '+Language' }, } -- Window menu -- See: https://github.com/nvim-mini/mini.nvim/discussions/2028#discussioncomment-14593098 vim.keymap.set('n', 'w', function() vim.api.nvim_input '' end, { desc = '+Window' }) -- 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 -- 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('bd', 'lua MiniBufremove.delete()', 'Delete') nmap_leader('bD', 'lua MiniBufremove.delete(0, true)', 'Delete!') 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('fb', 'Pick buffers', 'Buffers') 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') nmap_leader('fv', 'Pick visit_paths cwd=""', 'Visit paths (all)') nmap_leader('fV', 'Pick visit_paths', 'Visit paths (cwd)') -- 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 -- -- NOTE: most LSP mappings represent a more structured way of replacing built-in -- LSP mappings (like `:h gra` and others). This is needed because `gr` is mapped -- by an "replace" operator in 'mini.operators' (which is more commonly used). local formatting_cmd = 'lua require("conform").format({lsp_fallback=true})' nmap_leader('la', 'lua vim.lsp.buf.code_action()', 'Actions') nmap_leader('ld', 'lua vim.diagnostic.open_float()', 'Diagnostic popup') nmap_leader('lf', formatting_cmd, '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') xmap_leader('lf', formatting_cmd, 'Format selection') -- o is for 'Other'. Common usage: -- - `oz` - toggle between "zoomed" and regular view of current buffer nmap_leader('or', 'lua MiniMisc.resize_window()', 'Resize to default width') nmap_leader('ot', 'lua MiniTrailspace.trim()', 'Trim trailspace') nmap_leader('oz', 'lua MiniMisc.zoom()', 'Zoom toggle') -- s is for 'Session'. Common usage: -- - `sn` - start new session -- - `sr` - read previously started session -- - `sd` - delete previously started session local session_new = 'MiniSessions.write(vim.fn.input("Session name: "))' nmap_leader('sd', 'lua MiniSessions.select("delete")', 'Delete') nmap_leader('sn', 'lua ' .. session_new .. '', 'New') nmap_leader('sr', 'lua MiniSessions.select("read")', 'Read') nmap_leader('sw', 'lua MiniSessions.write()', 'Write current') -- t is for 'Terminal' nmap_leader('tT', 'horizontal term', 'Terminal (horizontal)') nmap_leader('tt', 'vertical term', 'Terminal (vertical)') -- stylua: ignore end