Vim: how to remove spaces before the first character?

I have a line like this:

foobar 

since you see that there are many spaces between the first column and β€œfoobar”. If I have a pointer in the first column, is there a key binding to remove spaces before "foobar"?

+6
source share
4 answers

d w

Will remove all spaces if you are in the first column.

+12
source
 dtf 

Delete to F

There are no other simple commands. You can use regex, but it would be harder to write.

My bad answer @Mat is even better ( dw ).

+2
source

Simple answer

 dw 

... which executes [d] elete [w] ord. If you want to remove all spaces in the entire document before all occurrences of "foobar":

 :%s/^\s*foobar/foobar/ 
+2
source

Method 1: Go to the line and :s/^ *//g

Path 2: Go to the first blank space of this line and press dw

0
source

Source: https://habr.com/ru/post/914962/


All Articles