[Misc] python 开发vim 插件初步测试
[Misc] python 开发vim 插件初步测试
今日雨夹雪, 晚上闲来没事突然想了解下用python试试VIM插件开发. 于是写了个初步测试.
总体来说相当简单, 几个相当设置语法后, import vim 后就进入python世界了. (相当操作命令vim内:help py了解更多)
- 测试代码, 放到.vim/plugin目录下, *.vim
- vim内
: Helloworld和: Helloname abeen调用测试方法.
测试如下:
1 " vim plugin test
2 " Author: ABeen
3
4 " check the vim supports python
5 if !has('python3')
- 6 echo 'Error: Required vim compile with +python3'
| 7 finish
8 endif
9
10
11 command! -nargs=0 Helloworld exec('python3 Helloworld()')
12 command! -nargs=1 Helloname exec('python3 Helloname(<f-args>)')
13
14
15 python3 << EOF
16
17 import vim
18
19 current = vim.current.buffer
20
21
22 def Helloworld():
- 23 print("hello,world")
| 24 global current
| 25 current.append('Hello, world!')
| 26 vim.command('set nu')
27
28
29 def Helloname(name):
- 30 print("Welcom {0}".format(name))
| 31 global current
| 32 current.append('Welcome, '+name)
| 33 vim.command('set nonu')
34
35 EOF
36 相关推荐
lerdor 2020-10-14
CoderMannul 2020-09-07
ZZBAIFFA 2020-08-31
yonggeno 2020-08-18
zhangxl0 2020-07-28
yhuihon 2020-07-26
想个标题偏头痛 2020-07-19
老甘的可读区 2020-07-18
想个标题偏头痛 2020-06-22
Geek猫 2020-06-15
想个标题偏头痛 2020-06-08
linzb 2020-06-04
圆圆的世界CSDN 2020-06-04
yhuihon 2020-05-31
想个标题偏头痛 2020-05-26
圆圆的世界CSDN 2020-05-14
linzb 2020-05-12