惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
有赞技术团队
有赞技术团队
博客园 - 三生石上(FineUI控件)
博客园_首页
博客园 - 【当耐特】
WordPress大学
WordPress大学
月光博客
月光博客
博客园 - 叶小钗
S
SegmentFault 最新的问题
雷峰网
雷峰网
H
Help Net Security
宝玉的分享
宝玉的分享
A
About on SuperTechFans
IT之家
IT之家
J
Java Code Geeks
Hugging Face - Blog
Hugging Face - Blog
D
DataBreaches.Net
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 聂微东
T
The Blog of Author Tim Ferriss
B
Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Y
Y Combinator Blog

博客园 - ABeen

[Database] Mongodb 分片集群 [Linux] vim状态栏配置 [Linux] Centos 添加开机启动脚本 [Linux] Docker 镜像及容器自动化思路 [Linux]Docker 容器时间与宿主机同步 [Linux] Tomcat java.lang.OutOfMemoryError: Java heap space [Linux] Nginx 反向代理配置 http headers 带下划线fields转发 [Linux] 非云环境的Ubuntu主机如何关闭Cloud-init [DataBase] MySql 查看实时日志 [Misc] ZSH 常用快捷键 [Database] MAC MySQL中文乱码问题 [Tools] 多媒体视频处理工具FFmpeg [Linux] Ubuntu Server18 python3.7 虚拟环境 [Linux] 树莓派编译python3.7.4 [Linux] TMUX Python版本设置 Linux 批量杀进程的命令 arm树莓派Raspbian 下安装selenium+chrome 树莓派Raspbian系统密码 mac 终端查看端口命令
[Misc] python 开发vim 插件初步测试
ABeen · 2020-01-07 · via 博客园 - ABeen

[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