gpt4 book ai didi

vim - 如何在vim脚本中将变量的值写入当前编辑文件

转载 作者:行者123 更新时间:2023-12-02 01:47:14 25 4
gpt4 key购买 nike

我在 vim 的脚本中获取变量的值,以及如何将其写入我现在正在编辑的文件中。

例如

"=== get date
let TodayDate=system("date")

最佳答案

您可以使用:put将变量(或表达式)的内容放入当前缓冲区

:put =TodayDate

:h :put的帮助

                                                        :pu :put
:[line]pu[t] [x] Put the text [from register x] after [line] (default
current line). This always works linewise, thus
this command can be used to put a yanked block as new
lines.
The cursor is left on the first non-blank in the last
new line.
The register can also be '=' followed by an optional
expression. The expression continues until the end of
the command. You need to escape the '|' and '"'
characters to prevent them from terminating the
command. Example:
:put ='path' . \",/test\"
If there is no expression after '=', Vim uses the
previous expression. You can see it with ":dis =".
<小时/>

用于映射和编辑 <C-R>=可能比 :put 更好因为它允许您使用表达式寄存器并输出光标位置的内容。 (看看:h <C-R>)

关于vim - 如何在vim脚本中将变量的值写入当前编辑文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18200435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com