Friday, November 25, 2011

Re: strip whitespace and carriage returns from end of file

Chris Lott wrote the following on 25.11.2011 18:30

> I have the following shortcut to strip whitespace from the end of a file:
> nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
:%s/[\r \t]\+$//

You might also have a look a my au below. It additionaly keeps cursor postion.

> How can I have that command also strip all trailing carriage returns?
>
> c
> --
> Chris Lott
>

,----[ ]--------

" automatically delete trailing whitespace & Dos-returns
fun! <SID>MyDeleteTrailingWhitespace()
if ! &bin
let l:cpo_orig = &cpo
set cpo&vim
let l:l = line(".")
let l:c = col(".")
silent! :%s/[\r \t]\+$//
call histdel("search", -1)
call cursor(l:l, l:c)
let &cpo = l:cpo_orig
endif
endfun
autocmd BufWritePre,FileWritePre * call <SID>MyDeleteTrailingWhitespace()
command! -bar DeleteTrailingWhitespace call <SID>MyDeleteTrailingWhitespace()

`---------------------------------------------


--
Regards,
Thilo

4096R/0xC70B1A8F
721B 1BA0 095C 1ABA 3FC6 7C18 89A4 A2A0 C70B 1A8F


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: