aboutsummaryrefslogtreecommitdiff
path: root/vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-10-30 20:31:54 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-10-30 20:31:54 +1300
commit0d4d325b3b8db2801c3a91791e5eb2244106551a (patch)
tree1ccd863d7493ce3a4c852e9e71978da136852f8d /vim
parentBackport StripTrailingWhitespace to pre-for Vim (diff)
downloaddotfiles-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.vim18
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