I'm just learning vim (via gvim, I used to be a Notepad++ user) and haven't yet found how to do 2 things:

  1. How can I indent a set of rows x spaces/tabs right? In Notepad++, for example, I just highlight the rows I need and press 'Tab' key.
  2. Also, is there a way to move backwards equivalent to "Shift+Tab" in Notepad++?


  • 1
    As Luc Hermitte suggested, vimers use the 'indent' or 'indentation' keyword in this context. By tabs we mean something slightly different - a layout feature. For more help, see :help tabpage in vim.
    – vtest
    Mar 2, 2011 at 11:05

3 Answers 3


Start at the first line you want to indent, then press > and type the number of lines you want to indent and press > again (for 10 lines you'd press >10>) To un-indent you'd just use < instead of > (<10<)

  • 1
    Yes, that worked. Any way of doing that without first knowing how many lines I'd want to indent? Is there a way to select all the lines I want using the cursor and then issuing the command?
    – drapkin11
    Mar 1, 2011 at 23:28
  • I don't know about selecting lines, but you can use >> to indent just the current line, then use the 'repeat last command' key (.) on all subsequent lines ([down][.][down][.][down][.]) After a while you get quite fast at this ;)
    – Majenko
    Mar 1, 2011 at 23:47
  • 6
    @drapkin11: One way to select the lines you want to shift is to move the cursor to the first line, type V, then move the cursor to the last line. All the selected lines should be highlighted. Now type < to shift the selected lines left or > to shift right.
    – garyjohn
    Mar 2, 2011 at 0:15
  • @garyjohn, your suggestion works very well
    – drapkin11
    Mar 2, 2011 at 23:20

What you want are the > and < commands, see ":help shift-left-right".

You can use these commands in multiple ways, but since you specifically mentioned highlighting, you can just use your mouse or keyboard to highlight the lines you want to shift/unshift and press > or <.

Instead of using visual mode (highlight) you can provide a count and >> or <<. For example, 3>> will indent the current line and two lines below it.

  • Right, I did as you suggested in your 2nd statement, but for some reason when I press '<', my selected rows are just overwritten with the '<' character! Certainly not what I intend.
    – drapkin11
    Mar 1, 2011 at 23:33
  • It looks like you have mswin.vim sourced, which makes some things in Vim behave more like "standard" Windows editing dialogs/notepad.
    – Heptite
    Mar 2, 2011 at 1:25
  • 1
    @drapkin11, I believe @Heptite is correct about mswin. If you use V when highlighting rows you will not have this problem.
    – johnny
    Mar 2, 2011 at 6:51
  • @johnny, you are correct, the issue goes away. @garyjohn suggested the same solution which works for me.
    – drapkin11
    Mar 2, 2011 at 23:23

The preferred approach is to let vim perform auto-indentation. Don't forget this in your .vimrc:

set ai
filetype indent on

Then, if you open a file badly indented, you can then use the = command (in conjunction with a motion, e.g. gg=G to reindent the whole file, == to reindent the current line, =i{ to reindent the current {} block, etc.).

>> and << exist indeed, since the old and plain vi, but they are really cumbersome for real and long term editing.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .