示例:
fun! s:MyScript(startline,endline)
python3 << endpython
import vim
startline = vim.eval("a:startline")
endline = vim.eval("a:endline")
for n in range(startline, endline + 1):
line = vim.current.buffer[n - 1]
#===========================
# start input lines
if re.search(...,line):
do this or that
# end input lines
#===========================
vim.current.buffer[n - 1] = line
endpython
endfun
我想在上面脚本的开始和结束输入行之间动态插入Python代码。
我知道我可以使用 Vim 的输入字段 (Let Question = ....
) 来用“line”做某些事情。 line = eval(myinputlline)
但是如何一次插入像 if re.search(....)
这样的 Python 代码以及更多行呢?
最佳答案
这对我有用:文件test-vim.py
:
import vim
startline = vim.eval("line(\"'<\")")
endline = vim.eval("line(\"'>\")")
print(startline)
print(endline)
我启动了vim somefile
。选择从 6 到 3 的几行。运行 :py3file test-vim.py
。 vim
报告
6
3
关于python - 如何使用 VIM 输入字段插入某些 python 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59388295/