Let say I've register which has string stored in it, but I'd like to use substitute command to change it.

For example I've 5x5 html table:

let @t='<table>'.repeat('<tr>'.repeat('<td>_</td>',5).'</tr>',5).'</table>'

and I'd like to replace placeholder (_) with some other data ideally by modifying existing register (not assigning to another).

I've tried the following syntax:

"@ts/_/test/g " with modifiable set

which doesn't give any errors, but it doesn't work as expected (in similar way as prefixing with % works).

What's the proper way of doing that?

  • You look like you want something like Emmet. Commented Mar 23, 2015 at 19:56
  • 2
    Note that :help function-list is a very useful page ;-) There are also some other tags in that page, such as string-functions. Commented Mar 24, 2015 at 13:47

2 Answers 2


Ex commands work on the buffer contents; for register (or variable) contents, you need to use a corresponding Vimscript function (if it exists).

For :substitute, the equivalent is substitute() (that was easy, right?) So:

:let @t = substitute(@t, '_', 'test', 'g')
  • 3
    substitute() isn't completely equivalent to :substitute; the function behaves as if 'magic' is set and 'cpoptions' is empty, whereas the command will observe user-set values.
    – tommcdo
    Commented Mar 23, 2015 at 22:05

Apart from using the let-statement and dealing with vim-script, you need to paste it into a buffer and then yank it back to the register:

  1. "tp
  2. :.s/_/test/g
  3. "tdd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.