sayth
sayth

Reputation: 7048

How is the best way to set changing colorscheme to a keybinding

How is the best way to set changing colorscheme to a keybinding?

Sometimes I find myself needing to change scheme due day and light conditions where a dark scheme doesn't suit.

So by default my colorscheme is seoul256. I thought that I could create an if statement in vimscript bound to d to flip the schemes.

So I created a variable cs = 0 which will default to my darkscheme and on keybinding it will set cs =1 which would cause the light scheme to execute.

However vimmscript doesn't like my variables and am unsure how to reload it after key press.

this is my attempt so far.

 map <space>d cs = 1
 cs = 0
 if cs = 0
     colorscheme seoul256
 else
     colorscheme calmar256-light
 endif

Upvotes: 1

Views: 536

Answers (1)

FDinoff
FDinoff

Reputation: 31439

You can use g:colors_names to get the name of the current color scheme. Then you can compare it to one of the color scheme names and choose the other if it matches.

nnoremap <silent> <space>d :exec 'colorscheme' (g:colors_name ==# 'seoul256') ? 'calmar256-light' : 'seoul256'<CR>

As for why yours doesn't work. You need to use let to assign variables. And you can resource a vim script file with source <filename>

Upvotes: 1

Related Questions