A Vim plugin that automatically formats Python styles

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.

Introduction of operator

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

A Vim plugin that automatically formats Python styles
Write a vim plugin in Python
Write a simple Vim Plugin in Python 3
Create a plugin to run Python Doctest in Vim (2)
Create a plugin to run Python Doctest in Vim (1)
Create a Wox plugin (Python)
A general-purpose program that formats Linux command strings in python
Automatically format Python code in Vim
[Python] A program that creates stairs with #
A Python script that automatically collects typical images using bing image search
[Python] I wrote a simple code that automatically generates AA (ASCII art)
[Python] Create a LineBot that runs regularly
A typed world that begins with Python
Let's create a customer database that automatically issues a QR code in Python
A program that plays rock-paper-scissors using Python
PGM that automatically creates a walking route
[Python] A program that rounds the score
Create a plugin that allows you to search Sublime Text 3 tabs in Python
Create a Vim + Python test environment in 1 minute
[Python] A tool that allows intuitive relative import
A nice nimporter that connects nim and python
Nogizaka46 A program that automatically saves blog images
Create a page that loads infinitely with python
Publish a Python module that calculates meteorological factors
"Python Kit" that calls a Python script from Swift
Split files when writing vim plugin in python
PGM that automatically creates a walking route
Nogizaka46 A program that automatically saves blog images
A Vim plugin that automatically formats Python styles
A simple system that automatically shoots with object detection and sends it to LINE
[Python] A program that counts the number of valleys
I made a VM that runs OpenCV for Python
Python that merges a lot of excel into one excel
From a book that programmers can learn ... (Python): Pointer
What's in that variable (when running a Python script)
Created a Python library DateTimeRange that handles time ranges
[Python] How to write a docstring that conforms to PEP8
A server that echoes data POSTed with flask / python
I tried to automatically generate a password with Python3
A function that easily calculates a listwise removal tree (Python)
[Python] A convenient library that converts kanji to hiragana
A memo that I touched the Datastore with python
Using a Python program with fluentd's exec_filter Output Plugin
[Python] A program that compares the positions of kangaroos.
A Python program that converts ical data into text
MALSS, a tool that supports machine learning in Python
Using a python program with fluentd's exec Output Plugin
[Python] Creating a GUI tool that automatically processes CSV of temperature rise data in Excel
A program that automatically resizes the iOS app icon to the required image size in Python
Let's create a program that automatically registers ID/PW from CSV to Bitwarden with Python + Selenium