Skip to main content

Questions tagged [filetype-python]

Configuring and using vi/vim to edit python code. For scripting vim using python, use the /vimscript-python tag.

Filter by
Sorted by
Tagged with
0 votes
1 answer
26 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 ...
Guilherme Marthe's user avatar
0 votes
1 answer
80 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 ...
Fisher's user avatar
  • 1,086
0 votes
2 answers
89 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 ...
backseat's user avatar
  • 121
1 vote
1 answer
71 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 ...
IvanProsperi94's user avatar
2 votes
1 answer
81 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 ...
Elevator9253's user avatar
1 vote
1 answer
130 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\+$...
Attilio's user avatar
  • 369
0 votes
1 answer
221 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 ...
Paul Rougieux's user avatar
1 vote
2 answers
227 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&...
Surya's user avatar
  • 21
3 votes
3 answers
115 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 ...
Ryan's user avatar
  • 151
2 votes
2 answers
224 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 = [ '...
Burrito's user avatar
  • 131
3 votes
1 answer
182 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 ...
jakun's user avatar
  • 155
1 vote
1 answer
301 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 ...
alpastor's user avatar
  • 115
1 vote
1 answer
85 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 ...
winkmal's user avatar
  • 185
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 ...
cal's user avatar
  • 21
0 votes
1 answer
152 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....
Aurelia Peters's user avatar
2 votes
1 answer
117 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"
NicoAdrian's user avatar
3 votes
0 answers
359 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....
Manoj's user avatar
  • 131
0 votes
0 answers
85 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:...
hibernation's user avatar
1 vote
1 answer
670 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 ...
Ayush Mandowara's user avatar
1 vote
1 answer
244 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/...
irritable_phd_syndrome's user avatar
1 vote
0 answers
29 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() ------...
LondonRob's user avatar
3 votes
2 answers
304 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 ...
xaxa's user avatar
  • 177
0 votes
1 answer
49 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 ...
kiabbo's user avatar
  • 1
2 votes
1 answer
333 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 ...
niekas's user avatar
  • 1,575
4 votes
3 answers
4k 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-...
Daniel's user avatar
  • 181
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'...
baxx's user avatar
  • 1,025
10 votes
3 answers
20k 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....
baxx's user avatar
  • 1,025
0 votes
1 answer
323 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> <...
Rohan's user avatar
  • 1
1 vote
1 answer
129 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 ...
Clumsy cat's user avatar
2 votes
2 answers
580 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 ...
sfx's user avatar
  • 33
4 votes
1 answer
222 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 ...
Akhil's user avatar
  • 41
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, ...
Xander's user avatar
  • 11
1 vote
1 answer
239 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 ...
Lagix's user avatar
  • 11
14 votes
2 answers
20k 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 ...
Wis's user avatar
  • 363
3 votes
3 answers
403 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 ...
Throckmorton's user avatar
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 :...
LondonRob's user avatar
1 vote
1 answer
825 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-...
Joff's user avatar
  • 165
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 ...
eyal karni's user avatar
  • 1,106
4 votes
0 answers
987 views

How do I setup Mypy with Neomake

I'm trying to use Mypy with Neomake, but without success. I am currently using flake8 with Neomake, and it works seamlessly, e.g.: def foo(bar): return 1 foo(1) > E305 expected 2 blank lines ...
Jay Lee's user avatar
  • 141
1 vote
1 answer
420 views

On startup: ImportError: No module named ropevim

When starting nvim, my :messages contains: Error detected while processing function LoadRope[4]..provider#python#Call: line 18: Traceback (most recent call last): File "<string>", line 1, ...
Tom Hale's user avatar
  • 2,691
0 votes
1 answer
58 views

Vim Jedi Plugin -- Add .sage filetype

,g$$$$$$$$$$$$$$$P. OS: Debian 9.9 stretch ,g$$P"" """Y$$.". Kernel: x86_64 Linux 4.19.0-0.bpo.4-amd64 ,$$P' `$$$. Uptime: 3h 17m ',$$P ,ggs. `$$...
Smilia's user avatar
  • 115
3 votes
1 answer
804 views

Documentation for python

I've been looking around for a while now but I couldn't find a proper answer. I would like to access python documentation from Vim. I know that some plugins exist (like this one: https://github.com/...
JPFrancoia's user avatar
1 vote
1 answer
1k views

vim python syntax not working (Partly)

Vim only seems to highlight comments, numbers, and imported modules. So function calls, attributes, etc are all non-highlighted. I have 'syntax on' and 'filetype plugin indent on' in my vimrc. syntax ...
be_elle95's user avatar
0 votes
0 answers
82 views

tabstop doesnt work by default in python files [duplicate]

I have set up set tabstop=2 set lcs=tab>.,trail=. in .vimrc when i open .txt files, tabs are displayed as >. however when i open a .py file, tabs are displayed as >......... I ...
Nic Wanavit's user avatar
5 votes
1 answer
2k views

How to highlight unused Python imports in VIM

I want to highlight unused Python imports as Python syntax errors. For example, I sometimes forget to remove some packages used for debugging such as time, ipdb. It would be great to see warnings or ...
niekas's user avatar
  • 1,575
3 votes
1 answer
367 views

Vim syntax for python call and keyword arguments: issues with built-in keyword

I am trying to come up with a Vim syntax for python function call, e.g.: foo(notarg==0, arg2, kwarg='a', kwarg2='b') dict(a=1, b=2, c=3) where we want to highlight (i) function name foo, dict (ii) ...
Jongwook Choi's user avatar
11 votes
3 answers
28k views

Python debugging

Is it possible to debug Python scripts line by line using :Termdebug? :help termdebug-customizing says, that you need a debugger that is "fully compatible with gdb". Is there a debugger for Python ...
Jakube's user avatar
  • 435
1 vote
1 answer
202 views

C++: different auto-indentation for function protoypes versus continuation lines

I have the following options setup for C++ and Python development in vim: autocmd BufEnter *.cpp setlocal tabstop=4 shiftwidth=4 softtabstop=4 textwidth=80 noexpandtab cindent cinoptions=:0,l1,t0,g0,(...
Cloud's user avatar
  • 223
1 vote
1 answer
4k views

How do I configure syntastic to use Python3 in Ubuntu?

The following code shows invalid syntax. I assume syntastic is looking at Python2 for syntax-checking. I need it to look at Python3 instead. def x(): x = 42 def y(): nonlocal x x = 8 ...
Evan Carroll's user avatar
  • 1,324
1 vote
0 answers
235 views

Issue when creating files using python in vim

When writing or appending files using python inside vim, new files are not being created and existing files are not being changed. Creating and appending files in python script and atom text editor ...
user669132's user avatar