Archived post: posted sometime between 2016 and 2022.

Vim: Clear trailing whitespace

Enter command mode and do the following substitution.

:%s/\s\{2,\}$//e

The backslashes \ are escape characters. \s is whitespace. {2,} is two or more instances. $ is the end of a line. e avoids an error if there is no match.