feat: which-key icons for plugins

This commit is contained in:
punkfairie 2024-12-01 17:10:02 -08:00
parent 46f5ab5a65
commit 7d4b907416
Signed by: punkfairie
GPG key ID: A509E8F77FB9D696
10 changed files with 219 additions and 86 deletions

13
nvim/lua/colors.lua Normal file
View file

@ -0,0 +1,13 @@
---@type {[string]:"azure" | "blue" | "cyan" | "green" | "grey" | "orange" | "purple" | "red" | "yellow"}
return {
buffers = 'cyan',
diagnostics = 'green',
surround = 'purple',
ui = 'green',
window = 'blue',
search = 'green',
git = 'orange',
notifications = 'orange',
sessions = 'azure',
explorer = 'yellow',
}

View file

@ -22,12 +22,12 @@ end
-- Resize windows -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
for key, dir in pairs({
Up = 'Increase',
Down = 'Decrease',
Left = 'Decrease',
Right = 'Increase',
Up = 'increase',
Down = 'decrease',
Left = 'decrease',
Right = 'increase',
}) do
local sign = (dir == 'Increase') and '+' or '-'
local sign = (dir == 'increase') and '+' or '-'
set(
{ 'n' },
@ -44,8 +44,8 @@ for key, dir in pairs({
['[b'] = 'previous',
[']b'] = 'next',
}) do
-- previous -> Prev
local prettyDir = (dir:gsub('^%l', string.upper)):sub(1, 4)
-- previous -> prev
local prettyDir = dir:sub(1, 4)
set(
{ 'n' },
@ -55,21 +55,21 @@ for key, dir in pairs({
)
end
set({ 'n' }, '<LEADER>bD', '<CMD>bd<CR>', { desc = 'Delete buffer and window' })
set({ 'n' }, '<LEADER>bD', '<CMD>bd<CR>', { desc = 'delete buffer and window' })
-- Clear search & refresh -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
set(
{ 'n', 'i' },
'<ESC>',
'<CMD>noh<CR><ESC>',
{ desc = 'Escape and clear hlsearch' }
{ desc = 'escape and clear hlsearch' }
)
set(
{ 'n' },
'<LEADER>ur',
'<CMD>nohlsearch<BAR>diffupdate<BAR>normal! <C-l><CR>',
{ desc = 'Redraw / clear hlsearch / diff update' }
{ desc = 'redraw / clear hlsearch / diff update' }
)
-- Better n & N -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
@ -80,14 +80,14 @@ for _, mode in ipairs({ 'n', 'x', 'o' }) do
{ mode },
'n',
f("'Nn'[v:searchforward]%s", zv),
{ desc = 'Next search result', expr = true }
{ desc = 'next search result', expr = true }
)
set(
{ mode },
'N',
f("'nN'[v:searchforward]%s", zv),
{ desc = 'Previous search result', expr = true }
{ desc = 'previous search result', expr = true }
)
end
@ -102,34 +102,36 @@ set(
{ 'n' },
'<LEADER>K',
'<CMD>norm! K<CR>',
{ desc = 'Search <KEYWORDPROG> for word' }
{ desc = 'search <KEYWORDPROG> for word' }
)
-- Better indenting -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
for _, char in ipairs({ '<', '>' }) do
set({ 'v' }, char, f('%sgv', char))
local desc = 'indent ' .. (char == '<' and 'left' or 'right')
set({ 'v' }, char, f('%sgv', char), { desc = desc })
end
-- Commenting -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
for key, dir in pairs({ o = 'Below', O = 'Above' }) do
for key, dir in pairs({ o = 'below', O = 'above' }) do
set(
{ 'n' },
f('gc%s', key),
f('%s<ESC>Vcx<ESC><CMD>normal gcc<CR>fxa<BS>', key),
{ desc = f('Add comment %s', dir) }
{ desc = f('add comment %s', dir) }
)
end
-- New files -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
set({ 'n' }, '<LEADER>fn', '<CMD>enew<CR>', { desc = 'New file' })
set({ 'n' }, '<LEADER>fn', '<CMD>enew<CR>', { desc = 'new file' })
-- Locations/quickfixes -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
set({ 'n' }, '<LEADER>xl', '<CMD>lopen<CR>', { desc = 'Location list' })
set({ 'n' }, '<LEADER>xq', '<CMD>copen<CR>', { desc = 'Quickfix list' })
set({ 'n' }, '<LEADER>xl', '<CMD>lopen<CR>', { desc = 'location list' })
set({ 'n' }, '<LEADER>xq', '<CMD>copen<CR>', { desc = 'quickfix list' })
for key, dir in pairs({ ['['] = 'Previous', [']'] = 'Next' }) do
-- Previous -> prev
local cmd = (dir:gsub('^%l', string.lower)):sub(1, 4)
for key, dir in pairs({ ['['] = 'previous', [']'] = 'next' }) do
-- previous -> prev
local cmd = dir:sub(1, 4)
set(
{ 'n' },
@ -142,7 +144,7 @@ end
-- Diagnostics -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
set({ 'n' }, '<LEADER>cd', function()
vim.diagnostic.open_float()
end, { desc = 'Line diagnostics' })
end, { desc = 'line diagnostics' })
local function goto_diagnostic(next, severity)
local go = next and vim.diagnostic.goto_next or vim.diagnostic.goto_prev
@ -153,48 +155,48 @@ local function goto_diagnostic(next, severity)
end
for key, sev in pairs({
d = { nil, 'Diagnostic' },
e = { 'ERROR', 'Error' },
w = { 'WARN', 'Warning' },
d = { nil, 'diagnostic' },
e = { 'ERROR', 'error' },
w = { 'WARN', 'warning' },
}) do
set(
{ 'n' },
f(']%s', key),
goto_diagnostic(true, sev[1]),
{ desc = f('Next %s', sev[2]) }
{ desc = f('next %s', sev[2]) }
)
set(
{ 'n' },
f('[%s', key),
goto_diagnostic(false, sev[1]),
{ desc = f('Previous %s', sev[2]) }
{ desc = f('previous %s', sev[2]) }
)
end
-- Quit -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
set({ 'n' }, '<LEADER>qq', '<CMD>qa<CR>', { desc = 'Quit all' })
set({ 'n' }, '<LEADER>qq', '<CMD>qa<CR>', { desc = 'quit all' })
-- Inspect -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
set({ 'n' }, '<LEADER>ui', vim.show_pos, { desc = 'Inspect position' })
set({ 'n' }, '<LEADER>ui', vim.show_pos, { desc = 'inspect position' })
-- Window management -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
set({ 'n' }, '<LEADER>w', '<C-w>', { desc = 'Windows', remap = true })
set({ 'n' }, '<LEADER>-', '<C-w>s', { desc = 'Split below', remap = true })
set({ 'n' }, '<LEADER>|', '<C-w>v', { desc = 'Split right', remap = true })
set({ 'n' }, '<LEADER>wd', '<C-w>c', { desc = 'Delete window', remap = true })
set({ 'n' }, '<LEADER>w', '<C-w>', { desc = 'windows', remap = true })
set({ 'n' }, '<LEADER>-', '<C-w>s', { desc = 'split below', remap = true })
set({ 'n' }, '<LEADER>|', '<C-w>v', { desc = 'split right', remap = true })
set({ 'n' }, '<LEADER>wd', '<C-w>c', { desc = 'delete window', remap = true })
-- Tab management -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
for key, act in pairs({
l = 'Last',
o = 'Only',
f = 'First',
['<TAB>'] = 'New',
[']'] = 'Next',
d = 'Close',
['['] = 'Previous',
l = 'last',
o = 'only',
f = 'first',
['<TAB>'] = 'new',
[']'] = 'next',
d = 'close',
['['] = 'previous',
}) do
local desc = (act == 'Only') and 'Close other tabs' or f('%s tab', act)
local desc = (act == 'only') and 'close other tabs' or f('%s tab', act)
set(
{ 'n' },

View file

@ -19,4 +19,20 @@ function M.local_require(prefix)
end
end
---Generates a function that can be used to create which-key mappings.
---@param color string The color to use for the icon.
---@return function
function M.wkSpec(color)
---@param lhs string
---@param icon string
---@param opts? wk.Spec
return function(lhs, icon, opts)
return vim.tbl_deep_extend(
'force',
{ lhs, icon = { icon = icon, color = color } },
(opts or {})
)
end
end
return M

View file

@ -8,7 +8,7 @@ return {
require('flash').jump()
end,
mode = { 'n', 'x', 'o' },
desc = 'Flash',
desc = 'flash',
},
{
'S',
@ -16,14 +16,15 @@ return {
require('flash').treesitter()
end,
mode = { 'n', 'x', 'o' },
desc = 'Flash (treesitter)',
desc = 'flash (treesitter)',
},
{
'r',
function()
require('flash').remote()
end,
desc = 'Remote flash',
mode = { 'o' },
desc = 'remote flash',
},
{
'R',
@ -31,17 +32,30 @@ return {
require('flash').treesitter_search()
end,
mode = { 'x', 'o' },
desc = 'Treesitter search',
desc = 'treesitter search',
},
{
'<C-s>',
function()
require('flash').toggle()
end,
'Toggle flash search',
mode = { 'c' },
desc = 'toggle flash search',
},
},
before = function()
require('lz.n').trigger_load('which-key.nvim')
end,
after = function()
require('flash').setup({})
local mkKey = MarleyVim.wkSpec(require('colors').search)
require('which-key').add({
mkKey('s', '', { mode = { 'n', 'x', 'o' } }),
mkKey('S', '', { mode = { 'n', 'x', 'o' } }),
mkKey('r', '', { mode = { 'o' } }),
mkKey('r', '󰊕', { mode = { 'x', 'o' } }),
mkKey('<C-s>', '󰥖', { mode = { 'c' } }),
})
end,
}

View file

@ -16,7 +16,7 @@ return {
})
end,
mode = { 'n', 'v' },
desc = 'Search and replace',
desc = 'search and replace',
},
},
after = function()

