Vim - Indent multiple lines with tab

To select and highlight your text, you need to start using visual mode, (I usually do this by hitting v) and select your text using the standard motions (such as h, j, k and l) .

To create mappings for use in visual mode you need :vmap...

:vmap <Tab> >
:vmap <S-Tab> <

But why do you need to create a mapping for this?

In visual mode, < will shift selected lines leftwards and > rightwards.

Sometimes it's better just to learn the Vim (or even Vi) keys, and then you can use any installation, not just the one with your .vimrc.

For instance, you've put:

imap <Tab> <

This a bad idea. This will make it harder for you to insert a tab-character into your text (even ctrl+i won't work as I'd expect), and every time you type tab you'll insert a <.

Happy editing!


In insert mode you can use control-d and control-t to remove/add an indent (respectively).

So, replace

imap <Tab> <

with

imap <Tab> <c-d>

and

imap <Tab> >

with

imap <Tab> <c-t>

In visual mode you can highlight a block and then hit < or >, but if you'd like it to be tab and shift-tab, you can set it with vmap like you have done for the others.