如何运行 python脚本里面vim?
How to run python script inside vim?
我知道我们可以在 vim 中 运行 a.py
使用命令:
:! python a.py " method 1
:! python % " method 2
我们还可以将键绑定设置为 运行 python 脚本为:
autocmd! FileType python nmap ,r :!clear; python %<CR>
现在的问题是如果我们必须传递参数,我尝试创建这样的命令:
command py !python % " This does not work!!
必填:
:py arg1 arg2
应该 运行 python 带有参数 arg1 和 arg2 的脚本,即 python a.py arg1 arg2
示例 python 脚本:
import sys
print(sys.argv[1])
print(sys.argv[2])
我在 Macbook Pro 中使用 vim。
$ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 29 2017 18:37:46)
Included patches: 1-503, 505-680, 682-1283
Compiled by root@apple.com
command! -nargs=* Py !python % <args>
-nargs=*
允许任意数量的参数(0、1 或许多)。 <args>
将命令行参数粘贴到命令中。
我知道我们可以在 vim 中 运行 a.py
使用命令:
:! python a.py " method 1
:! python % " method 2
我们还可以将键绑定设置为 运行 python 脚本为:
autocmd! FileType python nmap ,r :!clear; python %<CR>
现在的问题是如果我们必须传递参数,我尝试创建这样的命令:
command py !python % " This does not work!!
必填:
:py arg1 arg2
应该 运行 python 带有参数 arg1 和 arg2 的脚本,即 python a.py arg1 arg2
示例 python 脚本:
import sys
print(sys.argv[1])
print(sys.argv[2])
我在 Macbook Pro 中使用 vim。
$ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 29 2017 18:37:46)
Included patches: 1-503, 505-680, 682-1283
Compiled by root@apple.com
command! -nargs=* Py !python % <args>
-nargs=*
允许任意数量的参数(0、1 或许多)。 <args>
将命令行参数粘贴到命令中。