Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: left align consecutive lines with the current line

Often times when I paste into vim I get cascading indents that are quite frustrating to fix. The result will look something like this

This is line one
    This is line two
        This is line three
            This is line four

I'd like to know if there is a way that I could tell vim to align lines two through four with line one. If line one text is starting at cursor position 6 is there a way to say "make the next ten lines also start at position 6?"

like image 821
Kevin Thompson Avatar asked Oct 18 '12 16:10

Kevin Thompson


1 Answers

To correct this cascading indentation, you can re-indent a block using =. Select a visual block and type = or supply a motion: =4j to re-indent the next 4 lines.

You might avoid the cascading indentations by setting paste before pasting: :set paste. After the paste :set nopaste.

like image 140
pb2q Avatar answered Sep 21 '22 01:09

pb2q