Home

Awesome

🌈 colorbox.nvim

<p> <a href="https://github.com/neovim/neovim/releases/v0.9.0"><img alt="require" src="https://img.shields.io/badge/require-0.9%2B-blue" /></a> <a href="https://github.com/linrongbin16/commons.nvim"><img alt="commons.nvim" src="https://img.shields.io/badge/power_by-commons.nvim-pink" /></a> <a href="https://luarocks.org/modules/linrongbin16/colorbox.nvim"><img alt="luarocks" src="https://img.shields.io/luarocks/v/linrongbin16/colorbox.nvim" /></a> <a href="https://github.com/linrongbin16/colorbox.nvim/actions/workflows/ci.yml"><img alt="ci.yml" src="https://img.shields.io/github/actions/workflow/status/linrongbin16/colorbox.nvim/ci.yml?label=ci" /></a> <a href="https://github.com/linrongbin16/colorbox.nvim/actions/workflows/collect.yml"><img alt="collect.yml" src="https://img.shields.io/github/actions/workflow/status/linrongbin16/colorbox.nvim/collect.yml?label=collect" /></a> <a href="https://app.codecov.io/github/linrongbin16/colorbox.nvim"><img alt="codecov" src="https://img.shields.io/codecov/c/github/linrongbin16/colorbox.nvim/main?label=codecov" /></a> </p>

Do you want all the most popular (Neo)Vim colorschemes than only one? Do you want to change them from time to time?

This is it! Let's load all the ultra colorschemes into Neovim player!

https://github.com/linrongbin16/colorbox.nvim/assets/6496887/8fff55ea-749d-4064-90b8-a3799519898d

<details> <summary><i>Click here to see how to configure</i></summary>
require("colorbox").setup({
  policy = { seconds = 1, implement = "shuffle" },
  timing = "interval",
})
</details>

It uses GitHub actions to weekly collect/update the colorscheme dataset.

[!NOTE]

The most popular colorschemes are picked from below websites:

With below conditions:

  1. GitHub stars ≥ 500 (by default it only enable ≥ 800, see Configuration).
  2. Last git commit is in last 5 years.
  3. For multiple plugins that contain a same color name, it picks by following rules:
    1. The awesome-neovim wins the vimcolorschemes (they usually support modern Neovim features).
    2. More github stars.
    3. Newer git commits.

Please check COLORSCHEMES.md for full colorscheme dataset.

It installs colorschemes via git submodule instead of copy-paste source code, so you get continuously updates from original authors.

It allows you to play them with multiple playback settings(policies):

And multiple trigger timings:

📖 Table of Contents

✅ Requirements

📦 Install

[!IMPORTANT]

If this plugin provides the main colorscheme (i.e. the color show right after nvim start), then make sure:

  1. Don't lazy load it.
  2. Load it before all other plugins.

[!IMPORTANT]

Some colorschemes have specific requirements:

Please manually add these dependencies if you enable them.

<details> <summary><b>With <a href="https://github.com/folke/lazy.nvim">lazy.nvim</a></b></summary>
require('lazy').setup({
  {
    'linrongbin16/colorbox.nvim',

    -- don't lazy load
    lazy = false,
    -- load with highest priority
    priority = 1000,

    build = function() require("colorbox").update() end,
    config = function() require("colorbox").setup() end,
  }
})
</details> <details> <summary><b>With <a href="https://github.com/lewis6991/pckr.nvim">pckr.nvim</a></b></summary>
require('pckr').add({
  {
    'linrongbin16/colorbox.nvim',

    run = function() require("colorbox").update() end,
    config = function() require("colorbox").setup() end,
  };
})
</details>

🎬 How it Works

When loading this plugin, it does below steps:

  1. Runs the filters, only enables the colors you choose from the dataset (see Filter).
  2. Registers the triggers to invoke related policies at a proper timing (see Timing).

When a timing is triggered, it does below steps:

  1. Runs the registered policy and pick a colorscheme (see Policy).
  2. Refreshes the background option (see Background).
  3. Runs the colorscheme command to actually apply the colorscheme.

🚀 Usage

You can use the Colorbox command with below subcommands:

[!NOTE]

You can still use the colorscheme command to change a colorscheme.

🔧 Configuration

To configure options, please use:

require("colorbox").setup(opts)

The opts is an optional lua table that override the default options. Here we only introduce some of the most options.

For complete default options, please see configs.lua.

Filter

The filter option is to help user filter some colorschemes from the dataset, thus they will never show up.

There're 3 kinds of filters:

Timing

The timing option is to configure when to change to next colorscheme.

There're 3 kinds of timings:

Policy

The policy option is to configure how to pick the next colorscheme.

There're 3 kinds of policies (they work with the corresponding timings):

Background

The background option runs set background=dark/light every time before running the colorscheme command (to change a colorscheme).

require("colorbox").setup({
  background = "dark",
})

Some colors (tokyonight-day, rose-pine-dawn, etc) are forced to be light, i.e. they forced the background option to light inside their internal implementations.

This is no problem, except some user may want all those following colorschemes (after tokyonight-day and rose-pine-dawn) go back to dark background if they're dark-able.

Hook

To execute a hook function after policy is triggered and new colorscheme is applied, please use:

require("colorbox").setup({
  post_hook = function(color, spec)
    vim.notify(string.format("Colorscheme changed to: %s", vim.inspect(color)))
  end,
})

The hook accepts a lua function with below signature:

function(color:string, spec:colorbox.ColorSpec):nil

📝 Receipts

Choose fixed color on nvim start

require("colorbox").setup({
  policy = "single",
  timing = "startup",
})

Choose random color on nvim start

require("colorbox").setup({
  policy = "shuffle",
  timing = "startup",
})

Change random color per second

require("colorbox").setup({
  policy = { seconds = 1, implement = "shuffle" },
  timing = "interval",
})

Choose color by file type

require("colorbox").setup({
  timing = "filetype",
  policy = {
    mapping = {
      lua = "PaperColor",
      yaml = "everforest",
      markdown = "kanagawa",
      python = "iceberg",
    },
    empty = "tokyonight",
    fallback = "solarized8",
  },
})

Enable all colors

require("colorbox").setup({
  filter = false,
})

Enable only top stars (≥ 1000) & primary colors

require("colorbox").setup({
  filter = {
    "primary",
    function(color, spec)
      return spec.github_stars >= 1000
    end
  },
})

Disable by name

local function colorname_disabled(colorname)
  for _, c in ipairs({
    "iceberg",
    "ayu",
    "edge",
    "nord",
  }) do
    if string.lower(c) == string.lower(colorname) then
      return true
    end
  end
  return false
end

require("colorbox").setup({
  filter = function(color, spec)
    for _, c in ipairs(spec.color_names) do
      if colorname_disabled(c) then
        return false
      end
    end
    return true
  end
})

Disable by plugin

local function plugin_disabled(spec)
  for _, p in ipairs({
    "cocopon/iceberg.vim",
    "folke/tokyonight.nvim",
    "ayu-theme/ayu-vim",
    "shaunsingh/nord.nvim",
  }) do
    if string.lower(p) == string.lower(spec.handle) then
      return true
    end
  end
  return false
end

require("colorbox").setup({
  filter = function(color, spec)
    return not plugin_disabled(spec)
  end
})

✏️ Development

To develop the project and make PR, please setup with:

To run unit tests, please install below dependencies:

Then test with vusted ./spec.

🎁 Contribute

Please open issue/PR for anything about colorbox.nvim.

Like colorbox.nvim? Consider

Github Sponsor Wechat Pay Alipay