vim のスクリプトで変数の値を取得し、現在編集中のファイルにそれを書き込む方法を説明します。
例えば
"=== get date
let TodayDate=system("date")
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>
)
以下はいかがでしょうか?
execute "normal! i" . TodayDate
これにより、挿入モードになり、TodayDate のコンテンツがカーソル位置に挿入されます。