59

I've found several answers on how to indent multiple lines in vim, I want to know how to take a single line and indent it more than once. In effect, I want a shorter version of the following command: ">>>>>>>>>>" (That is 10 right bracket "greater-than" signs.)

Cory Klein
  • 40,647
  • 27
  • 164
  • 222
  • 15
    well, you could use `.` to repeat the last command, shortening it to `>>....` – meager Sep 13 '10 at 16:52
  • You could also press `:>>>>>` – meager Sep 13 '10 at 16:54
  • 1
    To be clear, `5>>` will indent five lines, not the current line five times. Strange design choice, as `>4>` does the same thing, and `3>4>` would be a handy way to indent five lines three times. – BallpointBen May 24 '18 at 16:01

5 Answers5

90

Select what you want (typically with v or Shift+v) then type 5>.

If you need to fix or repeat the same selection, use gv.

ldog
  • 10,559
  • 9
  • 52
  • 68
14

You can select the current line by pressing v, and then type 5> to indent the current line 5 times, the equivalent of pressing > 10 times.

meager
  • 209,754
  • 38
  • 307
  • 315
  • 8
    Daenyth is right, but it is moot. You only have to be in visual mode; whether line-select or not is irrelevant in this case. – Jay Sep 13 '10 at 17:14
13

One of the answers to "How do I indent multiple lines quickly in vi" showed me a neat trick to remap > in visual mode to reselect visual mode. In your .vimrc...

vnoremap < <gv
vnoremap > >gv

Then I just select the line (or lines) you want to indent and press the appropriate direction as many times as you want.

Community
  • 1
  • 1
dash-tom-bang
  • 16,375
  • 4
  • 43
  • 56
  • It's a nice trick if you do it all in visual mode, and I like to see the selection afterwards, but I like to use . after the initial modification, which is only in normal mode. I'm adding this to my .vimrc but mapping them to and instead. – Pif Jan 17 '12 at 12:41
12

Indent once the use . to redo the previous command or u to undo it.

Tudor
  • 4,108
  • 5
  • 36
  • 51
3

From vim help: :help >

To move a line several 'shiftwidth's, use Visual mode or the : commands.

For example:

    Vjj4>           move three lines 4 indents to the right
    :<<<            move current line 3 indents to the left
    :>> 5           move 5 lines 2 indents to the right
    :5>>            move line 5 2 indents to the right

Or simply, >> and repeat the command with . in normal mode.

Community
  • 1
  • 1
dlmeetei
  • 7,297
  • 3
  • 25
  • 34