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
[] ...
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 ...
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 ...
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 ...
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 ...
12
votes
Accepted
Python debugging
For me vimspector looks amazing, and has out-of-the-box Python support.
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 ...
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 ...
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 ...
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 ...
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.
...
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 ...
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 ...
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 ...
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 ...
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 ...
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/...
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 ...
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/...
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 ...
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)...
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 ...
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) ...
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,
...
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.
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 ...
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['...
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 ...
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
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
filetype-python × 106syntax-highlighting × 17
neovim × 13
vimrc × 12
indentation × 11
autocompletion × 6
plugin-you-complete-me × 5
plugin-ale × 5
python × 5
regular-expression × 4
filetype × 4
formatting × 4
quickfix × 4
plugin-coc × 4
key-bindings × 3
folding × 3
ide × 3
lsp × 3
plugin-python-mode × 3
vimscript × 2
plugin-system × 2
macvim × 2
whitespace × 2
tab-characters × 2
makeprg × 2