View file

@ -15,7 +15,7 @@ local function make_toggle_mapping(root, grouped)
dir = root and (MarleyVim.root()) or (vim.uv.cwd()),
})
end,
desc = 'Explorer (' .. (root and 'root' or 'cwd') .. ')',
desc = 'explorer (' .. (root and 'root' or 'cwd') .. ')',
}
end
@ -35,7 +35,7 @@ return {
toggle = true,
})
end,
desc = 'Git explorer',
desc = 'git explorer',
},
{
'<LEADER>be',
@ -45,11 +45,16 @@ return {
toggle = true,
})
end,
desc = 'Buffer explorer',
desc = 'buffer explorer',
},
},
before = function()
require('lz.n').trigger_load({ 'plenary.nvim', 'mini.icons', 'nui.nvim' })
require('lz.n').trigger_load({
'plenary.nvim',
'mini.icons',
'nui.nvim',
'which-key.nvim',
})
end,
after = function()
local icons = require('icons')
@ -122,5 +127,11 @@ return {
{ event = events.FILE_RENAMED, handler = on_move },
},
})
local colors = require('colors')
require('which-key').add({
{ '<LEADER>ge', icon = { icon = '', color = colors.git } },
{ '<LEADER>be', icon = { icon = '', color = colors.buffer } },
})
end,
}

