1

I'm trying to write a lua command that writes the current colorscheme out to a file. I can't seem to find a command that actually returns the name of the current colorscheme in lua, only one that prints that colorscheme to the command line.

Basically what i want is something like this;

local CurrentColor = vim.cmd.colorscheme()
-- ^^^ this doesn't work because vim.cmd.x returns nothing into lua env

except that it actually works.

I have been grepping around the helpfiles for the lua api, but so far I have found nothing helpful.

1

1 Answer 1

2

The name of the color scheme will be stored in global variable colors_name (see :help g:colors_name), though it is possible that this variable will be unset when no colorscheme was explicitly loaded and the default is in use.

As such, you can get the name of the color scheme in Lua with the following expression:

local CurrentColor = vim.g.colors_name or 'default'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.