invoke an editor ( vim ) in python

回眸只為那壹抹淺笑 提交于 2020-01-04 10:42:24

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/17196204/invoke-an-editor-vim-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!