Remove any leading spaces (not including tabs)

2

I'm trying to remove leading spaces in vim but not touch tabs. For instance, if each of the lines below have a leading tab, but b_line has an additional two spaces, how can I just remove those two spaces?

a_line
  b_line
c_line

I'm using this to remove all unwanted trailing whitespace:

:%s/\s\+$//

http://vim.wikia.com/wiki/Remove_unwanted_spaces

tarabyte

Posted 2015-11-17T04:34:11.747

Reputation: 1 151

Answers

2

Use this instead:

:%s/^\(\t\+\)\s\+/\1/

It preserves the leading tab characters, but removes spaces, following those tabs.

chaos

Posted 2015-11-17T04:34:11.747

Reputation: 3 704