How To Edit A Colorbuddy Based Color theme For Neovim

If I am going to spend eight or ten hours inside vim every day, it may as well be nice, right?

To that end, I like to play around with my color themes.

I recently started using a colorbuddy based color theme. Colorbuddy is a Neovim theme framework. You can use it create color themes with lua.

Maybe you are not interested in creating a theme. Neither am I. But you can edit an existing theme.

In this example, I will be editing my color theme for markdown files. Here is how:

Disable Treesitter

The first thing you need to do is disable Treesitter for markdown files:

require 'nvim-treesitter.configs'.setup {
  ensure_installed = {
    other configs here
    highlight {
      enable = true,
      disable = {'markdown'}
    }
  }
}

If you do not disable Treesitter for markdown, none of the changes you make for markdown will take effect.

Change highlight groups, change colors

Text in Neovim are objects. All objects are a part of a color group. These color groups are called highlight groups.

For example, the H1 header text in a markdown file is in the markdownH1 highlight group.

If you know the name of a highlight group, you can change the color of the object.

Prior to Neovim v0.9, there wasn’t an easy way to discover the name of the highlight group.

I suggest upgrading to 0.9. To discover the name of the highlight group in 0.9, put your cursor over the text object and type :Inspect.

Find the color theme you want to change on mac

Color themes are stored in .local/share/nvim/site/pack/packer/start/ (Mac M1)

Find the theme plugin folder and look for the .lua file.

Add a new color with Colorbuddy

Using the neosolarized.lua theme as an example, I added a new color:

Color.new('lightBlue', '#ADD8E6')

Assign the color to the highlight group

I changed the H2 headline color for markdown.

Group.new('markdownH2', colors.lightBlue, nil, opts)

Now the H2 headline for all markdown files is #ADD8E6

That’s it. Bye for now.