-1

Is it possible to indent blocks of code in vim instead of going to each line and indenting a line at a time?

Maybe highlight the code and execute a command that will indent the highlighted code?

Mars
  • 4,677
  • 8
  • 43
  • 65
  • 1
    n >> (where n is the number of lines you want to indent), if you want to auto indent, n == would work – bjhaid Nov 27 '13 at 07:35
  • Is there a way to set how many spaces `>>` will indent? – Mars Nov 27 '13 at 07:40
  • set tabstop=2 shiftwidth=2 softtabstop=2 would set it for you as you have seen I have set it to 2 you can add that to your ~/.vimrc file – bjhaid Nov 27 '13 at 07:41

2 Answers2

2

First, for indenting there's both the > command, which simply shifts to the right by adding one level of indent (how much is determined by the 'shiftwidth' option, and 'expandtab' tells whether to use Tabs or spaces), and the = command, which applies (language-specific) indentation rules.

Both commands work on line(s) when doubling, i.e. >> / ==; you address multiple lines by prepending a number.

But they also take a {motion}, e.g. 3j (3 lines down), or } (to the end of the paragraph).

And finally, you can make a visual selection (V), make it the right size, and then apply the command to it.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
1

hilite code and type >

yosukesabai
  • 6,184
  • 4
  • 30
  • 42