Reputation: 257
Is there a way to communicate with vim in python?
I mean, I am wring a small software using python, it has a facility of memo, so when I want to write some memo, the software should invoke vim. After editing, it will save the buffer of vim in some format.
Just like committing in git, git invokes an editor. So is there any module to do this?
Upvotes: 2
Views: 554
Reputation: 17497
Check my answer about invoking $EDITOR
on the content of your choice:
call up an EDITOR (vim) from a python script. That's how git and others do that: write an initial content up in temporary file, fire $EDITOR
on it, wait for the process to exit and then read the new content, parsing it. To provide syntax colouring or other niceties, usually a 'contrib' package is provided and has nothing to do with the functionality of the program itself.
Upvotes: 3
Reputation: 5866
Here's how git determines which editor to use. After that, you could just open a new process with the subprocess module.
Upvotes: 3