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

Add option to trim trailing newline in basic_format #345

Open
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ let g:neoformat_basic_format_retab = 1

" Enable trimmming of trailing whitespace
let g:neoformat_basic_format_trim = 1

" Enable trimmming of trailing newline
let g:neoformat_basic_format_trim_newline = 1
```

Run all enabled formatters (by default Neoformat stops after the first formatter
Expand Down
14 changes: 14 additions & 0 deletions autoload/neoformat.vim
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ function! s:basic_format() abort
let g:neoformat_basic_format_trim = 0
endif

if !exists('g:neoformat_basic_format_trim_newline')
let g:neoformat_basic_format_trim_newline = 0
endif

if neoformat#utils#var('neoformat_basic_format_align')
call neoformat#utils#log('aligning with basic formatter')
let v = winsaveview()
Expand All @@ -333,4 +337,14 @@ function! s:basic_format() abort
let @/=search
call winrestview(view)
endif
if neoformat#utils#var('neoformat_basic_format_trim_newline')
call neoformat#utils#log('trimming newline with basic formatter')
let search = @/
let view = winsaveview()
" vint: -ProhibitCommandRelyOnUser -ProhibitCommandWithUnintendedSideEffect
silent! %s/\n\+\%$//e
" vint: +ProhibitCommandRelyOnUser +ProhibitCommandWithUnintendedSideEffect
let @/=search
call winrestview(view)
endif
endfunction
3 changes: 3 additions & 0 deletions doc/neoformat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ Enable basic formatting when a filetype is not found. Disabled by default.
" Enable trimmming of trailing whitespace globally
let g:neoformat_basic_format_trim = 1

" Enable trimmming of trailing newline globally
let g:neoformat_basic_format_trim_newline = 1

Run all enabled formatters (by default Neoformat stops after the first
formatter succeeds)

Expand Down