Skip to content

Instantly share code, notes, and snippets.

@mikeslattery
Last active March 18, 2024 14:18
Show Gist options
  • Save mikeslattery/1c116c8fb8e812c7b0f70558194db4e1 to your computer and use it in GitHub Desktop.
Save mikeslattery/1c116c8fb8e812c7b0f70558194db4e1 to your computer and use it in GitHub Desktop.
which_key.nvim extension to limit how many marks are shown.
local M = {}
--
-- $HOME/.config/nvim/lua/which-key/plugins/briefmarks.lua
--
-- This extends which-key/plugins/marks.lua with these changes:
--
-- * Only show subset of marks
-- * Letters
-- * ^ . quote
-- * Do not show duplicate marks
--
-- Configuration:
--
-- require("which-key").setup {
-- plugins = {
-- briefmarks = true,
-- marks = false,
-- ...
local marks_module = require('which-key.plugins.marks')
M.name = "briefmarks"
M.actions = marks_module.actions
function M.setup(_wk, _config, options) end
M.allowed_marks = { "^", ".", "'"}
---@type Plugin
---@return PluginItem[]
function M.run(_trigger, _mode, buf)
local marks = marks_module.run(_trigger, _mode, buf)
local unique_values = {}
for i = #marks, 1, -1 do
local key = marks[i].key
local value = marks[i].value
if (key:match("^%a$") or vim.tbl_contains(M.allowed_marks, key))
and not unique_values[value] then
-- mark is allowed, but don't let duplicates later
unique_values[value] = true
else
-- Remove non-unique marks or unsupported marks
table.remove(marks, i)
end
end
return marks
end
return M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment