Questions tagged [vimscript-python]
For questions about The Python interface to Vim; DO NOT use for questions with Python examples or about syntax highlighting in Python.
88
questions
29
votes
2answers
13k views
How do I get Vim to be able to run both python and python3 on a Linux system in the same session?
On Linux systems, packaged Vim typically has only one of either python or python3 enabled. It is possible for both to be enabled (using python/dyn and python3/dyn), but during a session, only one can ...
26
votes
7answers
36k views
Vim 8.0 Python support
I'm trying to upgrade my Vim installation to version 8.0, but it doesn't support both Python and Python 3 as the below image.
(PS: Because of this problem, I cannot use the YCM (YouCompleteMe) plugin ...
22
votes
2answers
1k views
Can I script Vim using Python?
Vimscript looks somewhat similar to Python code.
Can Vim be integrated with high-level language interpreters, such as Python?
13
votes
3answers
15k views
Installing or building vim with +python3 support for Python 3.7.x on linux
I've got Vim installed on MacOS using Brew and it installs with +python3 support for Python 3.7.2 by default.
I'm writing a Vim plugin which utilises some Python 3.7 and would like this to be able to ...
12
votes
7answers
12k views
how to change python interpreter used by jedi-vim
I have Anaconda (including python3.5.2), VIM (7.4) and Jedi-VIM installed on my system. There was also a python installed on the linux system by default.
The autocompletion is working on base ...
11
votes
2answers
2k views
How to execute python statement for each line?
I've the following sample code which modifies the current line using Python statement:
:py import vim; vim.current.line="["+vim.current.line+"]"
How I can execute this statement for each line in the ...
9
votes
3answers
2k views
Elegant way to support both python and python3 in vim plugin
I recently received a pull request to change my vim plugin to make it support python3. But these changes break the plugin for the vim on my Mac which seems to listen to python.
python import sys
...
9
votes
2answers
4k views
How do I use Python plugins on Windows?
I have Windows 7 64-bit, with python 2.7.11 and python 3.5.1 (both 32-bit) installed, and I have compiled vim with python/dyn and python3/dyn, but I keep getting the following error:
:py print "hello"...
8
votes
2answers
1k views
Drawbacks of using Python to develop new code in a VIM plugin
In one of the vim plugins I use, we have been thinking about using python vs vimscript going forward (https://github.com/python-mode/python-mode/issues/813#issuecomment-344754563).
I understand that ...
8
votes
2answers
4k views
How can I build vim with just python 3 support?
I'm on Arch, and recently the vim-python3 and gvim-python3 packages were removed, so I'm working on building vim from source such that the :python command will act as python3. Specifically, I'm doing ...
7
votes
1answer
4k views
Trying to compile vim with python 3.6. Where is my config directory?
I'm a bit of a noob when it comes to Linux, only started using it recently.
However, I am trying to compile vim with python because I am using latex live preview and it needs a python compiled vim ...
6
votes
1answer
7k views
How to get Python support on MS Windows?
I've installed the latest version of Vim to date (8.0) for Windows. But the version of Vim I've got does not have Python support. I've downloaded the .exe version directly from vim.org.
echo has('...
6
votes
1answer
374 views
How to use the argument of a vimscript function in an inner python function?
I have the following vimscript: it contains a vimscript function which executes a python code thanks to python << EOF:
function! Test(myArgument)
python << EOF
def test(myArgument):
...
6
votes
0answers
814 views
Resources for scripting vim with python [closed]
I love vim, I love python, and I dislike vimscript. So I would like to know how to write plugins (or throwaway scripts) for vim in python.
Of course, the first reference should be :h python, but I ...
5
votes
4answers
650 views
Calculating with python and appending result to file or register
I found this vim tip which allows you to evaluate a Python expression and displays the result in the command line. You just have to add
:command! -nargs=+ Calc :py print <args>
:py from math ...
5
votes
3answers
4k views
How to access a custom python module inside vim?
This is a Python 2.7 question. I have a custom python 2.7, that I have compiled and have been using successfully across my system. My custom python has the YAML modules installed as well.
The system ...
4
votes
1answer
2k views
How can I get python library help in vim?
I tried python-mode, it seems that it can work when I press K on "numpy.array", but if I want to press K on "np.array", it won't work.
4
votes
1answer
440 views
How to write a plugin that works for both Python3 and python? [duplicate]
I feel like this might be because of my lack of vimscript knowledge. Basically I want to write a patch for this plugin https://github.com/actionshrimp/vim-xpath to make it work for python3 (and hence ...
4
votes
1answer
386 views
Making a box in vim via python
I am attempting to learn more about scripting vim and writing plugins with python, but I'm having trouble getting started. Although I've read :h python (first step, read the manual), I had trouble ...
4
votes
1answer
414 views
Start and attach to neovim in same python file
I have a working prototype for some kind of linux-based neovim-app. Sole functionality is "vsplit if 'k' is pressed". It is based on tarruda's nvim-terminal-edit-py.
It is started through start_nvim....
4
votes
1answer
592 views
neovim: autocompletion on user defined command plugin
I am write a plugin for neovim in python using this client and I looking for a way to offer completion when executing a command. I have look at the following example to structure my plugin. As an ...
3
votes
4answers
358 views
How to run a python command based on a matched group of a pattern?
Let say I want to run a command that uses a matched group of a pattern for each line matching the pattern.
The natural choice is :g.
With the command :s, there is no problem. If i would do
:g/aaa\(....
3
votes
1answer
8k views
requires Vim compiled with Python (2.7.1+ or 3.4+) support
I compiled vim8.1 with the following options :
$ vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Sep 18 2018 09:50:18)
Included patches: 1-320
Compiled by mohsen@ns1
Huge version with GTK2 ...
3
votes
1answer
611 views
How to detect the buffer number of new buffer
I would like to create a new scratch buffer in vim script. I would like to use this buffer to output the result of the execution of a scala script.
I am creating the buffer with this function:
...
3
votes
2answers
226 views
Inserting text with the Python interface
I would like to insert some Python-generated text at the current cursor position in insert mode using the Vim Python interface. The closest I have so far is:
imap <c-x><c-r> <c-o>:...
3
votes
2answers
791 views
The :python command doesn't work - E319: Sorry, the command is not available in this version
I am trying to use Python in vim, but it doesn't work despite vim having the +python3 option.
:python print("hello")
gives
E319: Sorry, the command is not available in this version
Question: How ...
3
votes
1answer
482 views
Neovim Python script hangs
I'm thinking of migrating from Vim to NeoVim. I decided to begin with a bit of Python code in my .vimrc that sets the backup directory.
Using the documentation, I wrote the following script:
"-------...
3
votes
1answer
181 views
What is the best way to embed external python modules to vim plugin?
I decided to write a plugin for vim. I want to write it mainly in python, as I am most proficient in it. I started development with this example: http://brainacle.com/how-to-write-vim-plugins-with-...
3
votes
1answer
5k views
How to resolve “requires Vim compiled with Python 2.x support” when launching Vim?
I have Vim 7.4 installed on Windows 10 as part of a Mingw64 installation. I installed the YouCompleteMe plugin on it through Vundle, then ran the install.py, which completed successfully.
Now, every ...
2
votes
1answer
904 views
Vim is unable to find Python
I'm using Vim on Fedora 28 and Python seems to be enabled:
vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Jul 11 2018 10:00:51)
Included patches: 1-177
Modified by <bugzilla@redhat.com&...
2
votes
1answer
67 views
Contextual Snippets in UltiSnips not working
I have been using vimtex with UltiSnips for a while on Linux platform and it has been working just fine.
Recently, I switched to MacBook Air M1 for the same and installed the above mentioned plugins ...
2
votes
1answer
110 views
How to assign a Python list to a vim variable and escape its strings correctly
Here is a Python list that I'm trying to assign to some Vim variable.
lines = ['"""Something foo\'s thing."""', '', 'foo = "asdfasdf" \\', 'bar']
command = 'let l:corrected_lines = {lines}'.format(...
2
votes
2answers
1k views
Vimscript-python support not working in terminal
When starting vim in a mingw64 terminal emulator on windows, the command :py print(1) fails, saying
Could not load library msys-python2.7.dll
Sorry, this command is disabled, the Python library could ...
2
votes
1answer
719 views
Ultisnips py3 errors
I have these following errors whenever I try to get into insert mode (see images). I am confused about how to resolve them. I did try uninstalling and reinstalling SirVer/ultisnips, but didn't change ...
2
votes
1answer
86 views
Return <motion> character from Python function in <expr> mapping
I am trying to return this :GrepperAck ''<Left> from a Python function and use it in the following mapping
def invoke_search_command():
return ":GrepperAck ''<Left>"
:nnoremap <expr&...
2
votes
1answer
839 views
Vim crash with :py3 import sys; print(sys.version)
Windows 8
Vim 8.0.584, 32 bit from https://tuxproject.de/projects/vim/ .7z archives: x86
python36.dll, 32 bit from https://www.python.org/ftp/python/3.6.0/python-3.6.0-embed-win32.zip
copied python36....
2
votes
1answer
1k views
Vim 8.0 breaks YCM on Windows 10
I was using Vim 7.4 with YCM quite successfully (thank you for YCM!) and just today noticed that Vim 8.0 was out. I downloaded, installed, started and now it complains that "YouCompleteMe unavailable: ...
2
votes
1answer
532 views
Conflict between python used by vim and by YouCompleteMe
YCM does not work for the reason given above. When I type :python import sys; print sys.version I obtain:
2.7.9 (default, Dec 13 2014, 15:13:49)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)]
...
2
votes
2answers
1k views
What does vim try to tell me with: 'Sorry, this command is disabled, the Pythons's site module could not be loaded'?
I try to get python support in gvim on windows to work with the help of this binary distribution.
First I got the error python27.dll could not be located, what I successfully fixed by copying python27....
2
votes
0answers
94 views
YouCompleteMe unavailable: unable to load Python [duplicate]
I have done PlugInstall but it gives:
YouCompleteMe unavailable: unable to load Python.
The same error happens while loading UltiSnips:
E370: Could not load python36.dll
My vimrc:
set rnu
set nu
...
2
votes
0answers
22 views
Running a python command with terminal-generated signals enabled
I'm trying to do a long blocking read call inside a python script supplied with the python command:
python3 << EOF
import ctypes
libc=ctypes.CDLL("libc.so.6")
ch = ctypes.create_string_buffer(1)...
2
votes
0answers
63 views
How to fix which python executable vim is using?
For the python command vim uses the python exetuable it finds first in the $PATH variable. However, for me this can change depending what project I work on (using virtual environments). Is there a way ...
2
votes
1answer
238 views
How to automate populating Python's class constructor?
I've done some searching with various keywords, but unsuccessfully. Sorry for my English, I'm not a native speaker.
I'm new to VIM and to Python, and I'm learning both on the go as much as I can, but ...
1
vote
1answer
718 views
Creating a hidden buffer
I know that with commands like sbuffer you can create a new buffer and display it in a split window, and commands like enew can create a new buffer in the current window. But is it possible to not ...
1
vote
1answer
985 views
Why is Vim's Python version compiled in?
My machines have Python 3.7 installed. On my Ubuntu machine I have no issues, but on my Windows 10 machine, I can't run Python plugins in Vim. The reason is that the Windows Vim as distributed has ...
1
vote
1answer
169 views
python vs pyx in vim
I'm a bit confused as to what the difference is between python and pyx in vim, other than one seems to work and the other does not. For example:
pyx print ("OK")
This works, however, this ...
1
vote
3answers
173 views
vim : how to set current buffer to a string using `:python`
As example, my current buffer contains below lines
di=01;34
ln=01;36
mh=00
pi=40;33
I want to join all lines with :, and set entire buffer to the joined string.
How to achieve that, using :python ...
1
vote
1answer
108 views
pyeval not working on vim -u NONE or vim diffs
:echo pyeval('vim.current.window.col') works fine on a normal Neovim instance.
But if I start Neovim in diff mode or with the -u NONE option and try the same command, I get this error:
Error ...
1
vote
1answer
123 views
Vim 8.0 python support: where to store a per-buffer python variable?
Context
Python integration in Vim 8.0 provides a handful of useful python objects in vim module. In particular, there are per-buffer objects accessible via vim.buffers list and vim.current.buffer. ...
1
vote
2answers
1k views
Vim python backend, how to import user installed shared libraries?
I (very) often write python, and I use Vim's python3 backend to test my code. To perform my tests I use:
vnoremap <localleader>p y:<c-r>"<c-b>python3 <cr>
It simply takes my ...