2

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?

Sylvain Leroux
  • 50,096
  • 7
  • 103
  • 125
おおさま
  • 257
  • 4
  • 9

2 Answers2

3

Here's how git determines which editor to use. After that, you could just open a new process with the subprocess module.

Community
  • 1
  • 1
austin
  • 5,816
  • 2
  • 32
  • 40
3

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.

Community
  • 1
  • 1
mike3996
  • 17,047
  • 9
  • 64
  • 80