tags:

views:

21602

answers:

9

Should be trivial, and it might even be in the help, but I can't figure out how to navigate it.

Thanks in advance.

+98  A: 

Use the > command. To indent 5 lines, 5>>. To mark a block of lines and indent it, Vjjj> to indent 3 lines (vim only). To indent a curly-braces block, put your cursor on one of the curly braces and use >%.

If you're copying blocks of text around and need to align the indent of a block in its new location, use ]p instead of just p. This aligns the pasted block with the surrounding text.

Greg Hewgill
<shift>-v also works to select a line in Vim.
akdom
akdom: thanks, fixed that.
Greg Hewgill
I had no idea! And I've used it for YEARS. -frown- Tnx for the tips...
Richard T
@akdom: interesting; that ('V') was always a key that I used for maps because it had no other use (v and g were two others).
Jonathan Leffler
I use >i} (indent inner {} block). Works in vim. Not sure it works in vi.
Martinho Fernandes
@Greg: consider adding to your answer that using set shiftwidth=' ' you can define the indentation size (default is 8) when using < or >
Roman M
I had been using control-v to indent by navigating to the front of the line but this is clearly much better.
Brandon Thomson
@Martinho: text objects, like i} are Vim-specific. Then again, so is visual mode.
jamessan
+11  A: 

In addition to the answer already given and accepted, it is also possible to place a marker and then indent everything from the current cursor to the marker. Thus, enter ma where you want the top of your indented block, cursor down as far as you need and then type >'a (note that "a" can be substituted for any valid marker name). This is sometimes easier than 5>> or vjjj>.

Daniel Spiewak
+6  A: 

As well as the offered solutions, I like to do things a paragraph at a time with >}

Paul Tomblin
+22  A: 

Also try this for "C-indenting" indentation, do ":help =" for more info:

={

That will auto-indent the current code block you're in.

Or just:

==

to auto-indent the current line.

svec
A: 

:help is your friend. Use hjkl to move the cursor, CTRL-] in :help to jump to a term's help entry, CTRL-SHIFT-O to jump back. See :help > for your question.

rampion
Ctrl-t is actually what should be used to move backwards through the tag stack. Ctrl-o (no shift needed) is how you move backwards through the jumps stack.
jamessan
+4  A: 

Key-Presses for more visual people:

[Escape]      # Enter Command Mode
# move around to the start of the area to indent 
[h][j][k][l][up][down][left][right]   
[v]           # start a block 
# move around to the end of the area to indent
[h][j][k][l][up][down][left][right]   
[0..9]     # ( Optional ) Type the Number of indentation levels you want 
[>]        # execute the indentation on the block
Kent Fredric
+10  A: 

A big selection would be

gg=G

it is really fast, and everything gets indented ;-)

Johan
I love this personally. :)
Robert Massaioli
+2  A: 

when you select a block and use > to indent, it indents then goes back to normal mode. I have this in my .vimrc :

vnoremap < <gv

vnoremap > >gv

It lets you indent your selection as many time as you want.

mike
To indent the selection multiple times, you can simply press . to repeat the previous command.
sundar
hahaha, i'm such a noob!
mike
+1  A: 

do this $vi .vimrc and add this line autocmd FileType cpp setlocal expandtab shiftwidth=4 softtabstop=4 cindent

this is only for cpp file you can do this for another file type also just by modifying the filetype...

pankaj ukumar