Remove Trailing Whitespace With Vim

Posted by Weston Ganger

Vim is awesome and it can remove all trailing whitespace automatically.

For the Current File:


:%s/\s\+$//


If you want to get Vim to remove all trailing whitespace whenever you save the file you can add an auto command to your ~/.vimrc


# on every file save
autocmd BufWritePre * :%s/\s\+$//e

# on certain file extension
autocmd BufWritePre *.rb :%s/\s\+$//e

# on certain file types
autocmd FileType ruby,php,java autocmd BufWritePre <buffer> :%s/\s\+$//e


Related External Links:

Article Topic:Software Development - Linux

Date:April 29, 2015

Recommended Posts

Contact

604-309-8713
info@solidfoundationwebdev.com

Send Me A Message

I would love to get in touch and talk about your next project. Feel free to send a message and I will get back to you shortly.

Get Connected