Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting spaces on multiple lines in VIM

Tags:

vim

macvim

To indent HAML code I usually add or delete 2 spaces. Adding I do:

  1. Enter visual mode ( ctrl + v)
  2. jj to select the lines
  3. shift + i to go into insert
  4. type 2 spaces
  5. ESC

That's it 2 spaces are added. However to remove the spaces, I't does not work, for example doing:

  1. Enter visual mode ( ctrl + v)
  2. jj to select the lines
  3. shift + i to go into insert
  4. Delete 2 spaces ( with backspace or delete)
  5. ESC

This just does not work, other lines spaces are not deleted. How then can I do this ?

Here is an example code:


 .module_1
     .pricing_details
       %h2
         Save

The idea is moving everything so it matches 2 space in respecto .module_1 as:


 .module_1
   .pricing_details
     %h2
       Save

The propose solution using < > works only for indenting now I'd like to for example:


 .module_1
   .pricing_details
     %h2
       Save

move the above to:


 .module_1
 .pricing_details
   %h2
     Save
like image 379
daniel Avatar asked Dec 21 '22 18:12

daniel


1 Answers

Try < and > commands. You will need :set shiftwidth=2 for them to work in this way.


UPDATE

Considering your last example, changing

.module_1
  .pricing_details
    %h2
      Save

to ⇓

.module_1
.pricing_details
  %h2
    Save

can be accomplished with moving to .pricing_details line and hitting Vjj<.

like image 173
ulidtko Avatar answered Jan 21 '23 11:01

ulidtko