python3 to vim桥装饰器,允许在本机vim脚本中透明调用python3函数。

vim-bridge3的Python项目详细描述


python 2的original的python 3端口:https://github.com/nvie/vim_bridge

这是什么?

vim_bridge3是一个python-to-vim桥装饰器,它允许透明调用 本地vim脚本中的python函数。

安装

使用setuptools安装vim_bridge3python包, easy_install,或pip

用法

在vim脚本中,按照如下方式装饰python函数,将它们公开为 本地vim可调用。参数和返回值都被分类,因此它应该 透明:

python3 << endpython
from vim_bridge import bridged

@bridged
def SayHello(first, last):
    return "Hello, %s %s!" % (first, last)

endpython

" Now call directly into the Python function!
echo SayHello("John", "Doe")
" prints "Hello, John Doe!"

支持

以下数据类型已证明有效:

  • 字符串
  • 整数
  • 列表
  • 例外情况

更多示例

传递列表:

python3 << endpython
from vim_bridge import bridged

@bridged
def GetLongest(list):
    return max(map(lambda s: len(s), list))

endpython

echo GetLongest(['one', 'two', 'three', 'four'])
            " returns 5 (because "three" is 5 chars long)

捕捉异常:

python3 << endpython
from vim_bridge import bridged

@bridged
def WillCauseException():
    raise Exception("Oops")

endpython

" This will throw an error to the user...
echo WillCauseException()

" But here's how you can catch that in Vim
try
    echo WillCauseException()
catch
    echo "Something went wrong. Aborting."
finally
    echo "Cleaning up."
endtry

使用python stdlib函数执行更困难的工作 使用纯vim脚本:

python3 << endpython
import os.path
from vim_bridge import bridged

@bridged
def NormalizePath(path):
    return os.path.realpath(path)
endpython

echo NormalizePath("/this/../or/./.././that/is/./a/.//very/../obscure/..//././long/./../path/name")
echo NormalizePath("..")

可以在python块中使用桥接函数定义 它本身,或者从vim内部,都无关紧要。在这个例子中, normalizePath是从python和vim调用的:

python3 << endpython
import os.path
from vim_bridge import bridged

@bridged
def NormalizePath(path):
    return os.path.realpath(path)

@bridged
def RealPath(path):
    # It does not matter if you call NormalizePath from here...
    return NormalizePath(path)
endpython

" ...or from here
echo NormalizePath("/this/../or/./.././that/is/./a/.//very/../obscure/..//././long/./../path/name")
echo RealPath("..")

由于vim_bridge 0.4,函数名大小写约定是 自动转换以匹配vim的约定(和requirement 甚至,因为函数名必须以大写字母开头。 除了外壳外,用下划线预置Python函数 导致在vim上下文中将函数定义为 <SID>-前缀函数(即不能是 从脚本外部调用):

python3 << endpython
import os
import vim
from vim_bridge import bridged

@bridged
def public():
    return "I am public."

@bridged
def _private():
    return "I am private (available in the current script only)."

@bridged
def my_name_is_auto_converted():
    return "In Python, I'm called my_name_is_auto_converted, " + \
           "but in Vim, I'm called MyNameIsAutoConverted :)"

@bridged
def _long_private_name():
    return "I'm private, and my case is converted automatically."
endpython

echo Public()
echo s:Private()
echo MyNameIsAutoConverted()
echo s:LongPrivateName()

更改

  • 2010年文森特·德里森(@nvie)的原始代码。BSD许可证。
  • 2016年Roland Puntaier(@rpuntie)对Python2和Python3的支持。
  • Walter Doekes(@wdoekes)在2017年对python3的支持。
  • 2018年罗兰·普泰尔(Roland Puntaier,@Rpuntaie)为Pypi设计的Vim_Bridge3。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Admob初始化失败,应用程序在启动时崩溃,即使没有错误   java如何在ibatis中使用存储过程?   java干净体系结构:在不同的环境中分离IO和核心。jar文件   Java streams compare属性在两个列表之间相等,并返回true或false   有没有一种压缩Java Try-Catch块的方法?   Android片段中的java Mapbox SDK   用于IzPack安装的JavaFX本机启动器:控制InnoSetup/WiX/RPMBuild行为   java接口是否可以将一个已经实例化的对象作为属性?   hashmap中的java线程问题   请求中的java字符编码。getRemoteUser()   java将OneTONE链接更改为另一个id为的实体   java当使用javaw启动应用程序时,不会执行关闭钩子。exe   Android java代码更改显示的微调器   java GZIP解压字符串和字节转换   运行springbatch后java LDAP运行状况检查失败