Jonathan
Jonathan

Reputation: 539

Why doesn't sourcing g:colors_name work in vim?

I'm trying to make an autocmd that reloads the current color scheme whenever I switch buffers. At the moment I have autocmd BufEnter * source '~/.vim/colors/' . g:colors_name . '.vim' and it's not working. I get E185 can't find color scheme g:colors_name. Echoing g:colors_name brings up the name of the color scheme, and since that's the same as the filename, it should just be a matter of appending the path and extension, but something's not right here. What am I doing wrong?

Upvotes: 1

Views: 645

Answers (1)

romainl
romainl

Reputation: 196606

-- edit --

Your problem is that the variable is not expanded. Use this command instead:

autocmd BufEnter * execute "source ~/.vim/colors/" . g:colors_name . ".vim"

-- edit --

Anyway, why don't you simply do colorscheme " . g:colors_name?

When working on my colorschemes, I just do :w | color apprentice and repeat with the <Up> arrow.

Upvotes: 3

Related Questions