来自vim doc:
vim.command(str) *python-command*
Executes the vim (ex-mode) command str. Returns None.
vim.eval(str) *python-eval*
Evaluates the expression str using the vim internal expression
evaluator (see |expression|). Returns the expression result as:
- a string if the Vim expression evaluates to a string or number
- a list if the Vim expression evaluates to a Vim list
- a dictionary if the Vim expression evaluates to a Vim dictionary
Dictionaries and lists are recursively expanded.
Run Code Online (Sandbox Code Playgroud)
我很难区分这两个,也许是因为我首先不理解表达式和命令之间的区别.对一些例子的解释非常受欢迎.
TL; DR:command()用于为其副作用执行Vim命令,并eval()获取由Vimscript函数计算的值.
像其他编程语言一样,Vim(脚本)区分一个过程(你只是调用它,但什么也得不回来;有趣的是它执行的动作),一个函数(返回一个值,也可以选择执行像一个程序).
使用:split foo.txt,您可以调用此方法在窗口拆分中打开文件.该命令不返回任何内容,但可以很容易地观察到它的效果(打开另一个窗口,在那里编辑一个文件).你会用vim.command()它.
使用:echo winnr('$'),您查询打开的窗口数.:echo有价值的打印,但如果您想在Python中使用,则可以使用vim.eval("winnr('$')").(但请注意,某些Vim属性已经被Vim中的Python集成公开;您只能将它用于Python中尚未提供的内容.)
| 归档时间: |
|
| 查看次数: |
463 次 |
| 最近记录: |