1

I'm new to the more advanced aspects of vi/vim/viemu

I commonly need to select a bit of text and indent/undent, among other things. Right now I have two ways to do this:

  • select the text and use <<
  • use a multi-line command such as :198,205<<

Now, sometimes I need to do this multiple times. When using the dot command though(.) it will never repeat my last command unless I was previously in insert mode. Instead, it will just delete the current line.

Is there a quick and easy way of doing this?

Community
  • 1
  • 1
Earlz
  • 62,085
  • 98
  • 303
  • 499
  • What does this have to do with Visual Studio? – SLaks Jun 15 '11 at 20:12
  • @SLaks ViEmu, presumably. There can always be differences between vim and the ViEmu implementation thereof. – Andrew Jun 15 '11 at 20:13
  • @SLacks, yes what Andrew said. I figured the viemu and visual-studio tag went hand-in-hand – Earlz Jun 15 '11 at 20:14
  • I had never heard of ViEmu until now. I was kinda wondering the same thing... :-) – Dave Rager Jun 15 '11 at 20:18
  • 1
    It's a pretty great little extension. The bad part is they hook you by giving you a 30 day free trial. At the end of the trial, I suppose you get use to vi and can't live without it. But it's fairly cheap at $99 for a single developer(across unlimited machines) – Earlz Jun 15 '11 at 20:36

2 Answers2

3

Use V to visually select the lines and then press the keys 5 then > to indent the lines 5 tabs to the right (or just < to indent once to the left).

ib.
  • 27,830
  • 11
  • 80
  • 100
Jason Rice
  • 1,686
  • 1
  • 12
  • 17
1

If you want to auto-indent the entire file use gg=G. gg move to the beginning of the file, = auto-indent function, G to the end of the file. This will indent code based on block nesting levels.

For what it's worth, >G will indent all the lines one tab to the right from the cursor position to the end of file.

You can also auto-indent text marked with the m bookmark function, i.e. position cursor at start, ma, position the cursor at end, ='a

Dave Rager
  • 8,002
  • 3
  • 33
  • 52