bits 12
I decided I need a random color scheme selector for one of those moments when you don’t know what to do and decide to hit random keys. Lazyvim already has <leader>uC
for selecting the color scheme but it’s too mentally taxing. It asks you to select one. This just switches to a random one.
RandomColorScheme
just spits the name of a random color scheme after searching it in all paths. SetRandomColorScheme
sets the color scheme to that. The keybinding is <leader>uR
.
function RandomColorScheme()
local color_schemes = vim.fn.globpath(vim.o.rtp, "colors/*.vim", false, true)
for i, fullpath in ipairs(color_schemes) do
color_schemes[i] = fullpath:match(".*/(.*).vim$")
end
-- Generate a random index
local index = math.random(#color_schemes)
local random_color_scheme = color_schemes[index]
vim.notify("Random Color Scheme: " .. random_color_scheme)
-- Select a random color scheme
return random_color_scheme
end
function SetRandomColorScheme()
vim.cmd("colorscheme " .. RandomColorScheme())
end
vim.api.nvim_set_keymap("n", "<leader>uR", ":lua SetRandomColorScheme()<CR>", { noremap = true, silent = true })