diff --git a/README.md b/README.md index a900470..ac84a6a 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,12 @@ Whitespace highlighting is enabled by default, with a highlight color of red. let g:strip_whitelines_at_eof=1 ``` +* To add a single trailing newline at the end of the file when stripping whitespace, set this option in your `.vimrc`: + ```vim + let g:strip_whitelines_at_eof=2 + ``` + +* To highlight space characters that appear before or in-between tabs, add the following to your `.vimrc`: * To highlight space characters that appear before or in-between tabs, add the following to your `.vimrc`: ```vim let g:show_spaces_that_precede_tabs=1 diff --git a/plugin/better-whitespace.vim b/plugin/better-whitespace.vim index d974038..cb3c99d 100644 --- a/plugin/better-whitespace.vim +++ b/plugin/better-whitespace.vim @@ -200,15 +200,17 @@ function! s:StripWhitespace(line1, line2) silent execute ':' . a:line1 . ',' . a:line2 . 's/' . s:strip_whitespace_pattern . '//e' " Strip empty lines at EOF - if g:strip_whitelines_at_eof == 1 && a:line2 >= line('$') - if &ff == 'dos' - let nl='\r\n' - elseif &ff == 'max' - let nl='\r' - else " unix + if g:strip_whitelines_at_eof >= 1 && a:line2 >= line('$') + if &ff == 'dos' || &ff == 'unix' let nl='\n' + elseif &ff == 'mac' + let nl='\r' endif silent execute '%s/\('.nl.'\)\+\%$//e' + " Add trailing newline at EOF + if g:strip_whitelines_at_eof == 2 + silent call append(line('$'), '') + endif endif " Restore the saved search and cursor position @@ -453,3 +455,4 @@ endif let s:errmsg='please set g:current_line_whitespace_disabled_{soft,hard} and reload better whitespace' command! -nargs=* CurrentLineWhitespaceOff echoerr 'E492: Deprecated command CurrentLineWhitespaceOff: '.s:errmsg command! CurrentLineWhitespaceOn echoerr 'E492: Deprecated command CurrentLineWhitespaceOn: '.s:errmsg +