how to indent blocks in vi using << and >>

Sean Reifschneider jafo at
Sat Mar 17 10:31:19 CET 2001

On Sat, Mar 17, 2001 at 04:10:04AM +0000, nspurrier at wrote:
>The >> indents a line right one tab and << indents a line left 
>one tab. You can indent a whole bunch of lines by giving a number

More precisely, ">" indents one *shift-width*.  If, for example you
do ":set sw=2 ts=8", that set's the swift width to 2 and the tabs to
8.  So, if you do a ">>", it will move it over two spaces while
leaving tabs set at 8.  I prefer ":set ts=3 sw=3" myself...

You say this is necessary for Python coding -- I actually found it just
as useful for coding in C and other languages.  People always seem
suprised by the fact that Python uses white-space for blocks.  I thought
it was weird before I used Python, but my coding style is so consistent
that I rarely have a problem (except when editing somone else's code).

>the number before the >> or <<. For example, 10>> will indent
>ten lines from the current cursor position.

Even better, you can move to the end of a block of code you want
to indent, do "ma", then move to the beginning and do "<'a" to
dedent that block, or ">'a" to indent it.  You can also do ">}"
to indent from the cursor to the next blank line, and ">{" to
indent to the PREVIOUS blank line.  Lotsa good stuff in there.
Don't forget "." to repeat the previous indent/dedent...

 Rocky: "I must be getting near-sighted!  You look all fuzzy..."
 Bullwinkle: "Let's face it, Rock...  I *AM* all fuzzy."
Sean Reifschneider, Inimitably Superfluous <jafo at> - Linux Consulting since 1995. Qmail, KRUD, Firewalls, Python

More information about the Python-list mailing list