-- stylua: ignore start -- Create global tables with information about clue groups in certain modes -- Structure of tables is taken to be compatible with 'mini.clue'. _G.Config.leader_group_clues = { { mode = 'n', keys = 'b', desc = '+Buffer' }, { mode = 'n', keys = 'e', desc = '+Explore' }, { mode = 'n', keys = 'f', desc = '+Find' }, { mode = 'n', keys = 'g', desc = '+Git' }, { mode = 'n', keys = 'l', desc = '+LSP' }, { mode = 'n', keys = 'L', desc = '+Lua' }, { mode = 'n', keys = 'm', desc = '+Map' }, { mode = 'n', keys = 'o', desc = '+Other' }, { mode = 'n', keys = 'r', desc = '+R' }, { mode = 'n', keys = 't', desc = '+Terminal/Minitest' }, { mode = 'n', keys = 'T', desc = '+Test' }, { mode = 'n', keys = 'v', desc = '+Visits' }, { mode = 'x', keys = 'l', desc = '+LSP' }, { mode = 'x', keys = 'r', desc = '+R' }, } -- Create `` mappings local nmap_leader = function(suffix, rhs, desc, opts) opts = opts or {} opts.desc = desc vim.keymap.set('n', '' .. suffix, rhs, opts) end local xmap_leader = function(suffix, rhs, desc, opts) opts = opts or {} opts.desc = desc vim.keymap.set('x', '' .. suffix, rhs, opts) end -- b is for 'buffer' nmap_leader('ba', 'b#', 'Alternate') nmap_leader('bd', 'lua MiniBufremove.delete()', 'Delete') nmap_leader('bD', 'lua MiniBufremove.delete(0, true)', 'Delete!') nmap_leader('bs', 'lua Config.new_scratch_buffer()', 'Scratch') nmap_leader('bw', 'lua MiniBufremove.wipeout()', 'Wipeout') nmap_leader('bW', 'lua MiniBufremove.wipeout(0, true)', 'Wipeout!') -- e is for 'explore' and 'edit' nmap_leader('ec', 'lua MiniFiles.open(vim.fn.stdpath("config"))', 'Config') nmap_leader('ed', 'lua MiniFiles.open()', 'Directory') nmap_leader('ef', 'lua MiniFiles.open(vim.api.nvim_buf_get_name(0))', 'File directory') nmap_leader('ei', 'edit $MYVIMRC', 'File directory') nmap_leader('em', 'lua MiniFiles.open(vim.fn.stdpath("data").."/site/pack/deps/start/mini.nvim")', 'Mini.nvim directory') nmap_leader('ep', 'lua MiniFiles.open(vim.fn.stdpath("data").."/site/pack/deps/opt")', 'Plugins directory') nmap_leader('eq', 'lua Config.toggle_quickfix()', 'Quickfix') -- f is for 'fuzzy find' nmap_leader('f/', 'Pick history scope="/"', '"/" history') nmap_leader('f:', 'Pick history scope=":"', '":" history') nmap_leader('fa', 'Pick git_hunks scope="staged"', 'Added hunks (all)') nmap_leader('fA', 'Pick git_hunks path="%" scope="staged"', 'Added hunks (current)') nmap_leader('fb', 'Pick buffers', 'Buffers') nmap_leader('fc', 'Pick git_commits', 'Commits (all)') nmap_leader('fC', 'Pick git_commits path="%"', 'Commits (current)') 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 (current)') nmap_leader('fm', 'Pick git_hunks', 'Modified hunks (all)') nmap_leader('fM', 'Pick git_hunks path="%"', 'Modified hunks (current)') nmap_leader('fr', 'Pick resume', 'Resume') nmap_leader('fR', 'Pick lsp scope="references"', 'References (LSP)') nmap_leader('fs', 'Pick lsp scope="workspace_symbol"', 'Symbols workspace (LSP)') nmap_leader('fS', 'Pick lsp scope="document_symbol"', 'Symbols buffer (LSP)') 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('gc', 'Git commit', 'Commit') nmap_leader('gC', 'Git commit --amend', 'Commit amend') nmap_leader('gg', 'lua Config.open_lazygit()', 'Git tab') nmap_leader('gl', 'Git log --oneline', 'Log') nmap_leader('gL', 'Git log --oneline --follow -- %', 'Log buffer') nmap_leader('go', 'lua MiniDiff.toggle_overlay()', 'Toggle overlay') nmap_leader('gs', 'lua MiniGit.show_at_cursor()', 'Show at cursor') xmap_leader('gs', 'lua MiniGit.show_at_cursor()', 'Show at selection') -- l is for 'LSP' (Language Server Protocol) local formatting_cmd = 'lua require("conform").format({ lsp_fallback = true })' nmap_leader('la', 'lua vim.lsp.buf.signature_help()', 'Arguments popup') nmap_leader('ld', 'lua vim.diagnostic.open_float()', 'Diagnostics popup') nmap_leader('lf', formatting_cmd, 'Format') nmap_leader('li', 'lua vim.lsp.buf.hover()', 'Information') nmap_leader('lj', 'lua vim.diagnostic.goto_next()', 'Next diagnostic') nmap_leader('lk', 'lua vim.diagnostic.goto_prev()', 'Prev diagnostic') nmap_leader('lR', 'lua vim.lsp.buf.references()', 'References') nmap_leader('lr', 'lua vim.lsp.buf.rename()', 'Rename') nmap_leader('ls', 'lua vim.lsp.buf.definition()', 'Source definition') xmap_leader('lf', formatting_cmd, 'Format selection') -- L is for 'Lua' nmap_leader('Lc', 'lua Config.log_clear()', 'Clear log') nmap_leader('LL', 'luafile %echo "Sourced lua"', 'Source buffer') nmap_leader('Ls', 'lua Config.log_print()', 'Show log') nmap_leader('Lx', 'lua Config.execute_lua_line()', 'Execute `lua` line') -- m is for 'map' nmap_leader('mc', 'lua MiniMap.close()', 'Close') nmap_leader('mf', 'lua MiniMap.toggle_focus()', 'Focus (toggle)') nmap_leader('mo', 'lua MiniMap.open()', 'Open') nmap_leader('mr', 'lua MiniMap.refresh()', 'Refresh') nmap_leader('ms', 'lua MiniMap.toggle_side()', 'Side (toggle)') nmap_leader('mt', 'lua MiniMap.toggle()', 'Toggle') -- o is for 'other' local trailspace_toggle_command = 'lua vim.b.minitrailspace_disable = not vim.b.minitrailspace_disable' nmap_leader('oC', 'lua MiniCursorword.toggle()', 'Cursor word hl toggle') nmap_leader('od', 'Neogen', 'Document') nmap_leader('oh', 'normal gxiagxila', 'Move arg left') nmap_leader('oH', 'TSBufToggle highlight', 'Highlight toggle') nmap_leader('og', 'lua MiniDoc.generate()', 'Generate plugin doc') nmap_leader('ol', 'normal gxiagxina', 'Move arg right') nmap_leader('or', 'lua MiniMisc.resize_window()', 'Resize to default width') nmap_leader('os', 'lua MiniSessions.select()', 'Session select') nmap_leader('oS', 'lua Config.insert_section()', 'Section insert') nmap_leader('ot', 'lua MiniTrailspace.trim()', 'Trim trailspace') nmap_leader('oT', trailspace_toggle_command, 'Trailspace hl toggle') nmap_leader('oz', 'lua MiniMisc.zoom()', 'Zoom toggle') -- r is for 'R' -- - Mappings starting with `T` send commands to current neoterm buffer, so -- some sort of R interpreter should already run there nmap_leader('rc', 'T devtools::check()', 'Check') nmap_leader('rC', 'T devtools::test_coverage()', 'Coverage') nmap_leader('rd', 'T devtools::document()', 'Document') nmap_leader('ri', 'T devtools::install(keep_source=TRUE)', 'Install') nmap_leader('rk', 'T rmarkdown::render("%")', 'Knit file') nmap_leader('rl', 'T devtools::load_all()', 'Load all') nmap_leader('rT', 'T testthat::test_file("%")', 'Test file') nmap_leader('rt', 'T devtools::test()', 'Test') -- - Copy to clipboard and make reprex (which itself is loaded to clipboard) xmap_leader('rx', '"+y :T reprex::reprex()', 'Reprex selection') -- s is for 'send' (Send text to neoterm buffer) nmap_leader('s', 'TREPLSendLinej', 'Send to terminal') -- - In simple visual mode send text and move to the last character in -- selection and move to the right. Otherwise (like in line or block visual -- mode) send text and move one line down from bottom of selection. local send_selection_cmd = [[mode() ==# "v" ? ":TREPLSendSelection`>l" : ":TREPLSendSelection'>j"]] xmap_leader('s', send_selection_cmd, 'Send to terminal', { expr = true }) -- t is for 'terminal' (uses 'neoterm') and 'minitest' nmap_leader('ta', 'lua MiniTest.run()', 'Test run all') nmap_leader('tf', 'lua MiniTest.run_file()', 'Test run file') nmap_leader('tl', 'lua MiniTest.run_at_location()', 'Test run location') nmap_leader('ts', 'lua Config.minitest_screenshots.browse()', 'Test show screenshot') nmap_leader('tT', 'belowright Tnew', 'Terminal (horizontal)') nmap_leader('tt', 'vertical Tnew', 'Terminal (vertical)') -- T is for 'test' nmap_leader('TF', 'TestFile -strategy=make | copen', 'File (quickfix)') nmap_leader('Tf', 'TestFile', 'File') nmap_leader('TL', 'TestLast -strategy=make | copen', 'Last (quickfix)') nmap_leader('Tl', 'TestLast', 'Last') nmap_leader('TN', 'TestNearest -strategy=make | copen', 'Nearest (quickfix)') nmap_leader('Tn', 'TestNearest', 'Nearest') nmap_leader('TS', 'TestSuite -strategy=make | copen', 'Suite (quickfix)') nmap_leader('Ts', 'TestSuite', 'Suite') -- v is for 'visits' nmap_leader('vv', 'lua MiniVisits.add_label("core")', 'Add "core" label') nmap_leader('vV', 'lua MiniVisits.remove_label("core")', 'Remove "core" label') nmap_leader('vl', 'lua MiniVisits.add_label()', 'Add label') nmap_leader('vL', 'lua MiniVisits.remove_label()', 'Remove label') local map_pick_core = function(keys, cwd, desc) local rhs = function() local sort_latest = MiniVisits.gen_sort.default({ recency_weight = 1 }) MiniExtra.pickers.visit_paths({ cwd = cwd, filter = 'core', sort = sort_latest }, { source = { name = desc } }) end nmap_leader(keys, rhs, desc) end map_pick_core('vc', '', 'Core visits (all)') map_pick_core('vC', nil, 'Core visits (cwd)') -- stylua: ignore end