-- Basic mappings ============================================================= -- NOTE: Most basic mappings come from 'mini.basics' -- Shorter version of the most frequent way of going outside of terminal window vim.keymap.set('t', '', [[h]]) -- Select all -- vim.keymap.set({ "n", "v", "x" }, "", "gg3vG$", { noremap = true, silent = true, desc = "Select all" }) -- Escape deletes highlights vim.keymap.set("n", "", "nohlsearch") -- Paste before/after linewise local cmd = vim.fn.has('nvim-0.12') == 1 and 'iput' or 'put' vim.keymap.set({ 'n', 'x' }, '[p', 'exe "' .. cmd .. '! " . v:register', { desc = 'Paste Above' }) vim.keymap.set({ 'n', 'x' }, ']p', 'exe "' .. cmd .. ' " . v:register', { desc = 'Paste Below' }) vim.keymap.set({ "n", "v", "x" }, "p", '"+p', { noremap = true, silent = true, desc = "Paste from clipboard" }) vim.keymap.set({ "n", "v", "x" }, "y", '"+y', { noremap = true, silent = true, desc = "Copy toclipboard" }) -- Leader mappings ============================================================ -- 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 = 'a', desc = '+AI' }, { mode = 'n', keys = 'b', desc = '+Buffer' }, { mode = 'n', keys = 'e', desc = '+Explore' }, { mode = 'n', keys = 'f', desc = '+Find' }, { mode = 'n', keys = 'fl', desc = '+LSP' }, { mode = 'n', keys = 'fa', desc = '+Git' }, { mode = 'n', keys = 'g', desc = '+Git' }, { mode = 'n', keys = 'l', desc = '+LSP' }, { mode = 'n', keys = 'L', desc = '+Lua/Log' }, { mode = 'n', keys = 'o', desc = '+Other' }, { mode = 'n', keys = 'r', desc = '+R' }, { mode = 'n', keys = 't', desc = '+Terminal' }, { mode = 'n', keys = 'u', desc = '+UI' }, { mode = 'n', keys = 'v', desc = '+Visits' }, { mode = 'n', keys = 'w', desc = '+Windows' }, { mode = 'x', keys = 'l', desc = '+LSP' }, { mode = 'x', keys = 'r', desc = '+R' }, { mode = 'n', keys = 'z', desc = '+ZK' }, { mode = 'n', keys = 'zr', desc = '+Reviews' }, { mode = 'x', keys = 'a', desc = '+AI' }, } -- 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 -- Other mappings local nmap_lsp = function(keys, func, desc) if desc then desc = desc .. "(LSP)" end vim.keymap.set("n", keys, func, { desc = desc }) end -- Switch buffers nmap_leader('', 'bnext', 'Next buffer') nmap_leader('', 'bprev', 'Prev buffer') -- a is for 'AI' nmap_leader("ac", "CodeCompanionChat Toggle", "Chat Toggle") nmap_leader("ae", "CodeCompanion /explain", "Explain Code") nmap_leader("af", "CodeCompanion /fix", "Fix Code") nmap_leader("ag", "CodeCompanion /commit", "Generate commit message") nmap_leader("ai", "CodeCompanionActions", "Chat Action") nmap_leader("al", "CodeCompanion /lsp", "Explain LSP Diagnostics") nmap_leader("an", "CodeCompanionChat Add", "Chat New") nmap_leader("as", "CodeCompanion /suggest", "Suggest Improvements") nmap_leader("ax", "CodeCompanion /fixer", "Code Fixer") nmap_leader("ax", "CodeCompanion /fixer", "Code Fixer") xmap_leader("ae", "CodeCompanion /explain", "Explain Code") xmap_leader("af", "CodeCompanion /fix", "Fix Code") xmap_leader("ap", "CodeCompanion /expert", "Code Fixer") xmap_leader("ap", "CodeCompanion /expert", "Code Fixer") xmap_leader("as", "CodeCompanion /suggest", "Suggest Improvements") -- b is for 'buffer' nmap_leader('bb', '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!') nmap_leader('bq', 'qall', 'Quit all') -- e is for 'explore' and 'edit' nmap_leader('ed', 'lua MiniFiles.open()', 'Directory') nmap_leader('ef', 'lua Config.try_opendir()', 'File directory') nmap_leader('es', 'lua MiniSessions.select()', 'Sessions') nmap_leader('eq', 'lua Config.toggle_quickfix()', 'Quickfix') nmap_leader('ez', 'lua MiniFiles.open(os.getenv("ZK_NOTEBOOK_DIR"))', 'Notes directory') -- f is for 'fuzzy find' nmap_leader('f/', 'Pick history scope="/"', '"/" history') nmap_leader('f:', 'Pick history scope=":"', '":" history') nmap_leader('f,', 'Pick visit_labels', 'Visit labels') nmap_leader('faa', 'Pick git_hunks scope="staged"', 'Added hunks (all)') nmap_leader('faA', 'Pick git_hunks path="%" scope="staged"', 'Added hunks (current)') nmap_leader('fb', 'Pick buffers', 'Buffers') nmap_leader(',', 'Pick buffers', 'Buffers') nmap_leader('fac', 'Pick git_commits', 'Commits (all)') nmap_leader('faC', '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('fj', 'Pick buf_lines scope="all"', 'Lines (all)') nmap_leader('fJ', 'Pick buf_lines scope="current"', 'Lines (current)') nmap_leader('fam', 'Pick git_hunks', 'Modified hunks (all)') nmap_leader('faM', 'Pick git_hunks path="%"', 'Modified hunks (current)') nmap_leader('fm', 'Pick marks', 'Marks') nmap_leader('fn', 'ZkNotes', "Notes") nmap_leader('fk', 'Pick keymaps', 'Keymaps') nmap_leader('fR', 'Pick resume', 'Resume') nmap_leader('fp', 'Pick projects', 'Projects') nmap_leader('fq', 'Pick list scope="quickfix"', 'Quickfix') nmap_leader('fr', 'Pick lsp scope="references"', 'References (LSP)') nmap_leader('flr', 'Pick lsp scope="references"', 'References (LSP)') nmap_leader('fS', 'Pick lsp scope="workspace_symbol"', 'Symbols workspace (LSP)') nmap_leader('flS', 'Pick lsp scope="workspace_symbol"', 'Symbols workspace (LSP)') nmap_leader('fs', 'Pick lsp scope="document_symbol"', 'Symbols buffer (LSP)') nmap_leader('fls', 'Pick lsp scope="document_symbol"', 'Symbols buffer (LSP)') nmap_leader('fld', 'Pick lsp scope="definition"', 'Definition (LSP)') nmap_leader('flD', 'Pick lsp scope="declaration"', 'Declaration (LSP)') nmap_leader('flt', 'Pick lsp scope="type_definition"', 'Type Definition (LSP)') nmap_leader('fv', 'Pick visit_paths cwd=""', 'Visit paths (all)') nmap_leader('fV', 'Pick visit_paths', 'Visit paths (cwd)') -- g is for git local git_log_cmd = [[Git log --pretty=format:\%h\ \%as\ │\ \%s --topo-order]] nmap_leader('gc', 'Git commit', 'Commit') nmap_leader('gC', 'Git commit --amend', 'Commit amend') nmap_leader('gd', 'Git diff', 'Diff') nmap_leader('gD', 'Git diff -- %', 'Diff buffer') nmap_leader('gg', 'lua require("neogit").open()', 'Git tab') nmap_leader('gl', '' .. git_log_cmd .. '', 'Log') nmap_leader('gL', '' .. git_log_cmd .. ' --follow -- %', 'Log buffer') nmap_leader('go', 'lua MiniDiff.toggle_overlay()', 'Toggle overlay') nmap_leader('gp', 'Git pull', 'Pull') nmap_leader('gP', 'Git push', 'Push') nmap_leader('gs', 'lua MiniGit.show_at_cursor()', 'Show at cursor') xmap_leader('gs', 'lua MiniGit.show_at_cursor()', 'Show at selection') -- j/k navigate quickfix nmap_leader("j", 'cnextzz', "Quickfix next") nmap_leader("k", 'cprevzz', "Quickfix prev") -- l is for 'LSP' (Language Server Protocol) vim.keymap.set({ 'n' }, 'grd', 'lua vim.lsp.buf.definition()', { desc = 'Definition' }) vim.keymap.set({ 'n' }, 'grk', 'lua vim.lsp.buf.hover()', { desc = 'Documentation' }) vim.keymap.set({ 'n' }, 'gre', 'lua vim.diagnostic.open_float()', { desc = 'Diagnostics' }) nmap_lsp("K", 'lua vim.lsp.buf.hover()', "Documentation") local formatting_cmd = 'lua require("conform").format({ lsp_fallback = true })' nmap_leader('la', 'lua vim.lsp.buf.code_action()', 'Actions') nmap_leader('le', 'lua vim.diagnostic.open_float()', 'Diagnostics popup') nmap_leader('lf', formatting_cmd, 'Format') nmap_leader('lk', 'lua vim.lsp.buf.hover()', 'Documentation') nmap_leader('li', 'lua vim.lsp.buf.implementation()', 'Information') -- use ]d and [d --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 free -- o is for 'other' local trailspace_toggle_command = 'lua vim.b.minitrailspace_disable = not vim.b.minitrailspace_disable' nmap_leader('od', 'Neogen', 'Document') nmap_leader('oh', 'normal gxiagxila', 'Move arg left') nmap_leader('ol', 'normal gxiagxina', 'Move arg right') nmap_leader('or', 'lua MiniMisc.resize_window()', 'Resize to default width') 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') nmap_leader('ow', "lua MiniSessions.write(vim.fn.input('Session name: ', string.match(vim.fn.getcwd(), \"[^/]+$\") .. '-session.vim'))", 'Write session') -- r is for 'R' nmap_leader('rc', 'RSend devtools::check()', 'Check') nmap_leader('rC', 'RSend devtools::test_coverage()', 'Coverage') nmap_leader('rd', 'RSend devtools::document()', 'Document') nmap_leader('ri', 'RSend devtools::install(keep_source=TRUE)', 'Install') nmap_leader('rk', 'RSend quarto::quarto_preview("%")', 'Knit file') nmap_leader('rl', 'RSend devtools::load_all()', 'Load all') nmap_leader('rL', 'RSend devtools::load_all(recompile=TRUE)', 'Load all recompile') nmap_leader('rm', 'RSend Rcpp::compileAttributes()', 'Run examples') nmap_leader('rT', 'RSend testthat::test_file("%")', 'Test file') nmap_leader('rt', 'RSend devtools::test()', 'Test') -- - Copy to clipboard and make reprex (which itself is loaded to clipboard) xmap_leader('rx', '"+y :RSend reprex::reprex()', 'Reprex selection') -- s is for 'send' (Send text to neoterm buffer) nmap_leader('s', 'SlimeSendCurrentLinej', '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. xmap_leader('s', 'SlimeRegionSend', 'Send to terminal') -- t is for 'terminal' vim.keymap.set("t", "", [[]], { desc = "Exit terminal mode" }) vim.keymap.set("n", "tc", 'lua Config.terminal.open_clickhouse_client()', { desc = "Open Clickhouse client" }) vim.keymap.set("n", "tl", 'lua Config.terminal.open_clickhouse_local()', { desc = "Open Clickhouse local" }) vim.keymap.set("n", "tp", 'lua Config.terminal.open_python()', { desc = "Open Python" }) vim.keymap.set("n", "tj", 'lua Config.terminal.open_julia()', { desc = "Open Julia" }) vim.keymap.set("n", "td", 'lua Config.terminal.open_duckdb();Config.terminal.toggle_bracket()', { desc = "Open DuckDB" }) vim.keymap.set("n", "tx", 'lua Config.terminal.open_in_terminal()', { desc = "Terminal Command" }) vim.keymap.set("n", "tt", 'lua Config.terminal.open_shell()', { desc = "Terminal" }) nmap_leader("tb", 'lua Config.terminal.toggle_bracket()', "Toggle bracketed paste") nmap_leader("up", 'lua Config.terminal.toggle_bracket()', "Toggle bracketed paste") -- u is for UI nmap_leader('ut', 'TSContext toggle', 'Toggle TScontext') nmap_leader('ua', 'Copilot toggle', 'Toggle AI completion') -- 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)') -- w is for 'windows' nmap_leader("wh", "h", "Go to Left Window", { remap = true }) nmap_leader("wj", "j", "Go to Lower Window", { remap = true }) nmap_leader("wk", "k", "Go to Upper Window", { remap = true }) nmap_leader("wl", "l", "Go to Right Window", { remap = true }) nmap_leader("_", "s", "Split Window Below", { remap = true }) nmap_leader("|", "v", "Split Window Right", { remap = true }) nmap_leader("wd", "c", "Delete Window", { remap = true }) nmap_leader("wo", "o", "Delete Other Windows", { remap = true }) -- z is for 'ZettelKasten' nmap_leader("zo", 'ZkNotes', "Notes") nmap_leader("zt", 'ZkTags', "Tags") nmap_leader( "zrd", 'ZkNew { group = "dreviews" }', "Daily Review" ) nmap_leader( "zrw", 'ZkNew { group = "wreviews" }', "Weekly Review" ) nmap_leader( "zn", 'ZkNew { group = "inbox", title = vim.fn.input("Title: ") }', "New" ) nmap_leader( "zp", "ZkNew { group = 'permanent', title = vim.fn.input('Title: ') }", "Permanent" ) nmap_leader( "zl", "ZkNew { group = 'literature', title = vim.fn.input('Title: '), extra.author = vim.fn.input('Author: '), extra.year = vim.fn.input('Year: ') }", "Literature" ) nmap_leader( "zd", "ZkNew { group = 'dashboard', title = vim.fn.input('Title: ') }", "Dashboard" ) nmap_leader( "zP", "ZkNew { group = 'project', title = vim.fn.input('Title: ')}", "Project" ) -- stylua: ignore end