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.
105
questions
0
votes
2
answers
30
views
How to open a file with "|" in the name from python3 function?
A file with | in the name confuses vim.
Example file:
/tmp/Testchars/UTF8 Grin |😬|..
The plugin tries to run:
vim.command(f"edit {chosen_file}")
But Vim interprets the | as a filter:
vim....
0
votes
1
answer
24
views
How to change the internal vim python sys.path?
I have learned that py3eval('print(sys.path)') return the sys.path used internally by Vim.
Say that i want add a new_path to the current sys.path. How shall I do?
I would appreciate solutions that ...
0
votes
1
answer
47
views
Pass local variables in a vimscript function to python
For example, I want to use default arguments:
function! MakeOrgTable(...)
let l:num_col = a:0 > 0? (a:0) : 0;
python << EOF
import vim
vim.current.buffer[:]=make_table(vim.current.buffer, ...
-1
votes
1
answer
30
views
How to replace between two marks with the content of a python variable
I'm writing a plugin to convert between word cases, and I would like to apply my filter between two marks.
The conversion part is done with python, but I don't know how can I replace the text between ...
0
votes
0
answers
73
views
neovim: pwntools process automatically stops when trying to invoke interactive shell
I'm using python pwntools.
I'm using python 3.10.x
This line of code should open a shell for me:
io.interactive()
But while running this file from vim using
!./% it doesn't open the shell doesn't ...
2
votes
1
answer
53
views
How can make every line contain 80 characters when to insert lorem ipsum string?
set textwidth=80 in my .vimrc.
I have written a function to create a lorem ipsum:
function! Lorem(num)
python3 << EOF
import random
num = int(vim.eval("a:num"))
words = ['...
0
votes
1
answer
36
views
How can write the string in the cursor's position?
I write the function in my .vimrc which can convert string into its uppercase.
function! Cap(string)
python3 << EOF
s = vim.eval("a:string")
print(s.upper())
EOF
endfunction
Now i ...
1
vote
1
answer
34
views
How can make the trigger_word as argument to python?
The syntax of UltiSnips's snippet is as below:
snippet trigger_word [ "description" [ options ] ]
The upper method can convert all characters in the string into upper case:
"string&...
0
votes
1
answer
80
views
How can call python in snippet?
I want to expand ptest into welcome python in file ending with html. Add these lines in html.snippets(located in vim-snippets/UltiSnips):
snippet ptest
!p print("welcome python")
endsnippet
...
1
vote
1
answer
818
views
The python library could not be loaded
I am trying to get UltiSnips to work with gVim on my Windows 10 machine and for some reason I keep getting the error:
Error detected while processing function UltiSnips #TrackChange:
line 1:
E370: ...
1
vote
0
answers
19
views
I am developing my own python package, but Omnicomplete won't recognize it
I have my package in a local folder (say C:/Users/Myself/PythonStuff/MyPackage).
Next, I created a new file in C:/Users/Myself/PythonStuff where I import my package, i.e. on top of my new file I have
...
1
vote
2
answers
45
views
Can I skip vimscript indentation inside conditional blocks
I'm editing my ~/.vimrc this weekend, and I've run into a use case that seems to beg that I strip off indentation in an if-block.
Broken use-case in my ~/.vimrc (with if-block indentation):
if has('...
1
vote
1
answer
104
views
Programming Vim in Python: how is it implemented?
Somebody told me that it is possible to write Vim plugins in Python.
I would like to inspect the source implementing this: I would like to use another scripting language for that.
Is there a ...
1
vote
1
answer
55
views
Prevent plugins from loading if python not found
I'm working on a server that has various different python installations set up. At any one time, only one will be accessable and working, depending on what I am working on. Some are python2, some ...
0
votes
0
answers
273
views
Use python through pythonthreehome and pythonthreedll?
I install python use msys2 in windows but i don't know how to put the path to vim
Here is my vim --version:
Here is where i install python3:
And python3 dll:
Vimrc config:
I use python for run ...
2
votes
0
answers
120
views
Neovim rplugin: why does vim.async_call(print, "msg") not echo?
In a traditional :python3 plugin, I can call print("msg") to echo a message.
In a remote plugin function, I expect that calling vim.async_call(print, "msg") would do the same thing,...
1
vote
1
answer
367
views
Neovim: How to start developing python plugins which run long-blocking code?
EDIT2: A user suggested that I may be going about this in a fundamentally wrong way, in particular in that I am not using remote (new-style) plugins and am trying to use async python code where it ...
1
vote
1
answer
68
views
Character level buffer modification
It is possible to modify buffer at the line granularity. E.g. :py3 vim.current.buffer[0] = "abc". But it deletes the attached marks even if a single character is replaced. Is it possible to ...
2
votes
1
answer
370
views
Stop vim from deleting expanded tab as a block of spaces
I am on CentOS 8.1 and using vim 8.0.1763. When I open a python file, e.g. vim tmp.py, I type tab and it inserts 4 spaces (see .vimrc below). When I type delete, it deletes all 4 spaces. I want it ...
3
votes
1
answer
615
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 ...
0
votes
2
answers
419
views
Solving issue with clang-format-vim.py saving new buffer
Summary
I configured vim to call clang-format.py following the steps in the clang documentation for vim integration. But when I save a new buffer the plugin fails. I'm new to vimscript and trying to ...
1
vote
0
answers
22
views
How can you isolate the date portion of each request of a IP adress? [closed]
How can you isolate the date portion of each request of a IP address if it's at the first line of each request from a log file using awk, creating a list of distinct dates, and then using grep to ...
1
vote
1
answer
1k
views
Gvim E370: cannot load library python36.dll with installed Python 3.8
I get often error E370: cannot load library python36.dll while using different plugins like: Fugitive.vim. I have Python 3.8 install with proper PATH.
Is it possible to force Gvim to use python38.dll ...
2
votes
0
answers
125
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
...
1
vote
2
answers
3k
views
How to let Vim work with pyenv?
I've created some Python virtual environments:
hmanx ~ » pyenv virtualenvs
3.7.4/envs/nn (created from /home/roach/.pyenv/versions/3.7.4)
3.8.2/envs/py38 (created from /home/roach/.pyenv/versions/...
0
votes
1
answer
304
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
0
answers
47
views
How to return from vimscript.python?
I have a script written in vimscript-python, e.g.:
function! MyFunction()
python3 << EOF
# if <condition>:
# return
print('Hello world')
EOF
endfunction
I want to add a check in ...
2
votes
1
answer
257
views
Quit script after a certain condition is true
I have a script that checks for a certain condition (it checks if pip dependencies are installed). If they are installed and everything is ok, I want to import a bunch of python functions from my ...
1
vote
0
answers
44
views
Simplest way for a clean uninstall/install of vim with python support [duplicate]
I have vim that is compiled with an outdated version of python (3.4).
I have install python into a local directory and verified it works properly:
$ which python3.7
/usr/local/bin/python3.7
What ...
2
votes
1
answer
1k
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 ...
6
votes
3
answers
8k
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 ...
1
vote
1
answer
667
views
How to use TexMathZones in Markdown Syntax, for Snippets?
I am a recent and very happy Vim User.
I write Mathematics and Computer Science Lecture Notes in Markdown Files, organized in a Vimwiki.
I use the UltiSnips Snippet Plugin.
This plugin provides me ...
2
votes
0
answers
41
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)...
3
votes
2
answers
5k
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 ...
4
votes
0
answers
379
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 ...
1
vote
0
answers
247
views
YouCompleteMe cannot find module
I am trying to get YCM working on Windows 10.
Vim version: 8.1 64-bit GUI
Since I'm using the regular gvim installer for Windows I have python support
Compiler flags as follows:
Compilation: cl -c /...
1
vote
1
answer
103
views
run vim without python3 suppport
I have python2 and python3 compiled into my vim
vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Oct 2 2019 14:25:42)
Included patches: 1-2109
Compiled by user@enterprise
Huge version ...
2
votes
4
answers
564
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 ...
3
votes
2
answers
387
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>:...
1
vote
1
answer
470
views
How to set internal vim variable from python code
I'm trying to write vim plugin for easier work with cmake. I want it to read some values from json file: build_dir, generator, cmake VARS and then give vim user few functions: configure, build, maybe ...
2
votes
1
answer
274
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(...
1
vote
0
answers
764
views
Vim shows error when running python3
OS: Ubuntu 18.04
First, I ran
apt-get install python3-dev ruby-dev
Then, I installed vim using the instructions in the website, using make distclean, make and make install (This was like the tenth ...
1
vote
0
answers
242
views
How to use visual mode in python/dyn?
Vim documentation states how to run command and normal mode commands (source):
vim.command(str) python-command
Executes the vim (ex-mode) command str. ...
1
vote
0
answers
460
views
Where could I find documentation of python/dyn or python3/dyn?
I guess that :py command is executed by some kind of extended Python interpreter. This extended Python has vim package available:
:py import vim; print(dir(vim)); print(vim.__package__, vim.__name__)
...
3
votes
1
answer
2k
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
0
answers
81
views
Why does vim work if command file is double clicked, but not from DOS?
(Windows7-64bits-Vim8.1)
I have a problem with getting the python in Vim to work. This problem is probably caused because I do not have admin access to the machine; I can't help that.
In order to ...
2
votes
1
answer
114
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
0
answers
377
views
Vim using wrong executable and site packages in Python venv
Issue
I am using Vim within an activated Python virtual environment i.e. I have run
python3 -m pip venv env
. env/bin/activate
However when I am editing a Python file, then Ale is complaining about ...
1
vote
1
answer
2k
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
1
answer
8k
views
How do I configure the python location?
The python I want to use is located at C:\randomplace\python.
I have a dev machine that has multiple instances of python (so relying on finding python in$PATH is unreliable).
How do I configure vim ...