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
28
votes
6answers
19k views

Vim Code Completion for Python 3

I am running Debian Jessie and use the current vim-nox (with +python -python3). I am having a hard time trying to program in Python 3, as I struggle with Python 3 code completion. YouCompleteMe doesn'...
26
votes
4answers
2k views

How can I reformat a multi-line string in vim when using the Python filetype?

Let's assume I am editing some Python code in vim that looks a bit like: myobj.myfunc("Some string parameter that goes on and on and on and on and sometimes doesn't" "split very" ...
20
votes
4answers
4k views

Quickfix support for Python tracebacks

Say I have a python script with a runtime error: $ cat example.py #! /usr/bin/env python3 a = 1/0 which gives: $ python3 example.py Traceback (most recent call last): File "example.py", line ...
19
votes
5answers
6k views

Vim syntax pattern to highlight python keyword argument

I'm struggling with learning vim regexps (I don't know any other regexp very well either), so the main problem is to define regexp that would match some_function_call(simple_value, keyword=value) ...
18
votes
1answer
1k views

Do large numbers make vim run slowly?

This seems like a really daft question, but I have a Python file that has a number in it that's a thousand digits long and that file seems to be running very slowly, I'm not sure if there's some kind ...
17
votes
1answer
6k views

How do I disable syntastic for python files?

I have the syntastic and python-mode plugins installed and they both include syntax checkers. I think the python-mode syntax checker is more versitle for python files so I would like to just use that ...
17
votes
1answer
4k views

End of python block motion

I need a motion that moves to end/beginning of a python block, and I need another motion that moves to begining/end of previous/next method/class (all combinations). I've tried vim-indent-object, ...
13
votes
1answer
10k views

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

I'm trying to fix syntax highlighting for python; my colors are different from those in screenshots of what it "should" look like in different vim color schemes. And you can see the difference in ...
11
votes
1answer
5k views

Why is “set noexpandtab” in my ~/.vimrc ignored when I open a file? [duplicate]

I'm using Mac OS X 10.12 and I have set noexpandtab in my ~/.vimrc There are 2 different behaviors : $ vim file.py If run Vim (8.0) to open one file and type :set expandtab?, it says expandtab $ vim ...
10
votes
3answers
16k 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 ...
9
votes
1answer
4k views

Argument completion for python

Is there a way to get argument completion for python? I am currently using a combination of ctags, python-mode and YouCompleteMe, but I am missing a function to autocomplete the arguments of a ...
8
votes
2answers
6k views

Vim doesn't use the correct indentation in Python files

I have encountered something that I have never seen before in Vim. While I was tentatively modifying some of the source code for software I've been planning to work on, I noticed vim was displaying ...
8
votes
2answers
973 views

Folding Python docstrings

According to the WIKI, scripts can be folded based on syntax. Does anyone have a solution to fold Python docstrings? Basically, all I need is to fold """ text between triple quotation marks """, like ...
7
votes
1answer
2k views

Python imports autocompletion

I'm trying to configure vim for python development. Right now I'm working on code autocompletion feature. I'm using YouCompleteMe plugin and it seems to be working great but only when I've already ...
6
votes
1answer
390 views

equalprg to use for Python

Python is whitespace dependent, and it can't be totally autoindented for that reason, but there are a lot of extra stuff that should be possible to do automatically to comply with PEP8. Things like ...
6
votes
1answer
1k views

How can I change the highlighting of python class name?

How can I define a syntax to highlight the python class name MyClass in vim? class MyClass(object): ...... Vim has already highlighted the class name. However, it seemingly highlights it with ...
5
votes
1answer
3k views

Incorrect auto-indent in python code

I have a following python code, which contains both 4 space and 2 space indents. class Foo(object): def __init__(self, flag = False): if flag: print("hello") ...
5
votes
3answers
4k views

Vim python debugger

I'm using vim for python scripting and currently approaching jedi-vim for autocomplete, navigation and refactoring. But it would be nice to have some ide-like debugging facilities. Is there some ...
5
votes
1answer
222 views

Is there a % equivalent for editing python code?

When I edit C-style languages, I can use % to jump between pairs of square brackets, braces, and parenthesis. If there an equivalent between for, while, def, if and the last indented line for the ...
5
votes
1answer
2k views

How can I highlight all function names in Python files?

I try to make python.vim color similar to material theme (sublime text 3), see pictures: https://imgur.com/a/wOgH7 expected is material theme and current is mine. You may noticed that all method, ...
4
votes
1answer
861 views

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

