Hate it when people commit whitespace in a codebase? Why not kill it all? There's definitely a way to do this with
sed(1) but this is my preferred workflow.
First, find all files inside your current directory:
find . -type f
#We don't care about directories
Then turn that output into a single line, space delimited list
find . -type f | tr "\\n" " "
#Turn all newline characters into a space
Now we have a list of files we can pipe into vi(m)
find . -type f | tr "\\n" " " | xargs vim
#Start vim with the arglist populated with all of our files
Once vim loads, you can run a command over all the files you just gave it with:
In our case, we want to remove trailing whitespace from each document:
Since we want to save the changes we've made we can also tell vim to write these files:
:argdo %s/\s\+$// | w
I also don't care about the files where no trailing whitespace was found, I pass it the "e" flag
:argdo %s/\s\+$//e | w
#See :help :s_flags for more info
Finally, If you don't care which files were changed you can call silent before the command
:silent argdo %s/\s\+$//e | w
I hope this helps someone!