Skip to content

Add option to trim last empty line #120

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

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
4 changes: 4 additions & 0 deletions autoload/clang_format.vim
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ let g:clang_format#filetype_style_options = s:getg('clang_format#filetype_style_

let g:clang_format#detect_style_file = s:getg('clang_format#detect_style_file', 1)
let g:clang_format#enable_fallback_style = s:getg('clang_format#enable_fallback_style', 1)
let g:clang_format#trim_last_empty_line = s:getg('clang_format#trim_last_empty_line', 0)

let g:clang_format#auto_format = s:getg('clang_format#auto_format', 0)
let g:clang_format#auto_format_git_diff = s:getg('clang_format#auto_format_git_diff', 0)
Expand Down Expand Up @@ -260,6 +261,9 @@ function! clang_format#replace_ranges(ranges, ...) abort
endif

let winview = winsaveview()
if g:clang_format#trim_last_empty_line
let formatted = trim(formatted, "\n", 2)
endif
let splitted = split(formatted, '\n', 1)

silent! undojoin
Expand Down
10 changes: 9 additions & 1 deletion doc/clang-format.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,15 @@ g:clang_format#enable_fallback_style *g:clang_format#enable_fallback_style*
".clang-format" is not found.
The default value is 1.


g:clang_format#trim_last_empty_line *g:clang_format#trim_last_empty_line*

If the initial buffer ends with one or more empty lines, vim-clang-format
will let one single empty line. This is not the clang-format behavior,
which do not let any empty line at the end of the file.
When the value is 1, vim-clang-format ensures that formatted buffer does
end with any empty lines.
The default value is 0 (which is the historical vim-clang-format
behavior).

==============================================================================
SETUP EXAMPLE *vim-clang-format-setup-example*
Expand Down