如何在 vim 中更改当前缓冲区或窗格的背景颜色? [英] How do I change the background color of current buffer or pane in vim?

查看:31
本文介绍了如何在 vim 中更改当前缓冲区或窗格的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我正在编码,并且打开了不同的拆分窗格.当我从一个缓冲区/窗格切换到另一个缓冲区/窗格时,我应该将哪些设置传递给 vimrc 以更改背景颜色?

Imagine I'm coding, and I have different split panes open. What settings should I pass into vimrc to change the background color as I switch from one buffer/pane to another?

我试过了:

autocmd BufEnter * highlight Normal ctermbg=black                                                                                                                                                                                                                              
autocmd BufLeave * highlight Normal ctermbg=white 

我想补充一点,我确定我启用了 256 种颜色

I would like to add that I am sure that I've got 256 colors enabled

推荐答案

实际上, 有一种方法可以获得这种效果.请参阅@blueyed 对此相关问题的回答:vim - 暗淡不活动的拆分窗格.他提供了下面的脚本,当放置在我的 .vimrc 中时,它会使非活动窗口的背景变暗.实际上,它使它们的背景与为 colorcolumn 指定的颜色相同(垂直线表示您想要的文本宽度).

Actually, there is a way to get this effect. See the answer by @blueyed to this related question: vim - dim inactive split panes. He provides the script below and when placed in my .vimrc it does dim the background of inactive windows. In effect, it makes their background the same colour specified for the colorcolumn (the vertical line indicating your desired text width).

" Dim inactive windows using 'colorcolumn' setting
" This tends to slow down redrawing, but is very useful.
" Based on https://groups.google.com/d/msg/vim_use/IJU-Vk-QLJE/xz4hjPjCRBUJ
" XXX: this will only work with lines containing text (i.e. not '~')
" from 
if exists('+colorcolumn')
  function! s:DimInactiveWindows()
    for i in range(1, tabpagewinnr(tabpagenr(), '$'))
      let l:range = ""
      if i != winnr()
        if &wrap
         " HACK: when wrapping lines is enabled, we use the maximum number
         " of columns getting highlighted. This might get calculated by
         " looking for the longest visible line and using a multiple of
         " winwidth().
         let l:width=256 " max
        else
         let l:width=winwidth(i)
        endif
        let l:range = join(range(1, l:width), ',')
      endif
      call setwinvar(i, '&colorcolumn', l:range)
    endfor
  endfunction
  augroup DimInactiveWindows
    au!
    au WinEnter * call s:DimInactiveWindows()
    au WinEnter * set cursorline
    au WinLeave * set nocursorline
  augroup END
endif

这篇关于如何在 vim 中更改当前缓冲区或窗格的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