Remove all arbitary spaces before a line in Vim

前端 未结 9 2252
感动是毒
感动是毒 2020-12-01 02:56

I\'v written a plugin where it comes to parsing a XML tag. The content inside the tag is indented and when i copy the parsed string into the file it\'s gettting like:

<
相关标签:
9条回答
  • 2020-12-01 03:06

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

    :5,10s/^\s*//
    
    0 讨论(0)
  • 2020-12-01 03:08

    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.

    0 讨论(0)
  • 2020-12-01 03:16

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

    :%le
    
    0 讨论(0)
  • 2020-12-01 03:19

    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;                                                                                                 
    
    0 讨论(0)
  • 2020-12-01 03:22

    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
    
    0 讨论(0)
  • 2020-12-01 03:24

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

    0 讨论(0)
提交回复
热议问题