In Vim, is there a way to TAB multiple adjacent lines at a time?

0

1

I've noticed that dragging your mouse to highlight, say, 5 lines in a row and then pressing the TAB button does not do it for you... Is there a way to TAB in bulk, or is just something that is usually done manually?

Also, is there a way to likewise un-TAB (by this I don't mean get rid of *all* tabs) those 5 adjacent lines? So let's say line 1 is tabbed twice, line 2 is tabbed four times, etc, can it be so that if you want to un-TAB them together, line 1 will now be tabbed only once, and line 2 now tabbed 3 times, etc?

Dark Templar

Posted 2011-12-20T19:18:42.570

Reputation: 2 329

1BTW, if you find you use the mouse a lot when working with VIM, you really aren't tapping into VIM's full power. I suggest spending some time looking at :help navigation until most of those commands are second nature and you're keeping your hands on the keyboard! – Codie CodeMonkey – 2011-12-21T16:53:55.587

Answers

9

Shift-V to enter Visual Line mode. Select the lines that you want. Press >.

To untab, do the same to select, but use <.

EBGreen

Posted 2011-12-20T19:18:42.570

Reputation: 7 834

2And of course you can use count, so 5<< would unindent 5 lines at a time. – Wayne Werner – 2011-12-20T19:50:12.837

I thought about that as my first answer and that is the best solution if you know exactly how many lines you want to effect...I'm just too lazy to count lines most of the time :) – EBGreen – 2011-12-20T19:54:23.840

1I tend to use >} a lot to indent paragraphs (in source code). I also use >'b after marking the endpoint with mb – RedGrittyBrick – 2011-12-20T20:41:11.403

4

Using the command line:

  1. : to enter command
  2. . to select current line
  3. ,[+,-] use + or - to select forward or back
  4. [number] the number of lines
  5. > or < to indent or outdent

or

  1. : to enter command mode
  2. [num],[num] to select a range of lines by line number
  3. > or < to indent or outdent

For example:

:.,+5>

:.,-3<

:12,25>

lhagemann

Posted 2011-12-20T19:18:42.570

Reputation: 286

1

Some ways to do it.

  • Enter viusal mode v and press > for adding tabs and < for removing tabs
  • Press 5>> to add tabs to five lines or 5<< to remove
  • Put a mark on the fifth line ma go to the first line and do >'a

Of course in many situations you can replace >/< with = to do auto-indent

tidbeck

Posted 2011-12-20T19:18:42.570

Reputation: 1 365