-- Quick command checker for Neovim -- Run with: :luafile check-commands.lua -- Or add to your config as a command local M = {} function M.list_all_commands() local commands = vim.api.nvim_get_commands({}) local sorted = {} for name, cmd in pairs(commands) do table.insert(sorted, name) end table.sort(sorted) print("=" .. string.rep("=", 60)) print("REGISTERED COMMANDS (" .. #sorted .. " total)") print("=" .. string.rep("=", 60)) for _, name in ipairs(sorted) do print(name) end end function M.check_conflicts() local commands = vim.api.nvim_get_commands({}) local seen = {} local conflicts = {} for name, cmd in pairs(commands) do if seen[name] then if not conflicts[name] then conflicts[name] = {seen[name], cmd} else table.insert(conflicts[name], cmd) end else seen[name] = cmd end end if next(conflicts) then print("⚠️ CONFLICTS FOUND:") for name, defs in pairs(conflicts) do print(" " .. name .. ":") for i, def in ipairs(defs) do print(" " .. i .. ". " .. (def.definition or "unknown")) end end else print("✓ No conflicts detected!") end end function M.find_command(pattern) local commands = vim.api.nvim_get_commands({}) local matches = {} for name, cmd in pairs(commands) do if name:match(pattern) then table.insert(matches, {name = name, cmd = cmd}) end end table.sort(matches, function(a, b) return a.name < b.name end) if #matches > 0 then print("Commands matching '" .. pattern .. "':") for _, item in ipairs(matches) do print(" " .. item.name) end else print("No commands found matching '" .. pattern .. "'") end end -- Create user commands vim.api.nvim_create_user_command("ListCommands", function() M.list_all_commands() end, { desc = "List all registered commands" }) vim.api.nvim_create_user_command("CheckCommandConflicts", function() M.check_conflicts() end, { desc = "Check for command conflicts" }) vim.api.nvim_create_user_command("FindCommand", function(opts) M.find_command(opts.args) end, { desc = "Find commands matching pattern", nargs = 1 }) print("Commands registered:") print(" :ListCommands - List all commands") print(" :CheckCommandConflicts - Check for conflicts") print(" :FindCommand - Find commands by pattern") return M