I get a variable's value in vim's script, and how to write it into the file I'm editing now.
e.g.
"=== get date let TodayDate=system("date")
l: local to a function. g: global. :help internal-variables. Follow this answer to receive notifications.
Vim script (aka Vimscript, or VimL) is a full feature scripting language, meaning it can solve almost any text processing problem.
You can use :put
to put the contents of the variable (or expression) into the current buffer
:put =TodayDate
The help for :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 =".
For mappings and editing <C-R>=
is probably better than :put
since it allows you to use the expression register and output the contents at the cursor location. (Take a look at :h <C-R>
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With