Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I call Vim from Python?

Tags:

python

vim

I would like a Python script to prompt me for a string, but I would like to use Vim to enter that string (because the string might be long and I want to use Vim's editing capability while entering it).

like image 209
jl6 Avatar asked Mar 19 '23 00:03

jl6


1 Answers

You can call vim with a file path of your choice:

from subprocess import call
call(["vim","hello.txt"])

Now you can use this file as your string:

file = open("hello.txt", "r")
aString = file.read()
like image 123
Jens Wirth Avatar answered Mar 27 '23 11:03

Jens Wirth