有没有办法将命令添加到Neovim中,可以称为“:命令”?

发布于 2025-02-10 08:10:06 字数 232 浏览 1 评论 0原文

我想归档的是能够使用:< shell命令,然后将输出添加到shell命令到光标在Neovim的位置。

看来我可以使用:redir来拱起此功能并将其包装到功能中。

有没有办法将[neo] vim函数与:命令相关联?

What I would like to archieve is to be able to use :< shell command and add the output to the shell command to the cursor's position in neovim.

It seems I could use :redir to archieve this functionality and wrap it in to a function.

Is there a way to associate a [neo]vim function to :command?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情何以堪。 2025-02-17 08:10:06
  1. 命令无法返回值。因此,命令不是表达式。特别是,命令永远不会被“嵌套”到另一个,例如函数调用。参见例如,外壳脚本。

  2. 原则上,有一些技巧,例如一个接受命令名称,运行它并返回输出为字符串值的内置函数。但这是“方便的redir”,而不是“语法断路器”。

  3. 将外部工具输出添加到光标位置使用中,例如

put=system('blah blah')

这是合法的,因为(某些)命令可以接受表达式,包括函数调用。

不过,请确保逃脱“ bar”和“双引号”,因为(有时)它们在vimscript中很特别。

  1. A command can't return value. Hence a command is not an expression. And in particular, commands never can be "nested" one into another, like function calls. Cf. Shell scripting, for example.

  2. In principle, there are some tricks, like a builtin function that accepts command name, runs it, and returns output as string value. But this is rather "convenient redir", not "syntax breaker".

  3. To add external tool output into cursor position use, for example,

put=system('blah blah')

This is legal, as (some of) commands may accept expressions, including function calls.

Make sure to escape "bars" and "double quotes" though, as (sometimes) they are special in VimScript.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文