27 votes
Accepted

End of python block motion

With the update from November 2017 of $VIMRUNTIME/ftplugin/python.vim following ft-specific motions are available for the python language [[ Jump backwards to begin of current/previous toplevel [] ...
Hotschke's user avatar
  • 4,740
19 votes
Accepted

How to format files on save using black with neovim and coc

This is a coc.nvim setup procedure that works for Neovim, which aims to: Use coc-pyright as language server. Provide static type checking from a Python virtualenv (e.g. I have created a venv called ...
Gordon Bai's user avatar
18 votes
Accepted

How can I fix "missing" syntax highlighting for Python keywords such as "self"?

How syntax highlighting works in brief: In syntax/<filetype>.vim the syntax rules are defined with the :syntax command. This command defines, well, syntax. It says "if text matches this regular ...
Martin Tournoij's user avatar
17 votes
Accepted

Vim doesn't use the correct indentation in Python files

It gets reset by the Python filetype plugin; from /usr/share/vim/vim74/ftplugin/python.vim: " As suggested by PEP8. setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8 This file is loaded ...
Martin Tournoij's user avatar
14 votes
Accepted

Vim syntax pattern to highlight python keyword argument

With these settings: syn region FCall start='[[:alpha:]_]\i*\s*(' end=')' contains=FCall,FCallKeyword syn match FCallKeyword /\i*\ze\s*=[^=]/ contained hi FCallKeyword ctermfg=yellow I get: Here: ...
muru's user avatar
  • 24.8k
14 votes

Quickfix support for Python tracebacks

Built in compiler plugin pyunit As already suggested by jamessan, one option is to use the built in compiler plugin pyunit: :compiler pyunit :set makeprg=python3\ % :make This has the downside, that ...
siho's user avatar
  • 241
13 votes
Accepted

Why is "set noexpandtab" in my ~/.vimrc ignored when I open a file?

It is not ignored, it is overwritten by your filetype plugin. In this case the python plugin. You can verify that like Marth said, with the :verbose command: :verbose set expandtab? If you want to ...
B.G.'s user avatar
  • 1,116
12 votes
Accepted

Python debugging

For me vimspector looks amazing, and has out-of-the-box Python support.
Shay Palachy Affek's user avatar
11 votes

How can I configure Black the python code formatter to indent 2 spaces instead of 4?

The whole point of Black is that it is not configurable. It calls itself "the uncompromising code formatter". Its name comes from the Henry Ford quote about the Model T: "any color you ...
Marty's user avatar
  • 111
10 votes

Python debugging

There are alternatives. Plain ol' pdb can be integrated into vim with vimpdb vebugger, etc (My own favourite) pudb can be integrated with pudb.vim vim-pudb And the popular ipdb can be integrated ...
jalanb's user avatar
  • 684
9 votes
Accepted

Quickfix support for Python tracebacks

Vim comes with a set of "compiler" scripts, one of which is called "pyunit". If you run :compiler pyunit and then :make (with your suggested value for 'makeprg'), quickfix is ...
jamessan's user avatar
  • 11k
8 votes
Accepted

Incorrect auto-indent in python code

In this case, the auto-indentation seems confused because the def __init__() is indented by four spaces, while the others are indented by two spaces. This is valid Python, but the Vim Python ...
Martin Tournoij's user avatar
8 votes

Vim syntax pattern to highlight python keyword argument

Here is where you can start from: /([^,]\+,\s\(\w\+\)=.*) Decomposing: /( start matching a ( [^,]\+ match multiple characters that are not , ,\s match a , and a space \( start a ...
nobe4's user avatar
  • 16k
8 votes
Accepted

Automatic whitespace in python

You want to have this setting: " ---- Minimal configuration: set smartindent " Do smart autoindenting when starting a new line set shiftwidth=4 " Set number of spaces per auto indentation set ...
Nales's user avatar
  • 198
7 votes
Accepted

Plugin for vim that auto indents after a : when editing python?

Try adding the following lines to your .vimrc: syntax on filetype plugin indent on N.B. The plugin is not necessary for indenting, but it enables filetype plugins to run, which you probably want. ...
Rich's user avatar
  • 31.7k
6 votes

How to set the relative indent after breaking Python lines?

The script that controls Vim's indentation of Python files is located at $VIMRUNTIME/indent/python.vim. You can see the help file for it with :help ft-python-indent. From that, we learn there are a ...
Gonçalo Ribeiro's user avatar
6 votes

Vim syntax pattern to highlight python keyword argument

In addition to @Nobe4 answer you could do the following: Create the file ~/.vim/after/syntax/python.vim Put theses line in the file: syntax match PythonArg /(.*\,\s*\zs\w\+\ze\s*=.*)/ hi PythonArg ...
statox's user avatar
  • 49.6k
6 votes
Accepted

Strange Fold Info Showing in Gutter

What you see is the 'foldcolumn' setting for opened folds. If you don't want it, simply disable it: :set foldcolumn=0 To find out where it was set, enter :verbose set foldcolumn? You might also play ...
Christian Brabandt's user avatar
5 votes

Test python function from within editor

Not really a "Vim answer", but writing a unit test and running the unit test(s) for the current file is probably the best way to do this. Specifically for Python you can use doctests: import ...
Martin Tournoij's user avatar
5 votes
Accepted

How can I remove a syntax keyword?

(Note: the Python 2 keywords were removed in February 2021 with Vim 8.2.2554). You'll have to look at the syntax file and undo what it's doing. You can find the syntax file with :e $VIMRUNTIME/syntax/...
Martin Tournoij's user avatar
5 votes
Accepted

Closing error window

It's aquickfix window, and you can close it with the command :cclose. The above is rubbish, and I apologise for answering too hastily. All the yapf plugins I found seem to work by replacing your ...
Rich's user avatar
  • 31.7k
5 votes
Accepted

Is there a % equivalent for editing python code?

That functionality is provided by the matchit plugin that is bundled with Vim. The distributed C filetype plugin includes the configuration b:match_words that defines those jumps for the matchit ...
Christian Brabandt's user avatar
4 votes
Accepted

How to check the syntax of a file on the fly?

If you're using Vim 8 or Neovim, you can use Asynchronous Lint Engine. Note that it doesn't work well with Syntastic (source): ALE conflicts with Syntastic. Uninstall it, or disable this warning ...
amigcamel's user avatar
  • 156
4 votes

Quickfix support for Python tracebacks

quickfix.py parses the traceback into a vim-friendly errorformat. Here is an example of running it on a file with a single line 1 / 0. ❯❯❯ quickfix.py tests/errors/div_by_zero.py "tests/errors/...
jadelord's user avatar
  • 141
4 votes

Vim Code Completion for Python 3

Since a couple of weeks, YouCompleteMe does support Python3 completion using Jedi via a JediHTTP wrapper. Only install YouCompleteMe (no need to install jedi-vim) according to the installation ...
cbaumhardt's user avatar
  • 2,119
4 votes
Accepted

How to disable automatic unindent of comments in Python?

Typing the # character causes an outdent because you have set 'smartindent', which is designed for C-like languages (where # indicates the start of a preprocessor directive). Quoting from the output ...
Rich's user avatar
  • 31.7k
4 votes
Accepted

How can I highlight all function names in Python files?

A regexp that seems to work well is: \v[[:alpha:]_.]+\ze(\s?\() Or for syntax highlighting (see How can I add additional syntax highlighting rules in my local vimrc? on how to add this to your vimrc)...
Martin Tournoij's user avatar
4 votes

Vim python debugger

I have successfully used vdebug for php and python, it provides the UI inside vim to visually step through the code, see stack traces, evaluate expressions, etc. But unfortunately, it's quite complex ...
Borys Serebrov's user avatar
4 votes

Show python help() inside vim

It is built-in, have a look at :h K, it says K Run a program to lookup the keyword under the cursor. The name of the program is given with the 'keywordprg' (kp) ...
statox's user avatar
  • 49.6k
4 votes
Accepted

How do I configure syntastic to use Python3 in Ubuntu?

Using Ubuntu, I couldn't figure out what was calling python or to change the default environment for all instances of syntastic. That would have been desirable. Instead what I did was install flake8, ...
Evan Carroll's user avatar
  • 1,244

Only top scored, non community-wiki answers of a minimum length are eligible