> I am a C/C++-programmer.
> And I a first time tourist in the world of python.
welcome to my favorite language :)
> Since python does not have start-/end-of-block
> marker a la "{}" in C: How can I indent a
> block of code? How does vim know, how large
> such a block is, where it starts and where it
> ends? How can I acchieve, what "==" does for
> C/C++-code?
Because C-like languages use secondary indicators for block
identification ({...}), the reformat commands in vim take the
known block structure and makes indentation match. Because
python uses indentation *as* the block identification, your
question becomes akin to "how do I get vim to automatically
insert '{' and '}' in my C code where I want them?". And the
[un?]fortunate answer is that you can't -- it involves knowing
the programmer's intent.
It took me all of 5 minutes to get past the "aagh, there are no
block-delimiters other than indentation" aspect of Python and I
realized that I already indented my C-like languages exactly as I
did my Python, so I was saving typing and the possibility of
getting my braces out of sync with my intent. The "dangling
else" is notorious in C-like languages (yes, coding standards
that require braces for both if/else parts help, but you become
redundant when you add braces *and* indentation), where you have
if (condition)
do_a();
else
do_b();
do_c();
The indentation shows the programmer's indent, but the parser
doesn't understand that and instead sees
if (condition)
{
do_a();
}
else
{
do_b();
}
do_c();
By relying on indentation, Python does what the developer
intended/expected.
Anyways, enough rambling about python for me. Off to bed :)
-tim
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---