Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output register value to stdout like :!echo command in vim?

Tags:

vim

I have done this:

:reg a

"a   iabc

I want to output the value in register a like :w !xargs -n1 echo command, but not all buffer content just the register value.

Thx in advanced!

like image 888
Big Shield Avatar asked Jan 05 '23 14:01

Big Shield


2 Answers

:echo getreg('a')

getreg([{regname} [, 1 [, {list}]]])

The result is a String, which is the contents of register {regname}. Example:

:let cliptext = getreg('*') 

When {regname} was not set the result is an empty string.

getreg('=') returns the last evaluated value of the expression register. (For use in maps.) getreg('=', 1) returns the expression itself, so that it can be restored with setreg(). For other registers the extra argument is ignored, thus you can always give it. If {list} is present and TRUE, the result type is changed to List. Each list item is one text line. Use it if you care about zero bytes possibly present inside register: without third argument both NLs and zero bytes are represented as NLs (see NL-used-for-Nul). When the register was not set an empty list is returned. If {regname} is not specified, v:register is used.

like image 85
Ry- Avatar answered Jan 07 '23 02:01

Ry-


Wrap in exe to use the value of getreg within a vim command:

:exe ":!echo ".getreg('a')
like image 40
Adam Bildersee Avatar answered Jan 07 '23 03:01

Adam Bildersee