Is there a way to indent automatcally after typing a : when editing python in vim? I works that way in CodeMirror and I found it nice; so I wondered if vim has that capability?
4
votes
2answers
1k views

How to set the relative indent after breaking Python lines?

When I insert a line break inside a line of Python 3 code, the remaining part of the line is indented by two additional tab widths (2 time 4 spaces) in the next line. # Before example_function(...
4
votes
2answers
1k views

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

For those who might not know, Flycheck is a plugin which checks the syntax of the code you're writing on the fly, without forcing you to save the file. It does that by periodically saving the buffer ...
4
votes
1answer
6k views

How do I complete Python3 with YouCompleteMe?

I'm using YouCompleteMe to do omni complete. Most of these are fine. But when I want to complete Python3, there is something wrong. It only can complete python2. For example, import urllib # ...
4
votes
0answers
702 views

vim compiled with python3 but python3 omni-completion does not work

It used to work when I used python2, but now I can't use ^X^O to complete function names. I do have vim with -python and +python3 (on Ubuntu 16.04), but here is the error I get when trying Ctrl-X ...
3
votes
3answers
703 views

Is it possible to add a specific text string in the beginning of creating a certain file type? [duplicate]

Just like the topic says; is it possible to add a certain text string in the beginning of a file if I create a certain file type? For example, if I create a random Python file with vim random.py. Can ...
3
votes
2answers
48 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 ...
3
votes
3answers
930 views

Test python function from within editor

I am writing python 3 code from within vim. There is a function within my file like this: def seconds_to_text(seconds): return str(datetime.timedelta(seconds=seconds)) Is there a way for me to ...
3
votes
1answer
693 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 ...
3
votes
1answer
576 views

How can I remove a syntax keyword?

In Python3, file is no longer a builtin. It's just a plain ol' name that isn't even associated with anything until you do. But all the syntax files that I've used have it as a builtin. Is there a ...
3
votes
1answer
95 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 ...
3
votes
3answers
112 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 ...
3
votes
0answers
483 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 ...
3
votes
0answers
2k views

Generating tags for python that follow imports [closed]

I'd like to be able to conveniently navigate to the file where a Python value (function/class/constant) is defined. Most of the guides I can find for using ctags with Python suggest options that aren'...
3
votes
0answers
567 views

Highlight python raw strings as regular expression

I heard someone had set up their editor to highlight python raw strings as regular expressions, e.g. for Django: urls(r'^site1/(\d)*/new$'', ...) Unfortunately my googleing doesn't get me anything. ...
2
votes
2answers
3k 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 ...
2
votes
1answer
747 views

Closing error window

When I run yapf on my code, an error page appears, rightly showing the error I have in the code. How on earth do I close this window and go back to my code? :lclose doesn't work. :close closed the ...
2
votes
1answer
2k 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....
2
votes
1answer
565 views

How to disable automatic unindent of comments in Python?

I start vanilla vim8 $ vim -u NONE with these settings: :set ft=python :set smartindent :set cinkeys-=0# When I enter in insertion mode the following: Hello # The # is automatically ...
2
votes
2answers
51 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 ...
2
votes
1answer
208 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/...
2
votes
1answer
78 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 ...
2
votes
1answer
523 views

What is a good debug front end plugin

I would like to use vim to write python codes, it is good to use python-mode plugin. However, I have to debug with pdb in the terminal, which is quite inconvenient since I have no way to view the ...
2
votes
1answer
498 views

Getting vim with yapf to work with anaconda environments

I'm trying to figure out how to get yapf to use my current conda environment when resolving imports. Basically, I just see a ton of the following errors: physics.py|6 col 1 error| [import-error] ...
2
votes
0answers
88 views

Automatically determine whether to use spaces or tabs [duplicate]

I like to use tabs for indentation (hey, don't bully me!). But 33% of other programmers prefer spaces. The norm with Python is to use spaces for indetation. Even so, I configured Vim to use tabs with ...
1
vote
1answer
10k views

Automatic whitespace in python

I'm a novice in Vim and configuring it for writing python scripts comfortably. Is the a way to automatically put four spaces after I jump onto the first line of while True: loop ?
1
vote
1answer
342 views

Strange Fold Info Showing in Gutter

It's only happening in one of my .py files when opened with vim, I am getting some kind of fold info in the gutter that shouldn't be there - made up of the characters '2', '-' and '|'. I disabled ...
1
vote
1answer
3k 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 ...
1
vote
1answer
46 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
1answer
47 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 ...