diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | doc/strip_trailing_whitespace.txt | 10 | ||||
-rw-r--r-- | plugin/strip_trailing_whitespace.vim | 72 |
4 files changed, 43 insertions, 43 deletions
@@ -23,7 +23,7 @@ because I could not find a plugin that did this in exactly the way I wanted: License ------- -Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself. +Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself. See `:help license`. [1]: https://sanctum.geek.nz/ @@ -1 +1 @@ -2.0.2 +2.1.0 diff --git a/doc/strip_trailing_whitespace.txt b/doc/strip_trailing_whitespace.txt index c29b664..6a79128 100644 --- a/doc/strip_trailing_whitespace.txt +++ b/doc/strip_trailing_whitespace.txt @@ -23,16 +23,16 @@ because I could not find a plugin that did this in exactly the way I wanted: REQUIREMENTS *strip_trailing_whitespace-requirements* -This plugin is only available if 'compatible' is not set. It also requires the -|+user_commands| feature. +This plugin is only available if 'compatible' is not set. It also requires +the |+user_commands| feature. COMMANDS *strip_trailing_whitespace-commands* *:StripTrailingWhitespace* Strip trailing space appropriately for the range of lines selected, defaulting -to the entire buffer. Remove all horizontal whitespace from the end of each -line. If the last line of the range is also the last line of the buffer, strip -trailing blank or whitespace-only lines as well. +to the entire buffer. Remove all horizontal whitespace from the end of each +line. If the last line of the range is also the last line of the buffer, +strip trailing blank or whitespace-only lines as well. AUTHOR *strip_trailing_whitespace-author* diff --git a/plugin/strip_trailing_whitespace.vim b/plugin/strip_trailing_whitespace.vim index 207863a..5fde8e3 100644 --- a/plugin/strip_trailing_whitespace.vim +++ b/plugin/strip_trailing_whitespace.vim @@ -6,48 +6,48 @@ " Author: Tom Ryder <tom@sanctum.geek.nz> " License: Same as Vim itself " -if exists('g:loaded_strip_trailing_whitespace') || &compatible +if exists('loaded_strip_trailing_whitespace') || &compatible finish endif if !has('user_commands') || v:version < 600 finish endif -let g:loaded_strip_trailing_whitespace = 1 +let loaded_strip_trailing_whitespace = 1 " Wrapper function to strip both horizontal and vertical trailing whitespace, " return the cursor to its previous position, and report changes function s:Strip(start, end) abort " Save cursor position - let l:line = line('.') - let l:col = col('.') + let line = line('.') + let col = col('.') " Whether we made changes - let l:changed = 0 + let changed = 0 " If we're going to the end, strip vertical space; we do this first so we " don't end up reporting having trimmed lines that we deleted if a:end == line('$') - let l:vertical = s:StripVertical() - let l:changed = l:changed || l:vertical > 0 + let vertical = s:StripVertical() + let changed = changed || vertical > 0 endif " Strip horizontal space - let l:horizontal = s:StripHorizontal(a:start, a:end) - let l:changed = l:changed || l:horizontal > 0 + let horizontal = s:StripHorizontal(a:start, a:end) + let changed = changed || horizontal > 0 " Return the cursor - call s:Cursor(l:line, l:col) + call s:Cursor(line, col) " Report what changed - let l:msg = l:horizontal.' trimmed' - if exists('l:vertical') - let l:msg = l:msg.', '.l:vertical.' deleted' + let msg = horizontal.' trimmed' + if exists('vertical') + let msg = msg.', '.vertical.' deleted' endif - echomsg l:msg + echomsg msg " Return whether anything changed - return l:changed + return changed endfunction @@ -55,26 +55,26 @@ endfunction function s:StripHorizontal(start, end) abort " Start a count of lines trimmed - let l:count = 0 + let count = 0 " Iterate through buffer - let l:num = a:start - while l:num <= line('$') && l:num <= a:end + let num = a:start + while num <= line('$') && num <= a:end " If the line has trailing whitespace, strip it off and bump the count - let l:line = getline(l:num) - if l:line =~# '\s\+$' - call setline(l:num, substitute(l:line, '\s*$', '', '')) - let l:count = l:count + 1 + let line = getline(num) + if line =~# '\s\+$' + call setline(num, substitute(line, '\s*$', '', '')) + let count = count + 1 endif " Bump for next iteration - let l:num = l:num + 1 + let num = num + 1 endwhile " Return the number of lines trimmed - return l:count + return count endfunction @@ -83,34 +83,34 @@ function s:StripVertical() abort " Store the number of the last line we found with non-whitespace characters " on it; start at 1 because even if it's empty it's never trailing - let l:eof = 1 + let eof = 1 " Iterate through buffer - let l:num = 1 - while l:num <= line('$') + let num = 1 + while num <= line('$') " If the line has any non-whitespace characters in it, update our pointer " to the end of the file text - let l:line = getline(l:num) - if l:line =~# '\S' - let l:eof = l:num + let line = getline(num) + if line =~# '\S' + let eof = num endif " Bump for next iteration - let l:num = l:num + 1 + let num = num + 1 endwhile " Get the number of lines to delete; if there are any, build a range and " remove them with :delete, suppressing its normal output (we'll do it) - let l:count = line('$') - l:eof - if l:count - let l:range = (l:eof + 1).',$' - silent execute l:range.'delete' + let count = line('$') - eof + if count + let range = (eof + 1).',$' + silent execute range.'delete' endif " Return the number of lines deleted - return l:count + return count endfunction |