Why is my vim colorscheme changing when I change buffers

前端 未结 2 1576
别那么骄傲
别那么骄傲 2020-12-12 01:37

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

相关标签:
2条回答
  • 2020-12-12 02:08

    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.

    0 讨论(0)
  • 2020-12-12 02:16

    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
    
    0 讨论(0)
提交回复
热议问题