From 0d4d325b3b8db2801c3a91791e5eb2244106551a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 30 Oct 2017 20:31:54 +1300 Subject: Add some comments to Vim StripTrailingWhitespace() No functional changes; this is just to make it a little clearer before I add some more functionality to it. --- vim/config/whitespace.vim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'vim/config/whitespace.vim') diff --git a/vim/config/whitespace.vim b/vim/config/whitespace.vim index 103ef808..d44ba333 100644 --- a/vim/config/whitespace.vim +++ b/vim/config/whitespace.vim @@ -4,14 +4,32 @@ set nojoinspaces " Strip trailing whitespace with \x if has('eval') + + " Define function for stripping whitespace function! s:StripTrailingWhitespace() + + " Iterating line number let l:li = 1 + + " Line number of the file's last line let l:ll = line('$') + + " Iterate over the lines while l:li <= l:ll + + " Get the line text let l:line = getline(l:li) + + " Replace the line with a subsitution of its text stripping extraneous + " whitespace call setline(l:li, substitute(l:line, '\m\C\s\+$', '', 'g')) + + " Increment the line counter for the next iteration let l:li = l:li + 1 endwhile endfunction + + " Map \x to the function just defined nnoremap x :call StripTrailingWhitespace() + endif -- cgit v1.2.3