vimluaneovim

Neovim - Conditional colorschemes


The Objective

I want to set a specific config for a plugin if a certain colorscheme is applied at startup.

What I tried

If vim.cmd("colorscheme") == "oxocarbon" then
    print("this is oxocarbon")
else
    print("this isn't oxocarbon")
end

The problem

Everytime I open neovim the theme oxocarbon loads, but the return is "this isn't oxocarbon".

Minimal config - init.lua

require('lazy').setup({
{ import = "plugins.core" } -- oxocarbon get installed and loaded
})
require("macros") -- the if statement 

Note

After VimEnter, when I type the command :lua vim.cmd("colorscheme") (or simply :colorscheme), it returns "oxocarbon" (Which is the configured theme loaded during VimEnter)


Solution

  • Just to give you one idea, here it is how I set my colors:

    local colorscheme = "tokyonight"
    -- vim.notify("Selected colorscheme: " .. colorscheme) -- Debugging message
    
    -- local colorscheme = "tokyonight"
    local status_ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme)
    if not status_ok then
      vim.notify("colorscheme " .. colorscheme .. " not found!")
      return
    end