I've installed the vim-flake8 plugin and it works correctly to lint Python in vim.

When I am on a particular line, I can use :call flake8#Flake8ShowError() and it will display the error in the vim ruler at the bottom.

I would like for this to be done automatically when my cursor moves over an offending line. Is this possible with a simple command added to .vimrc?

  • Check out :help CursorHold; you could install a buffer-local autocommand in Python files
    – D. Ben Knoble
    Jan 6 at 15:48
  • I put autocmd CursorHold *.py call flake8#Flake8ShowError() in .vimrc. It seems to work, but not ideal. I have to wait an arbitrary amount of time (a few seconds) and then move my cursor for it to display. I also tried CursorMoved but then vim runs slightly slower. Is there a way for it to run only when my cursor moves over an offending line, and only once?
    – efthimio
    Jan 7 at 7:35
  • There is an option (updatetime?) that controls the CursorHold time. For an offending line, how does Vim know until it’s called the function? And if it’s cached, you have to know when to invalidate the cache?
    – D. Ben Knoble
    Jan 7 at 21:08
  • @D.BenKnoble I'm a new contributor to this forum so I don't know the answer to these questions. I'm also curious if there is a way to read from the vim gutter since I configured it to display special characters in the gutter if there is an issue on an offending line.
    – efthimio
    Jan 7 at 22:52


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.