vim - 使不活动的拆分窗格变暗 [英] vim - dim inactive split panes

查看:34
本文介绍了vim - 使不活动的拆分窗格变暗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您熟悉 iTerm2 应用程序,您就会知道可以像 vim 一样拆分视图,将不活动的视图变暗".

If you're familiar with the iTerm2 application, you'll know that you can split views similar to vim, and the inactive views are "dimmed."

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

I usually work in vim with three vertical split views and it would be nice to dim the inactive ones by setting the background color to a darker tone, for example.

有没有办法做到这一点?

Is there a way to do this?

推荐答案

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

I have come up with the following solution (using 'colorcolumn' and unsetting '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

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

View it at my (current) dotfiles: https://github.com/blueyed/dotfiles/blob/master/vimrc#L351

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

Update I have created a plugin out of it: https://github.com/blueyed/vim-diminactive

这篇关于vim - 使不活动的拆分窗格变暗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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