Thursday, January 20, 2011

Re: Indenting Python blocks

On 01/20/2011 06:51 PM, Daryl Lee wrote:
> Let's say I've decided to wrap an existing region in an if statement,
> meaning that region now needs to be indented another 4 spaces. In C I could
> select the region and press = and it's done. The only thing I've figured
> out in Python is to select the region and do
>
> :'<,'>s/^/ /

I haven't had to do that since I used "ed" :)

It looks like you're using PEP-8 "4-spaces per indent" (instead
of 1-tab or some other increment of spaces), so you want to set
your 'shiftwidth' and 'expandtab' settings accordingly:

:set sw=4 et

You can then use the "<" and ">" operators to indent/dedent over
a motion such as

>ip

to indent the "inner paragraph" or

3<<

to dedent 3 lines by one 'shiftwidth'. You can also use them in
visual mode to indent/dedent the selected text. For more
information, you can read up at:

:help 'sw'
:h 'et'
:h >
:h v_>

My ">ip" presumes you're familiar with text-objects:

:help text-objects

which, if you're not, are something that drives me nuts in other
editors when I *don't* have them. They're killer for productivity.

-tim


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: