[Misc] python 开发vim 插件初步测试

[Misc] python 开发vim 插件初步测试

今日雨夹雪, 晚上闲来没事突然想了解下用python试试VIM插件开发. 于是写了个初步测试.
总体来说相当简单, 几个相当设置语法后, import vim 后就进入python世界了. (相当操作命令vim内:help py了解更多)

  1. 测试代码, 放到.vim/plugin目录下, *.vim
  2. 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          
posted @ 2020-01-07 23:01  ABeen  阅读(190)  评论(0编辑  收藏  举报