Remove white spaces in vi/vim

While editing a file you will find a few unwanted spaces at the end of line or at the beginning of the lines. You can get rid of these unwanted whitespace using vi/vim.

Commands to remove unwanted whitespace

Many of you might be aware of the search option in vi/vim command mode. In search, \s finds whitespace (a space or a tab), and \+ finds one or more occurrences.

You can use the following vi/vim command to delete trailing whitespace at the end of each line:


And, the following command can be used to delete whitespace at the beginning of each line:


No Comments

Post a Comment

Time limit is exhausted. Please reload CAPTCHA.