Vim 扩展(通过 Python)? [英] Vim extension (via Python)?

查看:25
本文介绍了Vim 扩展(通过 Python)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过自定义扩展(最好用 Python 编写)来扩展 vim 功能?

is it possible to extend vim functionality via custom extension (preferably, written in Python)?

理想情况下,我需要的是在命令模式下的自定义命令.例如

What I need ideally is custom command when in command mode. E.g.

电调

:do_this

:do_that

推荐答案

vim 支持在 python 中编写脚本(我认为在 perl 中也是如此).

vim supports scripting in python (and in perl as well, I think).

你只需要确保你使用的 vim 发行版已经编译了 python 支持.

You just have to make sure that the vim distribution you are using has been compiled with python support.

如果你使用的是Linux系统,你可以下载源码然后用

If you are using a Linux system, you can download the source and then compile it with

./configure --enable-pythoninterp 
make
sudo make install

在vim里面,你可以输入

Inside vim, you can type

:version

列出可用的功能;如果它有 python 支持,你应该在某处看到一个 '+python'(否则是一个 '-python').

to list the available features; if it has python support, you should see a '+python' somewhere (a '-python' otherwise).

然后,要检查python模块的使用情况,您可以输入

Then, to check the usage of the python module, you can type

:help python

P.S:如果您要编译 vim 源代码,请确保检查可用的配置选项,您可能还需要指定 --with-python-config-dir.

P.S: if you're going to compile the vim sources, make sure to check the available configure options, you might need to specify --with-python-config-dir as well.

PPS:要在命令模式下创建自定义命令"(如果我理解正确的话),您可以在 vim 脚本(使用 python 或 vim 脚本语言)中创建一个函数MyFunction",然后调用它与

P.P.S: to create a "custom command in command mode" (if I understand correctly what you mean), you can create a function "MyFunction" in a vim script (using python or the vim scripting language) and then invoke it with

:Call MyFunction()

检查

:help user-functions

详情

这篇关于Vim 扩展(通过 Python)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