vim - 使不活动的拆分 Pane 变暗

标签 vim iterm2

如果您熟悉 iTerm2 应用程序,您就会知道您可以像 vim 一样 Split View,并且不活动的 View 会“变暗”。

我通常在 vim 中使用三个垂直 Split View,例如,通过将背景颜色设置为较暗的色调来使不活动的 View 变暗会很好。

有没有办法做到这一点?

最佳答案

我想出了以下解决方案(使用'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

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

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

关于vim - 使不活动的拆分 Pane 变暗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8415828/

相关文章:

VIM iTerm SSH : Cant' copy paste

Vim 对象选择与语法感知文本对象

vim - 为什么\r\n在vi中显示为^M?

vim - 设置 mouse=a 在 iTerm2 中的 Vim/Neovim 上不起作用

applescript - 如何在applescript中将文本写入iterm2 session ?

applescript - iTerm applescript 在两个单独的垂直 Pane 中写入

ssh - 'xterm-新': unknown terminal type

VIM - 如何用复制寄存器的内容替换一行?

vim - Vim 中 FZF 最新文件的工作解决方案?

vim - 为什么 Y 和 yy 做同样的事情?