Why does my `au bufadd` prevent Vim from opening multiple files?

81 views Asked by At

So, I've had the following chunk in my vimrc for a few years:

" 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()

I've just realised, however, that this prevents me from opening multiple files in one command-line command (I usually do my browsing inside vim, hence why it took me so long to notice!): nvim -o lib/ocameel.ml bin/cli.ml opens two buffers containing cli.ml, and doesn't open lib/ocameel.ml at all!

If I comment out the last line, everything works fine; I can still manually invoke :call ToggleExtraWhitespace(), and everything's hunky-dory.

I'd really like to figure out, though, why adding that autocommand breaks vim-entry. What's my BufAdd screwing up? D:

0

There are 0 answers