22

我在 vim 的脚本中得到一个变量的值,以及如何将它写入我现在正在编辑的文件中。

例如

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

2 回答 2

48

您可以使用: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>

于 2013-08-13T04:03:35.337 回答
3

下面的呢?

execute "normal! i" . TodayDate

这将使您进入插入模式并在光标位置插入 TodayDate 的内容。

于 2020-04-25T20:49:31.543 回答