问题描述
我在某些文件类型上有一些首选的配色方案,但是当我打开另一个文件(具有不同配色方案的不同文件类型)并返回上一个文件时,新的配色方案仍然存在.
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.
我的 Gvimrc 中有这个(使用 gvim)
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 ?
添加以下内容没有修复
autocmd BufEnter,BufNew,FileType c,cpp colorscheme darkblue
autocmd BufEnter,BufNew,FileType R,r colorscheme desert
推荐答案
将 WinEnter
和 FileType
事件组合在同一个 autocmd 规则中是没有意义的;第一个匹配缓冲区的文件名,而后者匹配缓冲区的文件类型.
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.
相反,每当缓冲区被输入/显示在窗口中时,使用一个单独的 autocmd 触发,并选择带有 &filetype
条件的 colorschmeme.
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
这篇关于为什么当我改变缓冲区时我的 vim 颜色方案会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!