5

I'm trying to edit the copy-paste buffer:

I have the following command:

nmap gfb :let .shellescape(getreg('0'))=1<br>

that should have put the number 1 into the buffer, which is not happening.

how do i put the output of a perl script into a vimscript buffer?

Xavier T.
  • 40,509
  • 10
  • 68
  • 97
john-jones
  • 7,490
  • 18
  • 53
  • 86
  • very relevant: http://stackoverflow.com/questions/2471175/vim-replace-word-with-contents-of-paste-buffer @" is the copy-paste buffer. – john-jones Jan 02 '11 at 16:51

2 Answers2

3

To get the output of an external command into a vim buffer you use system:

:let @0 = system("/bin/ls")
:echo @0

I'm not sure how this relates to Perl exactly. You might want to edit your question to clarify.

Rob N
  • 1,015
  • 8
  • 20
  • okey so in order to get the output of a perl scrip i do: :let @0=system('perl /home/hermann/hi.pl') ? – john-jones Jan 02 '11 at 00:38
  • Something like that, yes. Of course `system` can be used anywhere you can use an expression - its not just for assignment. Try it and see! – Rob N Jan 02 '11 at 06:36
  • :let @0=222 doesn't work anymore, i dont know why but it doesn't change what gets pasted when i press p. it used to though so im not sure whats going on. – john-jones Jan 02 '11 at 10:50
  • the paste array is @", @0 is an array thats always changing and that was confusing me. it works now. – john-jones Jan 02 '11 at 17:06
  • on a related note: http://stackoverflow.com/questions/4579905/get-perl-script-output-into-vimscript – john-jones Jan 02 '11 at 19:24
  • You really should spend some time experimenting and reading the vim docs. Your questions suggest you have some gaps in your understanding. – Rob N Jan 03 '11 at 00:07
2

To store 1 inside register 0:

:let @0 = 1

To do this in vimscript via perl:

function! Foo()
perl << EOF
    my $foo = 1;
    VIM::DoCommand(':let @0 = ' . $foo);
EOF
endfunction

Then you can call that function:

:call Foo()
Naveed
  • 726
  • 1
  • 5
  • 12
  • This is totally in the direction, but i get the following error: E319: Sorry, the command is not available in this version: perl << EOF – john-jones Jan 01 '11 at 16:43
  • the solution to the e319 error was to do: sudo apt-get install vim-full in the shell. but now the let doesn't work. – john-jones Jan 02 '11 at 11:58
  • Just to be clear, you now have a vim with Perl support, which means the `perl` and `doperl` commands are now available to you. This won't change the other non-Perl stuff. – Rob N Jan 02 '11 at 13:07