diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-10-30 19:42:46 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-10-30 19:42:46 +1300 |
commit | c37fe80b339a669a7680902fbac2286dd4a677f5 (patch) | |
tree | 57c9c1c2f7d5271c7f2c21f4c8ee4e88ad919de8 /vim/config/whitespace.vim | |
parent | Move 'encoding' Vim config into subfile (diff) | |
download | dotfiles-c37fe80b339a669a7680902fbac2286dd4a677f5.tar.gz dotfiles-c37fe80b339a669a7680902fbac2286dd4a677f5.zip |
Backport StripTrailingWhitespace to pre-for Vim
Use a slightly more verbose but more compatible `:while` loop to
accommodate very old versions of Vim that do not have `:for`.
Vim 6.2 gives the following terminal output when the `:for` version is
run:
Error detected while processing /home/tom/.vim/config/whitespace.vim:
line 13:
E193: :endfunction not inside a function
However, it accepts this new version with no complaint, and the function
seems to work properly.
Diffstat (limited to 'vim/config/whitespace.vim')
-rw-r--r-- | vim/config/whitespace.vim | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/vim/config/whitespace.vim b/vim/config/whitespace.vim index 4189d858..103ef808 100644 --- a/vim/config/whitespace.vim +++ b/vim/config/whitespace.vim @@ -6,10 +6,12 @@ set nojoinspaces if has('eval') function! s:StripTrailingWhitespace() let l:li = 1 - for l:line in getline(1,'$') + let l:ll = line('$') + while l:li <= l:ll + let l:line = getline(l:li) call setline(l:li, substitute(l:line, '\m\C\s\+$', '', 'g')) let l:li = l:li + 1 - endfor + endwhile endfunction nnoremap <silent> <leader>x :<C-U>call <SID>StripTrailingWhitespace()<CR> endif |