从vim命令行运行vim脚本 [英] Run vim script from vim commandline

查看:158
本文介绍了从vim命令行运行vim脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几个月中,我构建了一系列包含vim命令的文件,以自动为我的项目生成样板代码.它可以让我更快地工作.

Over the last couple of months, I've built a series of files full of vim-commands to auto-generate boilerplate code for my projects. It's allowed me to work faster.

但是,我知道如何运行这些脚本的唯一方法是将它们分配给~/.vimrc中的键组合.我只能重映射很多键.

However, the only way I know how to run these scripts is by assigning them to key-combinations in ~/.vimrc. There's only so many keys I can remap.

是否可以通过几次击键从:命令行运行这些脚本?

Is there a way to run these scripts from the : commandline with a few keystrokes?

例如,我有一个unit_test_cpp.vim脚本,该脚本可构建样板单元测试cpp文件.我希望能够输入

For example, I have a unit_test_cpp.vim script, which builds a boilerplate unit test cpp file. I'd like to be able to type

:utc

或其他一些简单的字母组合以及一个简单的助记符,可在我当前打开的文件上运行此脚本.

or some other simple combination of letters with a simple mnemonic to run this script on my currently open file.

推荐答案

您可以使用vim的command功能.在您的unit_test_cpp.vim文件中,您将添加以下内容:

You could use the command feature of vim. In your unit_test_cpp.vim file you would add something like this:

command Utc call CreateUnitTests()

现在,当您键入:Utc时,它将调用您的函数.唯一的限制是您的命令必须以大写字母开头.

Now when you type :Utc it will call your function. The only limitation is that your command must start with an uppercase letter.

这篇关于从vim命令行运行vim脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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