Loading ...
Sorry, an error occurred while loading the content.

Re: Use vim as filter?

Expand Messages
  • Michael Naumann
    ... Benji - I think this is a hard question. Unfortunatly there doesn t seem to be a pure vim-way of doing this. My first idea looked like ls | vim - -es -c
    Message 1 of 4 , Apr 1, 2002
    • 0 Attachment
      01.04.2002 21:12:44, Benji Fisher <benji@...> wrote:

      > Can vim be used as a filter, like sed? For example,
      >
      >% ls | vim - --other-options
      >
      >I think the - option makes vim read a buffer from stdin, but how do we get it
      >to write to stdout? I especially want this to work on Windows, where sed may
      >not be available.
      >
      > Background: If I run :make then the compiler output is saved to an error
      >file. AFAIK, I do not have a chance to clean up that error file, except by
      >adding a filter to 'makeprg'. If I am running vim on Windows, I would like to
      >use vim itself as the filter program.
      >
      > I might also want to do the same for 'equalprg'.
      >
      > --Benji Fisher
      >

      Benji -

      I think this is a hard question. Unfortunatly there doesn't seem to be
      a pure vim-way of doing this.

      My first idea looked like
      ls | vim - -es -c "your command here" -c :%print -c :q!
      But this gave me lot of escape sequences. Maybe you know how to avoid them.

      My second try was more successful
      If you have +perl in :ver (and perl is installed), you can use
      ls | vim - -es -c "your vim command here" -c 'perl $\="\n"' -c ':%perldo print' -c :q!

      The first perl-statement
      perl $\="\n"
      determines the lineseperator in output.
      Under Windows you probably may want to set it to
      perl $\="\r\n"

      The second perl-statement prints the lines
      :%perldo print


      python or tcl may also be good candidates for this kind of misuse.

      I think, each solution using vim will not act as a filter like sed or perl, which
      are able intermix reading and writing. A vim-solution will most likely need to
      first read all the input and at the end create output. This may or may not be of
      any meaning and most likely is not in your :make - example.

      HTH, Michael
    • Preben Guldberg
      ... Iirc, you don t. ... A very crude hack. With a stdout.vim file reading silent exec w . tempname() silent !type % silent !del % q! you could invoke vim
      Message 2 of 4 , Apr 1, 2002
      • 0 Attachment
        Thus wrote Benji Fisher (benji@...) on [020401]:
        > Can vim be used as a filter, like sed? For example,

        > % ls | vim - --other-options

        > I think the - option makes vim read a buffer from stdin, but how do we get it
        > to write to stdout?

        Iirc, you don't.

        > I especially want this to work on Windows, where sed may
        > not be available.

        A very crude hack. With a stdout.vim file reading

        silent exec 'w ' . tempname()
        silent !type %
        silent !del %
        q!

        you could invoke vim as

        % ... | vim -c "so .../stdout.vim" -

        Not sure how "-s script" works with file in dos format, so I did not
        like to use it here. Alternatively, use ":runtime dosutils/stdout.vim".

        Not sure either how the type and del commands work from within vim
        under windows (does it still pop up windows with dos prompts?).

        Also, you would have to get rid off the leading "Vim: Reading from
        stdin..." and trailing blank line.

        Peppe [tested the equivalent on a unix box]
        --
        "Before you criticize someone, walk
        Preben "Peppe" Guldberg __/-\__ a mile in his shoes. That way, if
        c928400@... (o o) he gets angry, he'll be a mile away
        ----------------------oOOo (_) oOOo-- - and barefoot." --Sarah Jackson
      • Ingo Krabbe
        ... Hash: SHA1 ... I think you should think over what you want to do. Since the 70 s when the first vi came out for some UNIX Computer it was thought as a
        Message 3 of 4 , Apr 1, 2002
        • 0 Attachment
          -----BEGIN PGP SIGNED MESSAGE-----
          Hash: SHA1

          On Monday, 1. April 2002 21:12, Benji Fisher wrote:
          > Can vim be used as a filter, like sed? For example,
          >
          > % ls | vim - --other-options
          >
          > I think the - option makes vim read a buffer from stdin, but how do we get
          > it to write to stdout? I especially want this to work on Windows, where
          > sed may not be available.
          >
          > Background: If I run :make then the compiler output is saved to an
          > error file. AFAIK, I do not have a chance to clean up that error file,
          > except by adding a filter to 'makeprg'. If I am running vim on Windows, I
          > would like to use vim itself as the filter program.
          >
          > I might also want to do the same for 'equalprg'.
          >
          > --Benji Fisher

          I think you should think over what you want to do. Since the 70's when the
          first vi came out for some UNIX Computer it was thought as a "VISUAL" editor.
          That's where the name comes from. Now you want to make it invisible again.

          First, if you like System V,X/Open or Posix, all our nice UNIX standards, you
          should try to install a cygwin or something similar for your Windows. Then
          you can work with most of the well known commands like ed/sed ...

          Most solutions you can find with other concepts might be much more flexible
          and useful. But if you don't use a "|vim -" to read from stdin you should
          also be able to call vim commands through stdin:

          # This example only works for unix of course.
          cat cmd-script| vim bla bla &> /dev/null

          CU INGO
          -----BEGIN PGP SIGNATURE-----
          Version: GnuPG v1.0.6 (GNU/Linux)
          Comment: For info see http://www.gnupg.org

          iD8DBQE8qVGoy6Pb53AsRKkRAidYAJ9v4PW+eppj+OLQm/53vSEqYtctagCgm+T8
          GeDIcfl72rtreZkUvXhlf5c=
          =gUkS
          -----END PGP SIGNATURE-----
        Your message has been successfully submitted and would be delivered to recipients shortly.