Results 1 to 3 of 3
I would like to do the following:
(1) save the contents of the current line being edited in VI (and ideally also the cursor position on that line)
(2) export ...
- 11-25-2010 #1Just Joined!
- Join Date
- Nov 2010
- Posts
- 2
exporting line from vi/vim to shell for use in script
I would like to do the following:
(1) save the contents of the current line being edited in VI (and ideally also the cursor position on that line)
(2) export this line as input to a perl script
(3) perform several actions on that line from the perl script
Ideally, I would like all this to be possible by typing a single command in vi.
Is something like this possible? If so, could someone give me some guidance on how it might be done? I know, for instance, that a command like :6,8 !lpr will send lines 6-8 to the printer. I'm imagining that an appropriate modification of such a command might be what I want, but I'm not exactly sure. Thanks.
-a
- 11-26-2010 #2
You sure can. There are two ways to do this.
Approach 1 is to use an external Perl script that you've already written. In that case, you can choose a number of lines and use the ! command to filter them through an external program. See ":help !" for more information. This is what you proposed before. So for instance, if you wanted to filter lines 6-8, you could say:
The second approach is to use Vim's built-in Perl scripting functionality to actually run arbitrary Perl code from within Vim. See ":help perl" (and more specifically, ":help :perldo") for more information. This does require that your Vim was compiled with Perl support.Code::6,8 !my_perl_script_that_does_something
DISTRO=Arch
Registered Linux User #388732
- 08-03-2011 #3Just Joined!
- Join Date
- Nov 2010
- Posts
- 2
Thank you Cabhan. Your reply was very helpful to me.
-a


Reply With Quote