'vim run perl script with word under cursor as argument

is it possible to send the word under the cursor to a perl script by typing a shortcut?

how do i do that?



Solution 1:[1]

Given a perl script ${HOME}/test.pl, you could use:

:nnoremap <F2> :!${HOME}/test.pl <C-R><C-W><CR>

Then pressing F2 would send the word under the cursor to your script.

As per my answer to your previous question, CTRL-R CTRL-W represents the word under the cursor.

See the following help topics in Vim to get you started with writing keyboard shortcuts:

My test script:

#!/usr/bin/env perl -w
print "You selected '$ARGV[0]'.\n";

Solution 2:[2]

You can do the following:

nnoremap <f5> :!perl my_script.pl <c-r><c-w><enter>

In your vimrc, this lines maps the F5 key to this combination of characters. CTRL-R CTRL-W inserts current word in a command line.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 Benoit