Vim Macro: cleaning up line endings
Tuesday, July 1. 2008
Hi Lorna.
Cool tip but I think I can go one better!
I have the following line in my ~/.vim/ftplugin/php.vim file
autocmd BufWritePre *.php :%s/\s\+$//e
This removes all trailing spaces in a .php file prior to writing it to disk and means I can concentrate on work rather that using macros ;-)
Ken: Hello, thanks for dropping by and upstaging me with such an excellent tip :) I’ve also seen some nice pre-commit hooks for SVN that cleans up this kind of badness before the files go near the repo.
Have you tried using the svn:eol-style property? This seems more appropriate than using pre-commit hooks.
Geoff: For line-endings the SVN property is really useful, but for more complex requirements, like the ones Ken mentioned, a hook is more functional I think. I must admit to usually specifying whitespace and line endings in coding standards and then shouting at people that do it wrong … its a less technical solution but it works :)
Lorna,
If you’re getting into hooks and coding standards you might want to have a look at triggering Greg Sherwood’s php codesniffer when somebody attempts to check in changes.
http://url.ie/hq6 is a redirect to his blog posting about doing this.
Ken: Thanks for the link, I will have to take a look at that.