View file

@ -21,6 +21,9 @@ return {
require('lz.n').trigger_load('mini.icons')
end,
after = function()
local icons = require('icons')
local colors = require('colors')
require('which-key').setup({
preset = 'modern',
spec = {
@ -37,12 +40,12 @@ return {
{
'<LEADER>u',
group = 'ui',
icon = { icon = '󰙵 ', color = 'cyan' },
icon = { icon = '󰙵 ', color = colors.ui },
},
{
'<LEADER>x',
group = 'diagnostics/quickfix',
icon = { icon = '󱖫 ', color = 'green' },
icon = { icon = '󱖫 ', color = colors.diagnostics },
},
{ '[', group = 'previous' },
{ ']', group = 'next' },
@ -50,7 +53,7 @@ return {
{
'gs',
group = 'surround',
icon = { icon = '󰅲', color = 'purple' },
icon = { icon = '󰅲', color = colors.surround },
},
{ 'z', group = 'fold' },
{
@ -67,12 +70,59 @@ return {
return require('which-key.extras').expand.win()
end,
},
{ 'gx', desc = 'Open with system app' },
{ 'gx', desc = 'open with system app' },
{ '<LEADER>ur', icon = { icon = '', color = colors.ui } },
{ '<LEADER>|', icon = { icon = '' } },
{ '<LEADER>-', icon = { icon = '' } },
},
{
mode = { 'n', 'i' },
hidden = true,
{ '<DOWN>' },
{ '<UP>' },
{ '<LEFT>' },
{ '<RIGHT>' },
},
{
mode = { 'n', 'x' },
hidden = true,
{ 'j' },
{ 'k' },
},
{
mode = { 'v' },
{ '<', icon = { icon = '󰉵' } },
{ '>', icon = { icon = '󰉶' } },
},
},
icons = {
rules = {
{ pattern = 'explorer', icon = '󰙅' },
{ pattern = 'explorer', icon = '󰙅', color = colors.explorer },
{ pattern = 'lazygit', icon = '' },
{ pattern = 'comment', icon = '' },
{ pattern = 'buffer', color = colors.buffer },
{
pattern = 'notification',
icon = '󰈸',
color = colors.notifications,
},
{ pattern = 'message', icon = '󰈸', color = colors.notifications },
{ pattern = 'session', icon = '', color = colors.sessions },
{
pattern = 'diagnostic',
icon = icons.diagnostics.Info,
hl = 'DiagnosticInfo',
},
{
pattern = 'error',
icon = icons.diagnostics.Error,
hl = 'DiagnosticError',
},
{
pattern = ' warning',
icon = icons.diagnostics.Warning,
hl = 'DiagnosticWarn',
},
},
},
})

View file

@ -2,31 +2,35 @@ return {
'bufferline.nvim',
event = 'DeferredUIEnter',
keys = {
{ '<LEADER>bp', '<CMD>BufferLineTogglePin<CR>', desc = 'Toggle pin' },
{
'<LEADER>bp',
'<CMD>BufferLineTogglePin<CR>',
desc = 'toggle buffer pin',
},
{
'<LEADER>bP',
'<CMD>BufferLineGroupClose ungrouped<CR>',
desc = 'Delete non-pinned buffers',
desc = 'delete non-pinned buffers',
},
{
'<LEADER>br',
'<CMD>BufferLineCloseRight<CR>',
desc = 'Delete buffers to the right',
desc = 'delete buffers to the right',
},
{
'<LEADER>bl',
'<CMD>BufferLineCloseLeft<CR>',
desc = 'Delete buffers to the left',
desc = 'delete buffers to the left',
},
{ '<S-H>', '<CMD>BufferLineCyclePrev<CR>', desc = 'Previous buffer' },
{ '<S-L>', '<CMD>BufferLineCycleNext<CR>', desc = 'Next buffer' },
{ '[b', '<CMD>BufferLineCyclePrev<CR>', desc = 'Previous buffer' },
{ ']b', '<CMD>BufferLineCycleNext<CR>', desc = 'Next buffer' },
{ '[B', '<CMD>BufferLineMovePrev<CR>', desc = 'Move buffer left' },
{ ']B', '<CMD>BufferLineMoveNext<CR>', desc = 'Move buffer right' },
{ '<S-H>', '<CMD>BufferLineCyclePrev<CR>', desc = 'previous buffer' },
{ '<S-L>', '<CMD>BufferLineCycleNext<CR>', desc = 'next buffer' },
{ '[b', '<CMD>BufferLineCyclePrev<CR>', desc = 'previous buffer' },
{ ']b', '<CMD>BufferLineCycleNext<CR>', desc = 'next buffer' },
{ '[B', '<CMD>BufferLineMovePrev<CR>', desc = 'move buffer left' },
{ ']B', '<CMD>BufferLineMoveNext<CR>', desc = 'move buffer right' },
},
before = function()
require('lz.n').trigger_load('mini.icons')
require('lz.n').trigger_load({ 'mini.icons', 'which-key.nvim' })
if vim.g.colors_name == 'rose-pine' then
require('lz.n').trigger_load('rose-pine')
@ -85,5 +89,21 @@ return {
end)
end,
})
local colors = require('colors')
local mkKey = MarleyVim.wkSpec(colors.buffers)
require('which-key').add({
mkKey('<LEADER>bp', ''),
mkKey('<LEADER>bP', '󰐄'),
mkKey('<LEADER>br', ''),
mkKey('<LEADER>bl', ''),
mkKey('<S-H>', ''),
mkKey('<S-L>', ''),
mkKey('[b', ''),
mkKey(']b', ''),
mkKey('[B', ''),
mkKey(']B', ''),
})
end,
}

View file

@ -2,49 +2,49 @@ return {
'noice.nvim',
event = 'DeferredUIEnter',
keys = {
{ '<LEADER>nn', '', desc = '+notifications' },
{ '<LEADER>n', '', desc = '+notifications' },
{
'<S-ENTER>',
function()
require('noice').redirect(vim.fn.getcmdline())
end,
mode = 'c',
desc = 'Redirect cmdline',
desc = 'redirect cmdline',
},
{
'<LEADER>nl',
function()
require('noice').cmd('last')
end,
desc = 'Last message',
desc = 'last message',
},
{
'<LEADER>nh',
function()
require('noice').cmd('history')
end,
desc = 'Message history',
desc = 'message history',
},
{
'<LEADER>na',
function()
require('noice').cmd('all')
end,
desc = 'All messages',
desc = 'all messages',
},
{
'<LEADER>nd',
function()
require('noice').cmd('dismiss')
end,
desc = 'Dismiss all',
desc = 'dismiss all',
},
{
'<LEADER>nt',
function()
require('noice').cmd('pick')
end,
desc = 'Message picker',
desc = 'message picker',
},
{
'<C-f>',
@ -56,7 +56,7 @@ return {
mode = { 'i', 'n', 's' },
silent = true,
expr = true,
desc = 'Scroll forward',
desc = 'scroll forward',
},
{
'<C-b>',
@ -68,11 +68,11 @@ return {
mode = { 'i', 'n', 's' },
silent = true,
expr = true,
desc = 'Scroll backward',
desc = 'scroll backward',
},
},
before = function()
require('lz.n').trigger_load('nui.nvim')
require('lz.n').trigger_load({ 'nui.nvim', 'which-key.nvim' })
end,
after = function()
require('noice').setup({
@ -102,5 +102,12 @@ return {
lsp_doc_border = true,
},
})
local mkKey = MarleyVim.wkSpec(require('colors').notifications)
require('which-key').add({
mkKey('<S-ENTER>', '', { mode = 'c' }),
mkKey('<C-f>', '', { mode = { 'i', 'n', 's' } }),
mkKey('<C-b>', '', { mode = { 'i', 'n', 's' } }),
})
end,
}

View file

@ -26,16 +26,16 @@ vim.print = _G.dd
set({ 'n' }, '<LEADER>un', function()
Snacks.notifier.hide()
end, { desc = 'Dismiss all notifications' })
end, { desc = 'dismiss all notifications' })
-- Buffers -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
set({ 'n' }, '<LEADER>bd', function()
Snacks.bufdelete()
end, { desc = 'Delete buffer' })
end, { desc = 'delete buffer' })
set({ 'n' }, '<LEADER>bo', function()
Snacks.bufdelete.other()
end, { desc = 'Delete other buffers' })
end, { desc = 'delete other buffers' })
-- Toggles -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
@ -69,11 +69,11 @@ end
set({ 'n' }, '<LEADER>gb', function()
Snacks.git.blame_line()
end, { desc = 'Git blame line' })
end, { desc = 'git blame line' })
set({ 'n' }, '<LEADER>gB', function()
Snacks.gitbrowse()
end, { desc = 'Git browse (open)' })
end, { desc = 'git browse (open)' })
set({ 'n' }, '<LEADER>gY', function()
Snacks.gitbrowse({
@ -81,14 +81,14 @@ set({ 'n' }, '<LEADER>gY', function()
vim.fn.setreg('+', url)
end,
})
end, { desc = 'Git browse (copy)' })
end, { desc = 'git browse (copy)' })
-- LazyGit -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
if vim.fn.executable('lazygit') == 1 then
set({ 'n' }, '<LEADER>gg', function()
Snacks.lazygit({ cwd = MarleyVim.root() })
end, { desc = 'Lazygit (root dir)' })
end, { desc = 'lazygit (root dir)' })
-- set({ 'n' }, '<LEADER>gG', function()
-- Snacks.lazygit()
@ -96,7 +96,7 @@ if vim.fn.executable('lazygit') == 1 then
set({ 'n' }, '<LEADER>gf', function()
Snacks.lazygit.log_file()
end, { desc = 'Lazygit current file history' })
end, { desc = 'lazygit current file history' })
set({ 'n' }, '<LEADER>gl', function()
Snacks.lazygit.log({ cwd = MarleyVim.root() })