Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To add a single trailing newline at the end of the file when stripping whitespace #122

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions plugin/better-whitespace.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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