Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Whitespace highlighting is enabled by default, with a highlight color of red.
* If you want this behaviour by default for all filetypes, add the following to your `~/.vimrc`:

```
autocmd BufWritePre * StripWhitespace
autocmd BufEnter * EnableStripWhitespaceOnSave
```

For exceptions of all see ```g:better_whitespace_filetypes_blacklist```.
Expand All @@ -85,7 +85,7 @@ Whitespace highlighting is enabled by default, with a highlight color of red.
the following to your `~/.vimrc`:

```
autocmd FileType <desired_filetypes> autocmd BufWritePre <buffer> StripWhitespace
autocmd FileType <desired_filetypes> autocmd BufEnter <buffer> EnableStripWhitespaceOnSave
```

where `<desired_filetypes>` is a comma separated list of the file types you want
Expand Down
27 changes: 21 additions & 6 deletions plugin/better-whitespace.vim
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,27 @@ function! s:StripWhitespace( line1, line2 )
call cursor(l, c)
endfunction

" Strip whitespace on file save
function! s:EnableStripWhitespaceOnSave()
let g:strip_whitespace_on_save = 1
call <SID>Echo("Strip Whitespace On Save: Enabled")
call <SID>SetupAutoCommands()
endfunction

" Don't strip whitespace on file save
function! s:DisableStripWhitespaceOnSave()
let g:strip_whitespace_on_save = 0
call <SID>Echo("Strip Whitespace On Save: Disabled")
call <SID>SetupAutoCommands()
endfunction

" Strips whitespace on file save
function! s:ToggleStripWhitespaceOnSave()
if g:strip_whitespace_on_save == 0
let g:strip_whitespace_on_save = 1
call <SID>Echo("Strip Whitespace On Save: Enabled")
if g:strip_whitespace_on_save == 1
call <SID>DisableStripWhitespaceOnSave()
else
let g:strip_whitespace_on_save = 0
call <SID>Echo("Strip Whitespace On Save: Disabled")
call <SID>EnableStripWhitespaceOnSave()
endif
call <SID>SetupAutoCommands()
endfunction

" Determines if whitespace highlighting should currently be skipped
Expand All @@ -175,6 +186,10 @@ endfunction

" Run :StripWhitespace to remove end of line whitespace
command! -range=% StripWhitespace call <SID>StripWhitespace( <line1>, <line2> )
" Run :EnableStripWhitespaceOnSave to enable whitespace stripping on save
command! EnableStripWhitespaceOnSave call <SID>EnableStripWhitespaceOnSave()
" Run :DisableStripWhitespaceOnSave to disable whitespace stripping on save
command! DisableStripWhitespaceOnSave call <SID>DisableStripWhitespaceOnSave()
" Run :ToggleStripWhitespaceOnSave to enable/disable whitespace stripping on save
command! ToggleStripWhitespaceOnSave call <SID>ToggleStripWhitespaceOnSave()
" Run :EnableWhitespace to enable whitespace highlighting
Expand Down