in reply to Re: Piping data to vim
in thread Piping data to vim

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

Replies are listed 'Best First'.
Re^3: Piping data to vim
by roboticus (Chancellor) on Nov 19, 2010 at 06:07 UTC

    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!
Re^3: Piping data to vim
by cdarke (Prior) on Nov 19, 2010 at 12:23 UTC
    The batch version of vi(1) is called sed(1). However perl is more powerful.
Re^3: Piping data to vim
by tod222 (Pilgrim) on Nov 19, 2010 at 20:21 UTC

    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.