Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: pipe register to external command

Tags:

vim

How can I pipe the contents of a register to the standard input of an external command? I intuitively tried the following, but it doesn't work (may serve to illustrate my need, though):

:"0w !some_command
like image 777
slezica Avatar asked May 28 '12 06:05

slezica


1 Answers

If contents of the register does not happen to contain NULLs then it is as simple as

call system('some_command', getreg('r', 1, 1) + (getregtype('r') isnot# 'v' ? [''] : []))

. This form will also preserve NULs which may happen to live inside register, if you know you do not have that you may use @r in place of getreg() call. Note though that getreg('r', 1, 1) will not have trailing newline even if you copied text in linewise mode which is why I have written + (getregtype('r') isnot# 'v' ? [''] : []) to add it (form @r does not have this problem).

like image 82
ZyX Avatar answered Sep 19 '22 13:09

ZyX