Vim Shots
:%s/\s\+$//
Using the command line mode, we construct a regular expression that will remove all whitespace characters at the end of a line.
This command looks daunting at first but we can break it down into simpler pieces:
: %s/ \s \+ $ //
The first command - : - tells vim to run the following command in command-line mode.
The next command - %s/ - says that we will find and replace the following patterns globally.
The next 3 elements \s \+ $ are the pattern to match:
\smatches any whitespace character\+tells us to match one or more of the preceeding pattern (i.e.\s)$matches the end of a line
So, we match one or more whitespace characters at the end of the line, and …
//
replace them with nothing 😀