tags:

views:

79

answers:

2

I want to filter the content of a register (in my case, the clipboard register "+) through an external command before pasting it into the buffer.

There should be a solution along the lines of http://stackoverflow.com/questions/1694392/, but I just don't seem to be able to figure it out.

+1  A: 
:let @a = system("ls -l " . shellescape(@+))

Seems to work here.

profjim
that does not filter the contents of "+.Also it is missing a ).
0x89
You're right I dropped the final ')'. Fixed. But it was working here a moment ago. Let me investigate... Yeah, still works. Are you sure "+ has a valid value when you're testing? It wasn't overwritten because you copied and pasted from your browser, for example? (I made that mistake myself.)
profjim
ah, Luc's comment made me realize what you were probably missing. I was using the same example format from the linked question. Yeah, just pipe or do whatever you want in the string you supply to system().
profjim
your answer still does not filter anything.
0x89
+3  A: 

system() is the way to go. :h system().

You can use the old fashion way (the one that gives you a full control as you would be able to pipe and redirect as many times as it pleases you):

:let res = system("echo ".shellescape(@+)." | the-filter-command")
:put=res

However, you may have issues with line-endings (the last character needs to be chomped). Hence this second solution where vim uses a temporary file and pass it to the filter program:

:let res = system(the-filter-command, @+)
:put=res

There is also another way to accomplish this if you play with another buffer:

:new
:put=@+
:%!the-filter-command
:%d +
:bd
:put=@+

Last note: Vim already has a few filters of its own like :sort, uniq is also possible natively (but a little bit more complex), ...

Luc Hermitte