Skip to content

Commit 9e4f387

Browse files
committed
To add a single trailing newline at the end of the file when stripping whitespace
1 parent 166a409 commit 9e4f387

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ Whitespace highlighting is enabled by default, with a highlight color of red.
185185
let g:strip_whitelines_at_eof=1
186186
```
187187
188+
* To add a single trailing newline at the end of the file when stripping whitespace, set this option in your `.vimrc`:
189+
```vim
190+
let g:strip_whitelines_at_eof=2
191+
```
192+
193+
* To highlight space characters that appear before or in-between tabs, add the following to your `.vimrc`:
188194
* To highlight space characters that appear before or in-between tabs, add the following to your `.vimrc`:
189195
```vim
190196
let g:show_spaces_that_precede_tabs=1

plugin/better-whitespace.vim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ function! s:StripWhitespace(line1, line2)
200200
silent execute ':' . a:line1 . ',' . a:line2 . 's/' . s:strip_whitespace_pattern . '//e'
201201

202202
" Strip empty lines at EOF
203-
if g:strip_whitelines_at_eof == 1 && a:line2 >= line('$')
203+
if g:strip_whitelines_at_eof >= 1 && a:line2 >= line('$')
204204
if &ff == 'dos'
205205
let nl='\r\n'
206206
elseif &ff == 'max'
@@ -209,6 +209,10 @@ function! s:StripWhitespace(line1, line2)
209209
let nl='\n'
210210
endif
211211
silent execute '%s/\('.nl.'\)\+\%$//e'
212+
" Add trailing newline at EOF
213+
if g:strip_whitelines_at_eof == 2
214+
silent call append(line('$'), '')
215+
endif
212216
endif
213217

214218
" Restore the saved search and cursor position

0 commit comments

Comments
 (0)