refactor: merge leader functions

This commit is contained in:
Job Jobse
2026-09-23 20:29:53 +02:00
parent 09977eae88
commit cc4945649b
+59 -65
View File
@@ -14,12 +14,8 @@ Config.leader_group_clues = {
} }
-- Keymap Helpers -- Keymap Helpers
local nmap_leader = function(suffix, rhs, desc) local leader = function(suffix, rhs, desc, mode)
vim.keymap.set('n', '<Leader>' .. suffix, rhs, { desc = desc, silent = true }) vim.keymap.set(mode or 'n', '<Leader>' .. suffix, rhs, { desc = desc, silent = true })
end
local xmap_leader = function(suffix, rhs, desc)
vim.keymap.set('x', '<Leader>' .. suffix, rhs, { desc = desc, silent = true })
end end
-- Buffers -- Buffers
@@ -34,19 +30,19 @@ local close_invisible_buffers = function()
:each(function(buf) pcall(vim.api.nvim_buf_delete, buf, { force = false }) end) :each(function(buf) pcall(vim.api.nvim_buf_delete, buf, { force = false }) end)
end end
nmap_leader('bd', vim.cmd.bdelete, 'Delete') leader('bd', vim.cmd.bdelete, 'Delete')
nmap_leader('bs', new_scratch_buffer, 'Scratch') leader('bs', new_scratch_buffer, 'Scratch')
nmap_leader('bw', vim.cmd.bwipeout, 'Wipeout') leader('bw', vim.cmd.bwipeout, 'Wipeout')
nmap_leader('bo', close_invisible_buffers, 'Close invisible buffers') leader('bo', close_invisible_buffers, 'Close invisible buffers')
-- Debug -- Debug
nmap_leader('db', function() require('dap').toggle_breakpoint() end, 'Toggle Breakpoint') leader('db', function() require('dap').toggle_breakpoint() end, 'Toggle Breakpoint')
nmap_leader('dl', function() require('dap').set_breakpoint(nil, nil, vim.fn.input('Log point: ')) end, 'Log point') leader('dl', function() require('dap').set_breakpoint(nil, nil, vim.fn.input('Log point: ')) end, 'Log point')
nmap_leader('dc', function() require('dap').continue() end, 'Run/Continue') leader('dc', function() require('dap').continue() end, 'Run/Continue')
nmap_leader('dC', function() require('dap').run_to_cursor() end, 'Run to Cursor') leader('dC', function() require('dap').run_to_cursor() end, 'Run to Cursor')
nmap_leader('de', function() require('dap.ui.widgets').hover() end, 'Inspect') leader('de', function() require('dap.ui.widgets').hover() end, 'Inspect')
nmap_leader('dr', function() require('dap').repl.open() end, 'Open REPL') leader('dr', function() require('dap').repl.open() end, 'Open REPL')
nmap_leader('dt', function() require('dap').terminate() end, 'Terminate') leader('dt', function() require('dap').terminate() end, 'Terminate')
-- Explore -- Explore
local explore_at_file = function() local explore_at_file = function()
@@ -54,30 +50,30 @@ local explore_at_file = function()
MiniFiles.open(vim.uv.fs_stat(file) and file or nil) MiniFiles.open(vim.uv.fs_stat(file) and file or nil)
end end
nmap_leader('ed', function() MiniFiles.open() end, 'Directory') leader('ed', function() MiniFiles.open() end, 'Directory')
nmap_leader('ef', explore_at_file, 'File directory') leader('ef', explore_at_file, 'File directory')
nmap_leader('ey', function() vim.fn.setreg('+', vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ':.')) end, 'Yank relative path') leader('ey', function() vim.fn.setreg('+', vim.fn.fnamemodify(vim.api.nvim_buf_get_name(0), ':.')) end, 'Yank relative path')
nmap_leader('eY', function() vim.fn.setreg('+', vim.api.nvim_buf_get_name(0)) end, 'Yank absolute path') leader('eY', function() vim.fn.setreg('+', vim.api.nvim_buf_get_name(0)) end, 'Yank absolute path')
nmap_leader('en', vim.cmd.messages, 'Notifications') leader('en', vim.cmd.messages, 'Notifications')
-- Find -- Find
nmap_leader('fb', function() MiniPick.builtin.buffers() end, 'Buffers') leader('fb', function() MiniPick.builtin.buffers() end, 'Buffers')
nmap_leader('fc', function() MiniExtra.pickers.git_commits() end, 'Commits (all)') leader('fc', function() MiniExtra.pickers.git_commits() end, 'Commits (all)')
nmap_leader('fC', function() MiniExtra.pickers.git_commits({ path = vim.fn.expand('%') }) end, 'Commits (buf)') leader('fC', function() MiniExtra.pickers.git_commits({ path = vim.fn.expand('%') }) end, 'Commits (buf)')
nmap_leader('fd', function() MiniExtra.pickers.diagnostic({ scope = 'all' }) end, 'Diagnostic workspace') leader('fd', function() MiniExtra.pickers.diagnostic({ scope = 'all' }) end, 'Diagnostic workspace')
nmap_leader('fD', function() MiniExtra.pickers.diagnostic({ scope = 'current' }) end, 'Diagnostic buffer') leader('fD', function() MiniExtra.pickers.diagnostic({ scope = 'current' }) end, 'Diagnostic buffer')
nmap_leader('ff', function() MiniPick.builtin.files() end, 'Files') leader('ff', function() MiniPick.builtin.files() end, 'Files')
nmap_leader('fg', function() MiniPick.builtin.grep_live() end, 'Grep live') leader('fg', function() MiniPick.builtin.grep_live() end, 'Grep live')
nmap_leader('fG', function() MiniPick.builtin.grep({ pattern = vim.fn.expand('<cword>') }) end, 'Grep word') leader('fG', function() MiniPick.builtin.grep({ pattern = vim.fn.expand('<cword>') }) end, 'Grep word')
nmap_leader('fh', function() MiniPick.builtin.help() end, 'Help tags') leader('fh', function() MiniPick.builtin.help() end, 'Help tags')
nmap_leader('fl', function() MiniExtra.pickers.buf_lines({ scope = 'all' }) end, 'Lines (all)') leader('fl', function() MiniExtra.pickers.buf_lines({ scope = 'all' }) end, 'Lines (all)')
nmap_leader('fL', function() MiniExtra.pickers.buf_lines({ scope = 'current' }) end, 'Lines (buf)') leader('fL', function() MiniExtra.pickers.buf_lines({ scope = 'current' }) end, 'Lines (buf)')
nmap_leader('fm', function() require('git').status() end, 'Modified / changed files') leader('fm', function() require('git').status() end, 'Modified / changed files')
nmap_leader('fo', function() MiniExtra.pickers.oldfiles() end, 'Old / recent files') leader('fo', function() MiniExtra.pickers.oldfiles() end, 'Old / recent files')
nmap_leader('fr', function() MiniPick.builtin.resume() end, 'Resume') leader('fr', function() MiniPick.builtin.resume() end, 'Resume')
nmap_leader('fs', function() MiniExtra.pickers.lsp({ scope = 'workspace_symbol_live' }) end, 'Symbols workspace') leader('fs', function() MiniExtra.pickers.lsp({ scope = 'workspace_symbol_live' }) end, 'Symbols workspace')
nmap_leader('fS', function() MiniExtra.pickers.lsp({ scope = 'document_symbol' }) end, 'Symbols document') leader('fS', function() MiniExtra.pickers.lsp({ scope = 'document_symbol' }) end, 'Symbols document')
nmap_leader('f:', function() MiniExtra.pickers.history({ scope = ':' }) end, 'Command history') leader('f:', function() MiniExtra.pickers.history({ scope = ':' }) end, 'Command history')
-- Git -- Git
local diff_unstaged = function() local diff_unstaged = function()
@@ -86,44 +82,42 @@ local diff_unstaged = function()
vim.cmd.diffthis() vim.cmd.diffthis()
end end
nmap_leader('ga', function() vim.cmd('Git add %') end, 'Add current file') leader('ga', function() vim.cmd('Git add %') end, 'Add current file')
nmap_leader('gd', diff_unstaged, 'Diff unstaged') leader('gd', diff_unstaged, 'Diff unstaged')
nmap_leader('gs', function() MiniGit.show_at_cursor() end, 'Show at cursor') leader('gs', function() MiniGit.show_at_cursor() end, 'Show at cursor')
xmap_leader('gs', function() MiniGit.show_at_cursor() end, 'Show at selection') leader('gs', function() MiniGit.show_at_cursor() end, 'Show at selection', 'x')
-- Language -- Language
nmap_leader('la', function() vim.lsp.buf.code_action() end, 'Actions') leader('la', function() vim.lsp.buf.code_action() end, 'Actions')
nmap_leader('ld', function() vim.diagnostic.open_float() end, 'Diagnostic popup') leader('lf', function() require('conform').format({ async = true }) end, 'Format')
nmap_leader('lf', function() require('conform').format({ async = true }) end, 'Format') leader('lf', function() require('conform').format({ async = true }) end, 'Format selection', 'x')
xmap_leader('lf', function() require('conform').format({ async = true }) end, 'Format selection') leader('li', function() vim.lsp.buf.implementation() end, 'Implementation')
nmap_leader('li', function() vim.lsp.buf.implementation() end, 'Implementation') leader('ll', function() vim.lsp.codelens.run() end, 'Lens')
nmap_leader('lh', function() vim.lsp.buf.hover() end, 'Hover') leader('lr', function() vim.lsp.buf.rename() end, 'Rename')
nmap_leader('ll', function() vim.lsp.codelens.run() end, 'Lens') leader('lR', function() vim.lsp.buf.references() end, 'References')
nmap_leader('lr', function() vim.lsp.buf.rename() end, 'Rename') leader('ls', function() vim.lsp.buf.definition() end, 'Source definition')
nmap_leader('lR', function() vim.lsp.buf.references() end, 'References') leader('lt', function() vim.lsp.buf.type_definition() end, 'Type definition')
nmap_leader('ls', function() vim.lsp.buf.definition() end, 'Source definition')
nmap_leader('lt', function() vim.lsp.buf.type_definition() end, 'Type definition')
-- Request -- Request
nmap_leader('rs', function() require('kulala').run() end, 'Send HTTP request') leader('rs', function() require('kulala').run() end, 'Send HTTP request')
-- Terminal -- Terminal
local open_ai = function() local open_ai = function()
vim.cmd('vertical term ' .. (vim.fn.executable('pi') == 1 and 'pi' or 'claude')) vim.cmd('vertical term ' .. (vim.fn.executable('pi') == 1 and 'pi' or 'claude'))
end end
nmap_leader('tT', function() vim.cmd('horizontal term') end, 'Terminal (horizontal)') leader('tT', function() vim.cmd('horizontal term') end, 'Terminal (horizontal)')
nmap_leader('tt', function() vim.cmd('vertical term') end, 'Terminal (vertical)') leader('tt', function() vim.cmd('vertical term') end, 'Terminal (vertical)')
nmap_leader('ta', open_ai, 'AI') leader('ta', open_ai, 'AI')
nmap_leader('tf', function() require('terminal').open(vim.o.shell) end, 'Terminal (popup)') leader('tf', function() require('terminal').open(vim.o.shell) end, 'Terminal (popup)')
nmap_leader('tg', function() require('terminal').open('lazygit') end, 'LazyGit') leader('tg', function() require('terminal').open('lazygit') end, 'LazyGit')
nmap_leader('ts', function() require('terminal').open('lazysql') end, 'LazySQL') leader('ts', function() require('terminal').open('lazysql') end, 'LazySQL')
-- Tabs -- Tabs
nmap_leader('<Tab><Tab>', vim.cmd.tabnew, 'New tab') leader('<Tab><Tab>', vim.cmd.tabnew, 'New tab')
nmap_leader('<Tab>d', vim.cmd.tabclose, 'Close tab') leader('<Tab>d', vim.cmd.tabclose, 'Close tab')
nmap_leader('<Tab>]', vim.cmd.tabnext, 'Next tab') leader('<Tab>]', vim.cmd.tabnext, 'Next tab')
nmap_leader('<Tab>[', vim.cmd.tabprevious, 'Previous tab') leader('<Tab>[', vim.cmd.tabprevious, 'Previous tab')
-- Overwrites -- Overwrites
vim.keymap.set('n', '<Esc>', vim.cmd.nohlsearch, { desc = 'Clear highlights', silent = true }) vim.keymap.set('n', '<Esc>', vim.cmd.nohlsearch, { desc = 'Clear highlights', silent = true })