From 9e4f387678a4fca4f19115d2aedcd316cddd034c Mon Sep 17 00:00:00 2001 From: a12o Date: Sun, 10 Nov 2019 20:34:54 -0500 Subject: [PATCH 1/2] To add a single trailing newline at the end of the file when stripping whitespace --- README.md | 6 ++++++ plugin/better-whitespace.vim | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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..7928b9e 100644 --- a/plugin/better-whitespace.vim +++ b/plugin/better-whitespace.vim @@ -200,7 +200,7 @@ 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 g:strip_whitelines_at_eof >= 1 && a:line2 >= line('$') if &ff == 'dos' let nl='\r\n' elseif &ff == 'max' @@ -209,6 +209,10 @@ function! s:StripWhitespace(line1, line2) let nl='\n' 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 From 494d5aa11a0e33886c3f01dad7738cd5b18e659f Mon Sep 17 00:00:00 2001 From: a12o Date: Sun, 10 Nov 2019 23:41:49 -0500 Subject: [PATCH 2/2] fix mac fileformat typo, use \n as search criterion for both dos and unix --- plugin/better-whitespace.vim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugin/better-whitespace.vim b/plugin/better-whitespace.vim index 7928b9e..cb3c99d 100644 --- a/plugin/better-whitespace.vim +++ b/plugin/better-whitespace.vim @@ -201,12 +201,10 @@ function! s:StripWhitespace(line1, line2) " 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 &ff == 'dos' || &ff == 'unix' let nl='\n' + elseif &ff == 'mac' + let nl='\r' endif silent execute '%s/\('.nl.'\)\+\%$//e' " Add trailing newline at EOF @@ -457,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 +