diff --git a/README.md b/README.md index 4bc6951..df538a6 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,11 @@ Whitespace highlighting is enabled by default, with a highlight color of red. let g:better_whitespace_verbosity=1 ``` +* To skip lines that contain only whitespace, set the following in your `.vimrc`: + ``` + let g:better_whitespace_skip_empty_lines=1 + ``` + ## Supported Whitespace Characters Due to the fact that the built-in whitespace character class for patterns (`\s`) only matches against tabs and spaces, this plugin defines its own list of diff --git a/plugin/better-whitespace.vim b/plugin/better-whitespace.vim index 27e0c17..e668929 100644 --- a/plugin/better-whitespace.vim +++ b/plugin/better-whitespace.vim @@ -41,8 +41,13 @@ call s:InitVariable('g:better_whitespace_verbosity', 0) " Define custom whitespace character group to include all horizontal unicode " whitespace characters. Vim's '\s' class only includes ASCII spaces and tabs. -let s:whitespace_group='[\u0009\u0020\u00a0\u1680\u180e\u2000-\u200b\u202f\u205f\u3000\ufeff]' -let s:eol_whitespace_pattern = s:whitespace_group . '\+$' +let s:whitespace_chars='\u0009\u0020\u00a0\u1680\u180e\u2000-\u200b\u202f\u205f\u3000\ufeff' +let s:eol_whitespace_pattern = '[' . s:whitespace_chars . ']\+$' + +call s:InitVariable('g:better_whitespace_skip_empty_lines', 0) +if g:better_whitespace_skip_empty_lines == 1 + let s:eol_whitespace_pattern = '[^' . s:whitespace_chars . ']\@1<=' . s:eol_whitespace_pattern +endif " Only init once let s:better_whitespace_initialized = 0 @@ -292,4 +297,3 @@ function! SetupAutoCommands() augroup END endfunction -