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

convert vim variable contents into a file

Expand Messages
  • Zdenek Sekera
    Hi, I have a variable g:list= a nb nc nd n so :echo g:list displays a b c d ... (of course this is schematics) so I could later use grep on it, something
    Message 1 of 3 , May 19, 2005
    • 0 Attachment
      Hi,

      I have a variable
      g:list="a\nb\nc\nd\n"

      so :echo g:list displays

      a
      b
      c
      d

      I'd like to turn it into a file, something like:

      :echo g:list > /tmp/myfile
      (of course this is schematics)

      so I could later use grep on it, something like:

      let a=system(echo g:list | grep regexp)

      or

      let a=system(echo /tmp/myfile | grep regexp)

      I can't figure out how to do it.
      Am I overlooking anything obvious?

      Thanks and cheers,

      ---Zdenek

      ----------------------------------------
      Zdenek Sekera | zdenek.sekera@...
      LHC Computing Grid Project | mobile: +41-76-487.4971
      CERN - IT Division | tel: +41-22-767.1068
    • Keith Roberts
      ... How about: redir /tmp/myfile | echo g:list | redir end -Keith
      Message 2 of 3 , May 19, 2005
      • 0 Attachment
        >-----Original Message-----
        >From: Zdenek Sekera [mailto:Zdenek.Sekera@...]
        >Sent: Thursday, May 19, 2005 5:40 AM
        >To: vim-dev@...
        >Subject: convert vim variable contents into a file
        >
        >Hi,
        >
        >I have a variable
        >g:list="a\nb\nc\nd\n"
        >
        >so :echo g:list displays
        >
        >a
        >b
        >c
        >d
        >
        >I'd like to turn it into a file, something like:
        >
        > :echo g:list > /tmp/myfile
        > (of course this is schematics)
        >
        >so I could later use grep on it, something like:
        >
        > let a=system(echo g:list | grep regexp)
        >
        >or
        >
        > let a=system(echo /tmp/myfile | grep regexp)
        >
        >I can't figure out how to do it.
        >Am I overlooking anything obvious?
        >
        >Thanks and cheers,
        >
        >---Zdenek

        How about:

        redir /tmp/myfile | echo g:list | redir end

        -Keith
      • Zdenek Sekera
        ... Clever! Thanks! Slight obvious correction: redir /tmp/myfile | echo g:list | redir end
        Message 3 of 3 , May 19, 2005
        • 0 Attachment
          > -----Original Message-----
          > From: Keith Roberts [mailto:kroberts@...]
          > Sent: 19 May 2005 17:31
          > To: Zdenek Sekera; vim-dev@...
          > Subject: RE: convert vim variable contents into a file
          >
          > >-----Original Message-----
          > >From: Zdenek Sekera [mailto:Zdenek.Sekera@...]
          > >Sent: Thursday, May 19, 2005 5:40 AM
          > >To: vim-dev@...
          > >Subject: convert vim variable contents into a file
          > >
          > >Hi,
          > >
          > >I have a variable
          > >g:list="a\nb\nc\nd\n"
          > >
          > >so :echo g:list displays
          > >
          > >a
          > >b
          > >c
          > >d
          > >
          > >I'd like to turn it into a file, something like:
          > >
          > > :echo g:list > /tmp/myfile
          > > (of course this is schematics)
          > >
          > >so I could later use grep on it, something like:
          > >
          > > let a=system(echo g:list | grep regexp)
          > >
          > >or
          > >
          > > let a=system(echo /tmp/myfile | grep regexp)
          > >
          > >I can't figure out how to do it.
          > >Am I overlooking anything obvious?
          > >
          > >Thanks and cheers,
          > >
          > >---Zdenek
          >
          > How about:
          >
          > redir /tmp/myfile | echo g:list | redir end

          Clever! Thanks! Slight obvious correction:

          redir > /tmp/myfile | echo g:list | redir end

          ---Zdenek
        Your message has been successfully submitted and would be delivered to recipients shortly.