Removing trailing spaces in vim

Following commands can be added to the .vimrc file, so that once you save any .c or .h file, the trailing spaces will be removed.

autocmd BufWritePre *.c :%s/\s\+$//e
autocmd BufWritePre *.h :%s/\s\+$//e

If you simply want to removing trailing white spaces from your currently opened file, execute the following command within vim:

:%s/\s\+$//e

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s