所以,几年来我的 vimrc 中有以下块:
" This toggles the hilighting of trailing-whitespace.
fun! ToggleExtraWhitespace()
if exists('b:ews') && b:ews == 1
"echom "Disabling trailing-whitespace hilighting in" bufnr('%') "..."
let b:ews=0
call HighlightExtraWhitespace()
"echom "-- Removing ExtraWhitespace augroup"
au! ExtraWhitespace
augroup! ExtraWhitespace
else
"echom "Enabling trailing-whitespace hilighting in" bufnr('%') "..."
let b:ews=1
call HighlightExtraWhitespace()
"echom "-- Adding ExtraWhitespace augroup"
augroup ExtraWhitespace
au!
au BufEnter * match ExtraWhitespace /\s\+$/
au InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
au InsertLeave * match ExtraWhiteSpace /\s\+$/
augroup END
if mode() == "i" | do ExtraWhitespace InsertEnter | else | do ExtraWhitespace BufEnter | endif
endif
endfun
" This adds (or removes) the actual hilighting to your ColourScheme. (It's must be re-called every
" time you toggle hilighting, or change your scheme.)
fun! HighlightExtraWhitespace()
if exists('b:ews') && b:ews == 1
"echom "-- Adding ExtraWhitespace hilighting"
highlight ExtraWhitespace ctermbg=red guibg=red
else
"echom "-- Removing ExtraWhitespace hilighting"
highlight clear ExtraWhitespace
endif
endfun
au ColorScheme * call HighlightExtraWhitespace()
" (Uncomment the following line if you want trailing-whitespace hilighted by default!)
bufdo call ToggleExtraWhitespace() | au BufAdd * call ToggleExtraWhitespace()
但是,我刚刚意识到,这会阻止我在一个命令行命令中打开多个文件(我通常在vim 中进行浏览,因此我花了这么长时间才注意到!):nvim -o lib/ocameel.ml bin/cli.ml
打开两个cli.ml
包含,的缓冲区并且没有lib/ocameel.ml
根本不开门!
如果我注释掉最后一行,一切正常;我仍然可以手动调用:call ToggleExtraWhitespace()
,而且一切都很好。
不过,我真的很想弄清楚为什么添加该自动命令会破坏 vim-entry。我的 BufAdd 搞砸了什么?D: