Vim Recall繁體中文

Remove trailing whitespace

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

Example

Normal 0 / 2
one   
two 
three
Cursor on line 1, column 1

Match one or more whitespace characters at each line end.

Before & after
Before
one   
two 
three
Cursor on line 1, column 1
After
one
two
three
Cursor on line 2, column 1

Start in Normal mode, at line 1, column 1 (one-based). The percent range covers the file; e suppresses a no-match error. The example contains ordinary spaces. This example assumes gdefault and edcompatible are off. Type :%s/\s\+$//e and press Enter.

Details & Vim help

Example replayed in Vim

Match one or more whitespace characters at each line end.

The percent range covers the file; e suppresses a no-match error. The example contains ordinary spaces. This example assumes gdefault and edcompatible are off.