views:

80

answers:

2

Potentially 2 questions in one. I would like to know how to reference a register in Ex mode.

For instance, I'm editing a file and I want to save the file with a timestamp (or just datestamp really) appended to it.

I know I can set register to the value of a shell commands output using:

:let @a = system("date +\"%Y-%m-%d\"")

Is there any to dereference this register and insert its value into an Ex command? Something like:

:w testfile.<value of "a register>

Copying to the system clipboard and pasting would be nice, but doing it in a more generic/programitic way for building on other commands in the future would be nice.

+1  A: 

Assuming register "a", you can type:

<CTRL-R>a which will input the value of register a inline at that point. This can be used in insert mode as well.

Trent Davies
Yeah, knew about that, looking for a way to do it without having to paste it in. No particular reason, but would be nice to have something that would automatically dereferences the variable
Peck
+3  A: 

There are two approaches to doing this, but probably neither are exactly what you want.

  1. Use <CTRL-R>a to insert the contents in the current command line. See :help c_CTRL-R for more info.

  2. Use exe to allow insertion of variables into the expression. See :help :exe and :help 41.3.

    :exe 'w testfile.' . @a
    
Al