Questions tagged [filetype-python]
Configuring and using vi/vim to edit python code. For scripting vim using python, use the /vimscript-python tag.
106
questions
1
vote
1
answer
150
views
What is the good errorformat or compiler plugin for pyright?
I'm using pyright for static checking. I do not use language servers and want to avoid that if I can.
I want to use quickfix with pyright and I'm wondering if there's an existing pyright compiler ...
0
votes
1
answer
57
views
How can I show inline IPython plots?
I want to plot matplotlib figures inline in ipython in the (wezterm) terminal.
In the terminal proper this works:
However, in Neovim, it does not:
In this question I was told it's not possible for a ...
1
vote
1
answer
81
views
How do I syntax highlight this comment as if it were Python?
I am currently working on a Python(-like) project which contains code like this:
def func():
"""
This is a docstring.
EXAMPLES::
sage: func()
1
"&...
4
votes
1
answer
389
views
Interactive python script development
I'm trying to replicate my vscode setup in neovim, but none of the options I have found seem to work.
Goal
A vertically split application. Left side: source code, split into cells with the # %% marker....
1
vote
0
answers
28
views
Modify ALE coloring for style errors
I am using neovim with ALE and I want to change the coloring of style errors in general for any language and particularly in python using flake8, in the following code of my configuration file I try ...
1
vote
0
answers
118
views
How to jump to a specific file and line from an error output in Neovim?
I use Neovim as an IDE for Python development. When I execute a Python script inside Neovim using the :terminal command, and an error occurs, I get an output similar to the following:
Traceback (most ...
0
votes
1
answer
42
views
How can I solve this wrong behaviour in gf command?
For some reason, on a specific project I work on (no per project configuration on my side). The gf command does a replacement of the last dot to slash, as if I'm in a Java file, even though it is a ...
1
vote
1
answer
431
views
Pyright LSP, leading spaces appears as " " in hover
I am using pyright LSP with the neovim (0.10.0-dev), and am seeing any leading spaces in docstrings replaced by . For example, see the attached image:
As far as I can tell it seems very ...
0
votes
1
answer
309
views
How do I disable snake_case naming style warning in ALE?
I want to disable annoying snake_case naming style warning:
invalid-name: Variable name "xxx" doesn't conform to snake_case naming style
Tried :help and grep snake_case, but didn't get ...
1
vote
2
answers
172
views
Integration of mypy and QuickFix window
I would like to have a keyboard shortcut to
run mypy on the current buffer
put the output in the QuickFix window
I only want mypy to run and populate the QF window on demand, not constantly. I do ...
0
votes
1
answer
41
views
Semantic completion does not work for argparse.Namespace
I have a problem with the semantic completion for specific class argparse.Namespace with YouCompleteMe.
Here's a minimal repro case I can provide:
# .vimrc
silent! call plug#begin()
Plug 'ycm-core/...
1
vote
1
answer
243
views
How can I enable highlighting such that all Python variables use the same color?
When I was using VSCode as my main code editor, many extensions like The One Dark Pro theme offered variable highlighting.
This is not Semantic highlighting, where each variable is assigned its own ...
3
votes
2
answers
217
views
How to see command lines and output for linters, etc
I've used vim and python for decades, but since Syntastic has been deprecated, I recently switched to ALE.
I'm coding in Python 3.11 and running vim 8.1 under Linux Mint, and have created a virtual ...
1
vote
1
answer
148
views
How to replace the default python syntax in Neovim without a plugin manager?
As the title, I would like to replace the default python syntax with the more modern one in https://github.com/vim-python/python-syntax.
I managed to do this in Neovim 0.9.4 with the vim-plug plugin ...
0
votes
1
answer
26
views
How to configure repmo such that it works with ]m and pythonsense?
I would like to jump from method to method in Python. With Vim you can use the ]m combination to jump to the next method and the [m to the previous.
Since the ] is quite awkward to type on a Belgium ...
2
votes
1
answer
97
views
Wrong indentation in brackets
How can I change the automatic indentation inside brackets? Without any configuration, {vim,nvim} does the following:
test = [| # Press enter
test = [
| # Cursor ends up here, at the same ...
1
vote
1
answer
194
views
What is the difference between `au BufNewFile,BufRead *.py` and `au Filetype python` in this specific case?
The issue
Consider the following two Vimrc configuration lines for the YouCompleteMe plugin:
au BufRead, BufNewFile *.py,*.pyw match BadWhitespace /\s\+$/
au FileType python match BadWhitespace /\s\+$...
0
votes
1
answer
309
views
How to display vim-test output in a quickfix window?
I have installed vim-test, and setup the following pytest executable in my .vimrc:
let g:test#python#pytest#executable = 'python3 -m pytest'
When I call :TestFile, pytest runs in a background shell ...
1
vote
2
answers
292
views
ALE Code Action for python
I have a working linter with the ALE plugin.
Plugin 'dense-analysis/ale'
let g:ale_virtualtext_cursor = 0
let g:ale_python_flake8_options = '--extend-ignore=E501'
nnoremap <leader>ar :ALERename&...
3
votes
3
answers
133
views
Auto-fix missing Python f-string prefix in insert mode
I am constantly forgetting to add the f prefix in Python when I'm within a string and start inserting a variable ("foo bar {var}").
I then do: <ESC>F"if<ESC>f{a and finish ...
2
votes
2
answers
262
views
How to get the right indent size in python lists?
In my vimrc I have filetype indent plugin on
When I write python code, the indentation mostly looks good, but in lists it is too big:
def fun():
return 'indent looks good'
my_list = [
'...
3
votes
1
answer
219
views
How to set g:python_indent.disable_parentheses_indenting?
:help ft-python-indent lists the following command:
let g:python_indent.disable_parentheses_indenting = 1
but when I try to use that in my config I am getting the error message
E121: Undefined ...
1
vote
1
answer
344
views
Small issue when running Python code straight from VIM
I want to be able to set up the hot key \\ to be able to write and run python script from VIM without each time having to type in
:w
:! python3 file.py
What I have done so far is pasted the following ...
1
vote
1
answer
101
views
Replace arithmetic expression by their result
I am just trying to replace several arithmetic expressions inside a script file, which I cannot seem to find a simple solution for on the web.
Adapting this answer did not do the trick.
Suppose I have ...
1
vote
0
answers
2k
views
Ho to force the pyright language server to use a interpreter on a mounted volume
I have a problem with the following setup:
the volume of a remote machine is mounted using sshfs
nvim is opened on the mounted volume to ensure all my plugins and settings work
~/anaconda3/envs/.. is ...
0
votes
1
answer
191
views
Replace interpolated variables in Python string with positional formatting strings
How do I, with one regex, transform:
logger.info(f"Foo {alpha}")
logger.info(f"Foo {alpha} bar {beta}")
logger.info(f"Foo {alpha} bar {beta} baz {gamma}")
Into:
logger....
2
votes
1
answer
122
views
How to change the color of the prefix "b", "r", "f" or "u" before strings?
Is there any way to do this ? I'm using vim 8.2 with this python plugin.
The inside of f strings for example is correctly highlighted but not the "f"
3
votes
0
answers
375
views
How to select a python interpreter in vim
I have multiple versions of python on my ubuntu system, python2.7 which is default one and i have installed python3.8. I have a python module installed in python3.8 which is not installed in python2.7....
0
votes
0
answers
87
views
How dose colorscheme file working when python.vim file not exist?
I deleted python.vim in ~./Vim/vim82/syntax directory, and define colorscheme.vim in ~./Vim/vim82/colors directory.
The colorscheme.vim contain this code
call <sid>hi('pythonNumber', s:...
1
vote
2
answers
2k
views
No fold found with Python code, Mac and Debian
I'm trying to get vim to do code folding with my python code and I could really use your help with the last bit here.
I have this in my ~/.vimrc:
set number
"set tabstop=2
"set expandtab
&...
1
vote
1
answer
912
views
Convert print statements to log statements using a custom mapping
I want to write or find a plugin that helps me convert print statements to log statements in Python 3.
Consider a situation:
I am writing some code, I want to add a feature based around some API, I ...
1
vote
1
answer
268
views
Why is my setting of `set softtabstop` in vimrc being clobbered when editing python files?
I am using vim 8.0.1763 on CentOS 8.1. Here is my ~/.vimrc
" Cool vim plugins : http://vimawesome.com/plugin/fugitive-vim
set number
filetype plugin on " https://stackoverflow.com/questions/...
1
vote
0
answers
31
views
Signature pop-up describes dataclass as "The most base type"
I'm using coc-python for Python IDE-like features.
If I define a dataclass I would expect the signature pop-up to show me which fields an instance of this class expects.
Instead I get:
MyClass()
------...
3
votes
2
answers
335
views
Debug how vim calls makeprg
I'm trying to set up pylint to work with :make command in Vim 8.2.
I've set :compiler pylint but running :make gives me pylint's help message, so some arguments seem to be passed incorrectly.
:set ...
0
votes
1
answer
50
views
What's the fastest way to go about defining functions in Python?
def counter(num):
I always get stuck inside of the parenthesis and find myself pressing ESC, going back to Normal mode, then pressing A to append the colon to the end of the line. Is there a faster ...
2
votes
1
answer
352
views
Jump to definition in Python using static code analysis
I wonder if there is a way to jump to Python method definition in VIM using static code analysis (as described in https://gist.github.com/igemnace/dfa545d0d71228e010876d48a420a50b).
For example, if I ...
4
votes
3
answers
5k
views
How do I display a Python docstring in Vim
I've recently decided to give Vim a try and am trying to get it set up for work with Python.
I've installed YCM, so I have autocompletion now, which is good, but there are a few things documentation-...
3
votes
0
answers
3k
views
View pylint errors using coc and neovim
For the following code there is an error in the gutter, but I don't know how to view the actual message for it.
Similarly here:
In the bottom right of the editor are warnings and errors:
But I don'...
10
votes
3
answers
21k
views
How to format files on save using black with neovim and coc
I'm trying to have python files format on save using black and neovim, with coc.
Coc config
I have the following coc config:
{
"coc.preferences.useQuickfixForLocations": true,
"coc....
0
votes
1
answer
333
views
Python script not running through vim but runs on Windows CMD
I have recently switched to vim from VS Code. I have Vim 8.2.
I have put these lines in my _vimrc file so that I can run python in vim by pressing F9:-
autocmd FileType python map <buffer> <...
1
vote
1
answer
139
views
Start vim-coverage when opening a python file
If I run the command CoverageShow coverage.py when I have a python file open and a .coverage report in my directory it does a nice job of showing me which lines are included in my testing.
I would ...
2
votes
2
answers
705
views
How to exclude a pattern between a pair of parentheses?
I have the following Python code
z=xyz%10
gvu.set_ticks(ax, xticks=[45, 50],
yticks=[-25, -20, -15])
After this substitution, in visual mode
:s/\([^=]\)\ *\(=\)\ *\([^=]\)/\1 \2 \3/g
...
4
votes
1
answer
227
views
Vim thinks Python @ operator is decorator
Python3 has the matrix multiplication operator (@) which is used to multiply numpy matrices. But when we write something like A = B @ C in vim, the @ C portion gets highlighted. Apparently Python has ...
1
vote
1
answer
2k
views
Autocmd with a python file not working
I'm using the regular Vim that comes with Ubuntu.
I have the following line of code in my .vimrc:
autocmd filetype py nnoremap <F10> :w <bar> !python3 %<CR>
It's not working, ...
1
vote
1
answer
254
views
How to easily switch flake8 between python 2 and 3
I'm working with python 2.7 scripts that I need to update to python 3.8 while maintaining backwards compatibility. vim-flake8 on my mac has been working great up until now for python 2.7, but I can't ...
15
votes
2
answers
22k
views
How can I configure Black the python code formatter to indent 2 spaces instead of 4?
I'm using the psf/black plugin, I install and load it with vimplug: Plug 'psf/black'
and I use it with <leader>f: autocmd FileType python nmap <leader>f :Black<CR>
I use and prefer ...
3
votes
3
answers
424
views
Pretty python comments
I comment sections in python via a centered title surrounded by #. What I would like is to make a command so that I can automatically generate such headers. For example, to generate a line like the ...
1
vote
1
answer
2k
views
Python Language Server Protocol with virtual environment
Can anyone help me get things like "Go to definition" working with Neovim and Python virtual environments?
My setup currently uses a specific virtual environment for Neovim (as recommended by :...
1
vote
1
answer
846
views
getting vim to autocomplete python methods
I am coming from statically types languages, but I will have to be using python for the next few years and I want to get my setup as smooth as possible.
Right now I am using vim-jedi, and deoplete-...
2
votes
1
answer
3k
views
Correct way to setup python version for coc
I want to set PYTHONPATH and python interpreter according to projects I am working on. I am working both on projects involving python 2.0, and ones involving python 3.0.
There is the concept of ...