vim - 昏暗的非活动分割窗格

21 vim iterm2

如果您熟悉iTerm2应用程序,您就会知道可以拆分类似于vim的视图,并且非活动视图会"变暗".

我通常使用三个垂直分割视图在vim中工作,例如,通过将背景颜色设置为较暗的色调来调暗非活动的视图会很好.

有没有办法做到这一点?

blu*_*yed 19

我提出了以下解决方案(使用'colorcolumn'和取消设置'cursorline'):

" 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 '~')
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
Run Code Online (Sandbox Code Playgroud)

在我的(当前)dotfiles查看它:https://github.com/blueyed/dotfiles/blob/master/vimrc#L351

更新 我已经创建了一个插件:https://github.com/blueyed/vim-diminactive

  • 真棒!非常好. (2认同)

TaD*_*Daa 11

把它作为一个新的答案扔出去。https://github.com/TaDaa/vimade淡出非活动缓冲区,保留语法突出显示,还可以淡化标志。我是作者,但我认为这可能对某些人有用,作为更新的替代方案。支持 nvim 和 vim8、256 色终端、termguicolors 和 gui。

  • 尝试过,喜欢它,使用它。干杯。 (3认同)

Ale*_*lex 5

在 neovim(v0.2.1) 中,以下配置将使非活动窗格变暗:

hi ActiveWindow ctermbg=16 | hi InactiveWindow ctermbg=233
set winhighlight=Normal:ActiveWindow,NormalNC:InactiveWindow
Run Code Online (Sandbox Code Playgroud)