Einenlum.

How to preview colorschemes in Neovim

Thu Jul 06 2023

I know that telescope is a very popular fuzzy finder in the Neovim world. The fact that it was built by the main core maintainer of Neovim probably plays a role.

It’s well thought but I have to say I prefer a less-known alternative: fzf-lua. It adds some dependencies (like fzf which is mandatory or a few optional ones like bat and ripgrep) but since I already use all of them daily, it’s not a problem for me. I experienced fzf-lua to be way faster than telescope.

Another super important feature for me is the ability to preview colorschemes (which is not possible in telescope).

To do so, just launch :FzfLua colorschemes or bind it to a key.

In my Lua config, I mapped it to Ctrl J:

local map = vim.api.nvim_set_keymap

map("n", "<C-j>", "<Esc>:FzfLua colorschemes<CR>", {})

-- other cool features
-- map("n", "<C-p>", "<Esc>:FzfLua files<CR>", {})
-- map("n", "<C-o>", "<Esc>:FzfLua buffers<CR>", {})
-- map("n", "<C-h>", "<Esc>:FzfLua command_history<CR>", {})
-- map("n", "<C-w>", "<Esc>:FzfLua builtin<CR>", {})
-- map("n", "<Leader>f", "<Esc>:FzfLua live_grep_native<CR>", {})

Now when using Ctrl J, I get a preview of all my colorschemes.

The catpuccin theme
The everforest theme

If I press enter, the colorscheme is applied, of course. If I press ESC it applies my previous colorscheme back. You can now have a colorscheme preview feature as you would have in VS Code and other tools.

How to exclude some colorschemes from the list

Everything works perfectly, but Neovim installs a few ugly colorschemes by default, which means I have them in the list and I don’t want to stumble upon them.

ibhagwan, the creator of fzf-lua implemented a way to exclude some colorschemes from the list, only a few hours after I asked about it (!). Another reason to love this plugin.

Here is what I added to my lua config:

require('fzf-lua').setup{
  colorschemes = {
    ignore_patterns = {
        "^blue$",
        "^darkblue$",
        "^default$",
        "^delek$",
        "^desert$",
        "^elflord$",
        "^evening$",
        "^habamax$",
        "^industry$",
        "^koehler$",
        "^lunaperche$",
        "^morning$",
        "^murphy$",
        "^pablo$",
        "^peachpuff$",
        "^quiet$",
        "^ron$",
        "^shine$",
        "^slate$",
        "^torte$",
        "^zellner$",
    }
  }
}

This requires the 758d4ddb2a94 commit that appeared on July, 5th 2023. Think about updating your plugin.