In regular text editors, you select a block of text, and then press Tab to entab and Shift + Tab to define.
How do I paste or highlight a selected block of text in VIM?
If you select the text and press ">", it will indent and "<" will indent.
Inserting tabs or spaces depends on the expandtab setting. You can edit the number of spaces / tabstop with the settings "shiftwidth" and "tabstop".
In addition to Andy White's answers. I would also add the following to vimrc:
vnoremap > >gv vnoremap < <gv
This way, you will not need to reselect your code block for indentation / selection.
You donβt even need to select text. You can reverse / cancel the current line by pressing >> or << .
>>
<<