Skip to main content
29 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,830
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
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,186
12 votes
Accepted

Python debugging

For me vimspector looks amazing, and has out-of-the-box Python support.
Shay Palachy Affek's user avatar
12 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
  • 121
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

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
  • 308
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
  • 11.2k
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
  • 32.4k
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
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
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
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
  • 32.4k
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
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
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
  • 32.4k
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
  • 50.4k
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,483
4 votes
Accepted

How to highlight unused Python imports in VIM

Flake8 already supports checking for unused imports and is integrated with Syntastic. Python developers should make sure to install flake8 into their user or virtual environment.
D. Ben Knoble's user avatar
  • 27.2k
4 votes

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

It looks like the Black Python code formatter intentionally does not allow you to configure whether to use 2 or 4 spaces, which makes me wonder why, I can't imagine this change requiring anything ...
Wis's user avatar
  • 373
4 votes
Accepted

How to set g:python_indent.disable_parentheses_indenting?

The . syntax is an alternative to access a dictionary value associated to a key. let g:python_indent.disable_parentheses_indenting = 1 Is equivalent to: let g:python_indent['...
Vivian De Smedt's user avatar
3 votes
Accepted

Mapping to execute python file only works on first buffer

Your mapping use <buffer> which means that it creates a mapping which is local to a buffer (and thus doesn't exists in other buffers). As the command is in your vimrc the mapping only exists on ...
statox's user avatar
  • 50.4k
3 votes

Vim doesn't use the correct indentation in Python files

Solution for me was to add this line after the filetype plugin on into my ~/.vimrc file filetype plugin on autocmd FileType python setlocal noexpandtab shiftwidth=4 softtabstop=4
Philippe Gachoud's user avatar
3 votes

Vim syntax pattern to highlight python keyword argument

I found that @Wolfie's answer captures unwrapping of a tuple as a keyword and it also had trouble capturing linebroken keyword arguments. Inspired by his regex I came up with the following to put in ...
ludo's user avatar
  • 31

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