Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entab / Detab in VIM

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?

like image 546
Andreas Grech Avatar asked Nov 19 '09 00:11

Andreas Grech


3 Answers

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.

like image 185
Andy White Avatar answered Nov 09 '22 09:11

Andy White


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.

like image 42
Maxim Kim Avatar answered Nov 09 '22 07:11

Maxim Kim


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

like image 37
Alison R. Avatar answered Nov 09 '22 08:11

Alison R.