Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

color scheme - Why is my vim colorscheme changing when I change buffers

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 colorscheme persists.

I have this in my Gvimrc (using gvim)

autocmd WinEnter,FileType * colorscheme default
autocmd WinEnter,FileType c,cpp colorscheme darkblue
autocmd WinEnter,FileType R,r colorscheme desert

How can I modify to make sure that colorscheme persists according to filetype when I navigate across buffers ?

EDIT: adding the following did not fix

autocmd BufEnter,BufNew,FileType c,cpp colorscheme darkblue
autocmd BufEnter,BufNew,FileType R,r colorscheme desert
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...