Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write value of variable into current edit file in vim script

Tags:

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") 
like image 578
songhir Avatar asked Aug 13 '13 04:08

songhir


People also ask

What is let G in Vim?

l: local to a function. g: global. :help internal-variables. Follow this answer to receive notifications.

What is VimL script?

Vim script (aka Vimscript, or VimL) is a full feature scripting language, meaning it can solve almost any text processing problem.


1 Answers

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>)

like image 78
FDinoff Avatar answered Sep 24 '22 00:09

FDinoff