I have some prefered colorscheme on some filetypes, but when I open another file (different file type with different colorscheme) and come back on a previous one, the new co
Ingo's answer is smarter but these autocommands
autocmd BufEnter * colorscheme default
autocmd BufEnter *.php colorscheme desert
autocmd BufEnter *.py colorscheme darkblue
should work. Well, they work, here.
It does not make sense to combine WinEnter
and FileType
events in the same autocmd rule; the first matches against the buffer's filename while the latter matches against the buffer's filetype.
Instead, use a single autocmd triggered whenever a buffer is entered / displayed in a window, and choose the colorschmeme with a conditional on the &filetype
.
:autocmd BufEnter,FileType *
\ if &ft ==# 'c' || &ft ==# 'cpp' | colorscheme darkblue |
\ elseif &ft ==? 'r' | colorscheme desert |
\ else | colorscheme default |
\ endif