How to Change Neovim Colorscheme On-the-Fly with Themery

(Actualizado el )
Themery social banner.
Themery social banner.
Other languages: Español

I don’t think anyone disputes that Vim is a fantastic text editor with its extensive capabilities. However, there are some essential aspects that have been overlooked, such as the ability to change themes, or colorschemes as they’re called in this program.

The Problem

You see, in Vim and Neovim, all configuration is governed by a file where you specify how you want the editor to behave. Of course, the appearance of the editor is no exception. The problem with this setup is that if you want to change the colorscheme, you’ll have to enter your configuration file, locate the theme section (if you don’t have a specific one), make the changes, and restart to apply them. This is impractical if you need to change it frequently in your daily workflow.

Another option is to change the theme using the :colorscheme example command. Although this is more instantaneous, it has some drawbacks. First, the changes are temporary and are lost when Neovim is closed. You have to remember the theme name you want to switch to, and most importantly, many colorschemes rely on variables.

If we look at the instructions for using a colorscheme like the popular gruvbox, we can see the following in the documentation:

vim.o.background = "dark" -- or "light" for light mode
vim.cmd([[colorscheme gruvbox]])

Wow! In addition to calling the colorscheme, we need to set a variable. At this point, simply using the :colorscheme command becomes less viable. Most of these schemes have dozens of lines of customization, making it mandatory to resort to the configuration file.

Themery to the Rescue

Themery.nvim is a highly configurable plugin for Neovim that adds the ability to display a menu with a list of all configured themes, allowing you to switch between them quickly. Not only that, but it also lets you preview each theme in real-time without applying it, similar to how it works in Vs Code.

Themery demo

Its features include:

  • Persistent Choice: You can select a colorscheme, and it will be saved for the next time you start Neovim.
  • Customization: You can customize which elements to display in the list and their order.
  • Intelligent: You can define code that will be executed before and after setting the colorscheme in case you need to set some variables or do something else.
  • Lightweight: It only runs when invoked. In other words, setting the colorscheme is handled by Neovim on startup.

You can find complete installation and configuration information on the Themery repository.

Sources