views:

241

answers:

3

In normal text editors, you select the block of text and then press Tab to entab and Shift + Tab to detab.

How do I entab or detab a selected block of text in VIM?

+3  A: 

If you select the text and hit ">" it will indent, and "<" will de-indent.

Whether it inserts tabs or spaces depends on your "expandtab" setting. You can edit the number of spaces/tabstop with the "shiftwidth" and "tabstop" settings.

Andy White
+1 Note: Shift V (Visual mode) to select the text block. Otherwise < and > will work on the current line.
Stefan Mai
You can also select a block of text and press = to get vim to auto-indent.
MichaelM
@MichaelM: Thanks for that tip! Post it as an answer please, instead of a comment. I'll upvote you
Andreas Grech
+2  A: 

In addition to Andy White's answer. I would also add the following into vimrc:

vnoremap > >gv
vnoremap < <gv

So you wouldn't need to reselect your code block to indent/dedent further.

Maxim Kim
A: 

You don't even need to select the text. You can indent/unindent the current line by hitting ">>" or "<<".

Alison R.