1

I'd like to have a colorscheme but keeping my terminal color as a background color. This code achieved that

colorscheme MyFavoriteOne
autocmd ColorScheme * highlight Normal ctermbg=NONE guibg=NONE

I'd also like to have a different colorscheme for different filetype. By itself, this also works :

autocmd Filetype txt colorscheme NiceTheme

The problem is that now for .txt files my background is not my terminal background no more (even if permute the code lines above). Is there a solution?

  • 1
    See :h autocmd-nested – Matt Oct 16 '19 at 13:44
  • Also note that colorscheme is global, so if you open a txt and then a different file, it will still keep using NiceTheme and not go back to the other default theme. It's not really possible to have actual colorschemes per file, since you can be editing two different file types in split windows and you can't have a different colorscheme for each of them... – filbranden Oct 17 '19 at 5:25
  • Yes you are right. Still not perfect, but to get closer to what I want to achieve to would be better : autocmd BufEnter *.txt ++nested colorscheme NiceTheme – Chickpioupiou Oct 18 '19 at 11:37
2

Change your FileType autocommand to

autocmd Filetype txt ++nested colorscheme NiceTheme

to allow for nesting (by default, they do not nest).

See :h autocmd-nested (and thanks to Matt for the tip).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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