How to override the colors of NeoSolarized in NeoVim

xxxuutaxxx

uuta

Posted on April 21, 2024

How to override the colors of NeoSolarized in NeoVim

Recently, I’d like to alter a theme with a new one in NeoVim. The onedarkpro is a fantastic theme that I’ve used for a long time, but it’s difficult to defeat the temptation to try out another theme like NeoSolarized.

https://user-images.githubusercontent.com/70003855/235333907-c064208a-3975-404d-874b-58e5c52ee5f0.png

First, I installed NeoSolarized.nvim via lazy.nvim, so the code would be simple like the following one.

return {
    {
        "Tsuzat/NeoSolarized.nvim",
        config = function()
            local neosolarized = require('NeoSolarized')
            neosolarized.setup {
                transparent = true,
            }
        end
    }
}

Enter fullscreen mode Exit fullscreen mode

But I wanted to customize it more.

Image description

There was no explicit description in README to modify styles, but referring theme.lua in NeoSolarized, colors can be overridden.

return {
    {
        "Tsuzat/NeoSolarized.nvim",
        config = function()
            -- https://github.com/Tsuzat/NeoSolarized.nvim/blob/208e65a3ede945b8a1d00104a4441217c5e23509/lua/NeoSolarized/theme.lua#L1-L11
            local neosolarized = require('NeoSolarized')
            local cls = require("NeoSolarized.colors")
            local config = require("NeoSolarized.config")
            local options = config.options
            local theme = {config = options, colors = cls.setup()}

            local c = theme.colors
            c.green = '#40f7d2'
            c.yellow = '#eaea8a'
            c.red = '#ea4481'
            c.blue = '#2bb3d8'
            c.fg0 = '#dde8d5'
            c.orange = '#dd9f4d'
            neosolarized.setup {
                transparent = true,
                -- https://github.com/Tsuzat/NeoSolarized.nvim/blob/208e65a3ede945b8a1d00104a4441217c5e23509/lua/NeoSolarized/theme.lua#L748
                styles = {
                    comments = {italic = false},
                    keywords = {italic = false, bold = true},
                    string = {italic = false}
                },
                on_highlights = function(highlights, colors)
                    -- highlights.Include.fg = colors.red -- Using `red` foreground for Includes
                end
            }
        end
    }
}
Enter fullscreen mode Exit fullscreen mode

Image description

💖 💪 🙅 🚩
xxxuutaxxx
uuta

Posted on April 21, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related