Skip to content

Instantly share code, notes, and snippets.

@mpereira
Created July 24, 2011 21:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mpereira/1103130 to your computer and use it in GitHub Desktop.
Save mpereira/1103130 to your computer and use it in GitHub Desktop.

Remove trailing whitespace, convert tabs to spaces and file format to unix (remove ugly ^M carriage returns) from files using a single command:

vim -es -c 'set et ts=2 | bufdo retab | %s/\s\+$//e | set ff=unix | w' -c 'q' FILES

You could get your FILES using find

vim -es -c 'set et ts=2 | bufdo retab | %s/\s\+$//e | set ff=unix | w' -c 'q' $(find scripts -name '*.sh' -type f)

If in doubt, ask man.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment