diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-10-30 20:31:54 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-10-30 20:31:54 +1300 |
commit | 0d4d325b3b8db2801c3a91791e5eb2244106551a (patch) | |
tree | 1ccd863d7493ce3a4c852e9e71978da136852f8d /vim | |
parent | Backport StripTrailingWhitespace to pre-for Vim (diff) | |
download | dotfiles-0d4d325b3b8db2801c3a91791e5eb2244106551a.tar.gz dotfiles-0d4d325b3b8db2801c3a91791e5eb2244106551a.zip |
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.
Diffstat (limited to 'vim')
-rw-r--r-- | vim/config/whitespace.vim | 18 |
1 files changed, 18 insertions, 0 deletions
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 <silent> <leader>x :<C-U>call <SID>StripTrailingWhitespace()<CR> + endif |