flake8-vim
If you want to make the source code look beautiful, and if you write Python for the time being, pep8 should be protected.
When playing with the source code of the time when the coding style was not unified, or when pep8 gets angry at the source code in the middle of writing, it is troublesome to manually format them. If it's a hassle, no one will protect it, so if you use an IDE or stick to an editor, install an auto-formatting plugin.
If you have a new project, you can force it to autopep8 every time you save it, but if you don't want to do it, you may be in trouble.
There is a module called autopep8 that can get rid of all that. However, it is troublesome to use such a module as it is, so let's use the Vim plugin so that it can be used through an editor. andviro / flake8-vim also provides functions for autopep8 along with flake8.
With flake8-vim installed, select the line you want to edit and run :'<,'> PyFlakeAuto
.
#Before
def main():
d={
'a':111,
'b':'cc',
'c': 12
}
if 0: print 1
foo = 'aa'+'bb'
return aa
#After
def main():
d = {
'a': 111,
'b': 'cc',
'c': 12
}
if 0:
print 1
foo = 'aa'+'bb'
return aa
It's like that. It also removes the trailing space soberly. I just noticed that the ʻE226 missing whitespace around arithmetic operator [pep8]` below isn't resolved, but this may be a bug in autopep8. Let's do something appropriately later.
For vimmer, which has many lazy boys, redundant operations such as selecting a range with v
and executing a command are unbearable penances.
That's why I also include operator and textobj that seems to be useful.
The rest is appropriate
map ,p <Plug>(operator-autopep8)
If you put in settings like, the previous operation can be solved with a simple key binding of , paf
. Moreover, the same operation can be performed no matter how many lines the function body has.
Besides, it is quite convenient to try to fix the indent collapse of the dictionary literal (, pa {}
).
We need to consider sea otters and dolphins through this kind of eco.
Recommended Posts