2

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?

3
  • 2
    See :h autocmd-nested
    – Matt
    Oct 16, 2019 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, 2019 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 Oct 18, 2019 at 11:37

1 Answer 1

3

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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