VIM:如何将参数从用户命令传递给函数? [英] VIM: How to pass arguments to functions from user commands?

查看:31
本文介绍了VIM:如何将参数从用户命令传递给函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 VIM 中创建一个用户定义的命令,该命令接受一个参数并使用用户提供的参数调用一个函数.看起来很简单,但我无法让它工作.这是我的 foo.vim 插件中的代码:

I am trying to create a user-defined command in VIM that takes one argument and calls a function with the user supplied argument. Seems simple but I am unable to get it to work. Here is the code from my foo.vim plugin:

function! s:MyFunc(myParam)
    do something
endfunction

command! -nargs=1 MyCommand call s:MyFunc(myParam)

当我在这样的 VIM 缓冲区中尝试此操作时:

When I try this out in a VIM buffer like this:

:MyCommand exampleParam

我收到以下错误:

E121: Undefined variable: myParam 
E116: Invalid arguments for function <SNR>7_MyFunc

这里有什么问题?我该如何解决?非常感谢任何帮助.

What's wrong here? How do I fix this? Any help is greatly appreciated.

推荐答案

使用 :

command! -nargs=1 MyCommand call s:MyFunc(<f-args>)

这篇关于VIM:如何将参数从用户命令传递给函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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