Remove all arbitary spaces before a line in Vim

↘锁芯ラ 提交于 2019-11-27 07:11:35

To format a line to the left I use :left. Use this format an entire file:

:%le

A simple search/replace s/^\s*// should do the trick, but it's probably not the minimal version.

Personally I would visually select the lines with V, then use 99< to push the text as far left as it could go.

Just type d followed by w followed by j at the beginning of each line.

How about this:

:%s/^ *//

Or are you looking for a vim-script solution?

To remove initial spaces and tabs at specified line numbers (E.g. from lines 5 to 10),

:5,10s/^\s*//

The search/replace suggested by Lukáš Lalinský or the %le approach in the wikia page is probably the way I'd do it, but as another alternative you could also do:

:%< 99

As a quick way to shift the whole file (%) 99 times to the left.

Remove all consecutive spaces: :%s/ */ /g

It was useful to me to go from:

$screen-xs-min:              480px;
$screen-sm-min:              768px;
$screen-md-min:                992px;
$screen-lg-min:                  1200px;

To:

$screen-xs-min: 480px;       
$screen-sm-min: 768px;       
$screen-md-min: 992px;           
$screen-lg-min: 1200px;                                                                                                 

Yet another way to achieve this is using the the normal command :h :normal-range

:%norm d^

This goes to column 0 in each line (%) and deletes (d) to the first non-white character(^).

This is slightly more to type as the accepted answer, but allows for easy extension if you have a more complex scenario in mind, such as additional un-commenting or so:

:%norm d^I# 

Resulting in:

#Example line
#This is part of the parsed line
#Thats goes one
#End of line
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!