Skip to content

Commit 86a0579

Browse files
authored
make autocmds for whitespace highlights/deletion buffer-specific (#168)
fixes #127
1 parent 029f35c commit 86a0579

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

plugin/better-whitespace.vim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ endfunction
345345
function! <SID>SetupAutoCommands()
346346
augroup better_whitespace
347347
" Reset all auto commands in group
348-
autocmd!
348+
autocmd! * <buffer>
349349

350350
if <SID>ShouldHighlight()
351351
if s:better_whitespace_initialized == 0
@@ -354,19 +354,19 @@ function! <SID>SetupAutoCommands()
354354

355355
" Highlight extraneous whitespace at the end of lines, but not the current line in insert mode.
356356
call <SID>HighlightEOLWhitespace()
357-
autocmd CursorMovedI,InsertEnter * call <SID>HighlightEOLWhitespaceExceptCurrentLine()
358-
autocmd InsertLeave,BufReadPost * call <SID>HighlightEOLWhitespace()
357+
autocmd CursorMovedI,InsertEnter <buffer> call <SID>HighlightEOLWhitespaceExceptCurrentLine()
358+
autocmd InsertLeave,BufReadPost <buffer> call <SID>HighlightEOLWhitespace()
359359

360360
if g:current_line_whitespace_disabled_soft == 0
361361
" Using syntax: clear whitespace highlighting when leaving buffer
362-
autocmd BufWinLeave * if expand("<afile>") == expand("%") | call <SID>ClearHighlighting() | endif
362+
autocmd BufWinLeave <buffer> if expand("<afile>") == expand("%") | call <SID>ClearHighlighting() | endif
363363

364364
" Do not highlight whitespace on current line in insert mode
365-
autocmd CursorMovedI * call <SID>HighlightEOLWhitespaceExceptCurrentLine()
365+
autocmd CursorMovedI <buffer> call <SID>HighlightEOLWhitespaceExceptCurrentLine()
366366

367367
" Do not highlight whitespace on current line in normal mode?
368368
if g:current_line_whitespace_disabled_hard == 1
369-
autocmd CursorMoved * call <SID>HighlightEOLWhitespaceExceptCurrentLine()
369+
autocmd CursorMoved <buffer> call <SID>HighlightEOLWhitespaceExceptCurrentLine()
370370
endif
371371
endif
372372

@@ -377,7 +377,7 @@ function! <SID>SetupAutoCommands()
377377

378378
" Strip whitespace on save if enabled.
379379
if <SID>ShouldStripWhitespaceOnSave()
380-
autocmd BufWritePre * call <SID>StripWhitespaceOnSave(v:cmdbang)
380+
autocmd BufWritePre <buffer> call <SID>StripWhitespaceOnSave(v:cmdbang)
381381
endif
382382

383383
augroup END

0 commit comments

Comments
 (0)