Use this indent script in vim to indent your python files. It does what is recommended in PEP-0008. The code you have posted, indented with the script gives me this:
if settings.DEBUG:
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
}),
)
Moreover the type of indentation you want, is recommended if you do not have any argument on the first line. So rearranging the code and using the indent script gives:
if settings.DEBUG:
urlpatterns += patterns(
'',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
}),
)
Vim offers four increasingly complex and powerful methods to automatically indent text. In its simplest form, Vim behaves almost identically to vi’s autoindent option, and indeed it uses the same name to describe the behavior.,Slightly more powerful than autoindent, but it recognizes some basic C syntax primitives for defining indentation levels.,Auto indentation closely mimics vi’s autoindent. It differs subtly as to where the cursor is placed after indentation is deleted., Vim offers the following methods, listed in order of increasing sophistication:
You can choose the indentation method simply by specifying it in
a :set
command, such as:
: set cindent
As noted above, with 'foldmethod' set to indent, lines with the same level of indentation will be folded together. Note this means text like this: ,The 'foldmethod' option (abbreviated to 'fdm') is local to each window. It determines what kind of folding applies in the current window. Possible values are: ,Here is an alternative procedure: In normal mode, press Space to toggle the current fold open/closed. However, if the cursor is not in a fold, move to the right (the default behavior). In addition, with the manual fold method, you can create a fold by visually selecting some lines, then pressing Space. ,If you change the default 'foldmarker' setting, be sure to communicate the correct setting to other people in some way. An especially effective method for this would be to use a modeline, so that most Vim users will get your intended settings by default when they edit the file.
As noted above, with 'foldmethod' set to indent, lines with the same level of indentation will be folded together. Note this means text like this:
Line one Line two Line three Line four
will be folded as follows, which may not be expected:
Line one + Line two and three Line four
If you like the convenience of having Vim define folds automatically by indent level, but would also like to create folds manually, you can get both by putting this in your vimrc:
augroup vimrc
au BufReadPre * setlocal foldmethod = indent
au BufWinEnter *
if & fdm == 'indent' | setlocal foldmethod = manual | endif
augroup END
Here is an alternative procedure: In normal mode, press Space to toggle the current fold open/closed. However, if the cursor is not in a fold, move to the right (the default behavior). In addition, with the manual
fold method, you can create a fold by visually selecting some lines, then pressing Space.
nnoremap <silent>
<Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
vnoremap <Space> zf
Where to Put the Closing Brace, Bracket, or Parenthesis?,Where to Put the Closing Brace?,The reason is that both opening and closing braces (brackets, parentheses) should be placed in their own line.,So, how to correctly intend list or dictionary data enclosed in braces, brackets, and parentheses?
A quick example shows how you can create a multi-line construct that complies with the PEP 8 standard:
# PEP 8 Compliant age = { 'Alice': 24, 'Bob': 28, 'Ann': 26, }
1. Align the closing brace with the first non-whitespace character of the previous line:
# PEP 8 Compliant age = { 'Alice': 24, 'Bob': 28, 'Ann': 26, }
2. Align the closing brace with the first character that starts the multi-line construct:
# PEP 8 Compliant age = { 'Alice': 24, 'Bob': 28, 'Ann': 26, }
However, the PEP 8 standard allows NOT to place both opening and closing braces (brackets, parentheses) into their own line—IF the arguments or items align. Here are three PEP 8 compliant examples:
# PEP 8 Compliant
def f(argument_1, argument_2,
argument_3, argument_4):
None
# PEP 8 Compliant
def f(argument_1,
argument_2,
argument_3,
argument_4):
None
# PEP 8 Compliant
def f(argument_1, argument_2, argument_3, argument_4):
None
We’ve seen many examples of multi-line constructs where there’s a trailing comma after the last list element:
# PEP 8 Compliant age = { 'Alice': 24, 'Bob': 28, 'Ann': 26, }