Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8081521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:45:12+00:00 2026-06-05T16:45:12+00:00

Background: I’m using the (fantastic) Vim plugin python-mode , which includes the pep8 linter.

  • 0

Background:

I’m using the (fantastic) Vim plugin python-mode, which includes the pep8 linter. The :PyLint command runs all linters and opens errors in a QuickFix window.

Problem:

Now, let’s assume I’m only using the pep8 linter, and I have a QuickFix window full of errors. I’d like to step through each of these errors and apply an automatic fix (with something like autopep8). The autopep8 tool is fantastic, but it makes mistakes. Ideally, I’d like to be able to supervise each fix in Vim (apply fix, check, move to next fix).

My current approach is to run autopep8 on my Python file, diff the results, then repair any bad changes:

$ autopep8 --in-place spam.py
$ git difftool spam.py  # check edits in gVim, write to file
$ git commit spam.py -m "Fix bad PEP8 formatting"

However, this approach ruins my undo history, and seems needlessly complex. Is there a better way?

Question:

Is there any way to automatically apply pep8 fixes (when available) to pep8 errors within the QuickFix window?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:45:14+00:00Added an answer on June 5, 2026 at 4:45 pm

    Options

    There are two simple answers that won’t wipe out your undo history.

    1. Diff with the saved file in Vim

    I found this DiffWithSaved function online quite a while ago and it has been very useful. In this case, you can just run autopep8 in the terminal, and when Gvim asks to reload the file, choose no and then run this function, which will pop up a scratch buffer with your new file and allow you to change things around.

    " copy this to your vimrc or source it
    
    " tells vim not to automatically reload changed files
    set noautoread 
    
    function! DiffWithSaved()
      let filetype=&ft
      diffthis
      vnew | r # | normal! 1Gdd
      diffthis
      exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
    endfunction
    
    " sets up mappings to function
    
    com! DiffSaved call DiffWithSaved()
    map <Leader>ds :DiffSaved<CR>
    

    Once you run that, you can use the vim copy-diff and other diff commands to quickly go through and accept/not accept changes. Plus, all will be stored in undo history.

    " run these commands after sourcing the above function
    
    " % expands to filename (also %:h to head, %:t to tail)
    " if it throws an error, just do :cd %:h first
    
    :!autopep8 --in-place %
    :DiffSaved
    

    2. Diff with the git difftool and reload the file

    If you want to diff with the file in the git index (and using git’s difftool), you could do the following:

    1. leave gvim open,
    2. run your commands in the terminal and let the program open up a new instance of gvim (or vim) to handle the diffing.
    3. Save it all.
    4. Go back to your original gvim, let vim reload the file and (at least to my knowledge) your undo history should remain.

    Advantages/Disadvantages

    Option 1

    Advantages:

    • each change will be saved in your undo history
    • graphical diffs in vim are easy to read

    Disadvantages:

    • Won’t be using git’s difftool
    • relies upon vim’s diff functions.

    Option 2

    Advantages:

    • uses git’s difftool
    • cleaner undo history (single undo from pre and post autopep8–very dependent on what you want)

    Disadvantages:

    • seems more awkward
    • less granular undo history
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

BACKGROUND I'm using VS 2010 on a machine where I installed .Net 4.5 which
Background: Our web app uses the jquery.constrain.js plugin to handle data entry in some
Background: Sometimes when editing in vim it is possible to have extra characters in
Background I have a ror application which is continuously recording and showing on a
Background: I am developing an app which sends an SMS to users after registration
Background Windows 7 x 64 Python 2.7 Django 1.4 Celery with Redis bundle While
[background below] I've got my data modelled out in SQLObject in Python on the
Background: I am using Eclipse to develop an Android app. I have an xml
Background: At my company we are developing a bunch applications that are using the
Background I am writing and using a very simple CGI-based (Perl) content management tool

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.