Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Piping data to vim

by roboticus (Chancellor)
on Nov 19, 2010 at 03:53 UTC ( [id://872415]=note: print w/replies, xml ) Need Help??


in reply to Piping data to vim

yoda54:

You're using perl to automate vim? That just makes my head hurt. Why not just edit the text using standard perl features? I can only assume that there are some vim packages you have installed that you're trying to take advantage of.

Anyway, if you want to automate vim from a perl script, it appears that Rolf already has you covered.

You could also call your perl script from within vim, if that would help things. For example, I frequently call out to the sort command to sort data in a document while in vim. There's no reason you can't call a perl script to process a section of text.

Or even uglier: you could have your perl script open a document in vim, and then tell it to execute a perl script from within vim. That'll certainly help you keep your job "interesting".

...roboticus

Replies are listed 'Best First'.
Re^2: Piping data to vim
by yoda54 (Monk) on Nov 19, 2010 at 04:50 UTC
    What I need is a editor for data inside my perl script. Rather then writing my own I was thinking I could use vim instead.

    Thanks

      yoda54:

      I see. You may want to check out a few things on CPAN, then. I just took a brief look and found:

      • Proc::InvokeEditor: This module provides the ability to supply some text to an external text editor, have it edited by the user, and retrieve the results.
      • AnyEvent::EditText: This little module will start a text editor in a seperate process without stopping the current process. Usually something like a terminal with a vim instance running in it will be started, but also a graphical editor could be used (like gedit or gvim).
      • Term::CallEditor: This module calls an external editor with an optional text message via the solicit() function, then returns any data from this editor as a file handle. By default, the EDITOR environment variable will be used, otherwise vi.
      • Term::EditorEdit: Term::EditorEdit is a tool for prompting the user to edit a piece of text via $VISUAL or $EDITOR and return the result
      • Term::ReadLine::Zoid:This package provides a set of modules that form an interactive input buffer written in plain perl with minimal dependencies. It features almost all key-bindings described in the posix spec for the sh(1) utility with some extensions like multiline editing; this includes a vi-command mode with a save-buffer (for copy-pasting) and an undo-stack.

      Some of those look interesting. (There were a few pages of stuff that didn't look interesting, though...)

      ...roboticus

        Thanks you!
      The batch version of vi(1) is called sed(1). However perl is more powerful.

      Few proficient Perl programmers would choose your method, which is why you're not finding code already written to do this.

      As others have said, Perl's editing features are powerful. It seems like the reason you're looking to use vim is that your proficiency with vim is greater than with Perl. If so, the correct approach is to improve your proficiency with Perl and edit your data using Perl instead of kludging something with vim.

      If the data can be represented in a config format, there are many modules available to be used; just do a CPAN search on 'config'.

      Even if your data isn't nicely represented in a config format, it's possible that CPAN may contain a module which will solve your problem without using an external editor.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://872415]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-24 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found