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

passing local variable to shell howto

Expand Messages
  • Shaw Vrana
    Hi All, I m trying to write a simple vim function that prompts me for a filename and then calls an external shell script with the entered filename, and then
    Message 1 of 3 , Mar 1, 2005
    • 0 Attachment
      Hi All,

      I'm trying to write a simple vim function that prompts me for a filename and
      then calls an external shell script with the entered filename, and then loads
      the file. Here's what I have so far.

      fun! GetFile()
      let myfilename = input("Filename? )
      !my_script myfilename
      e myfilename
      endfun

      This almost works, but it doesn't look like my_script is getting the value I
      entered for myfilename, though it is being assigned the value, and my_script
      is being called. I guess this is b/c I'm using the ! operator? How can I
      call my_script with the myfilename input?

      Any pointers or help pages greatly appreciated!

      Thanks,
      Shaw
    • A. J. Mechelynck
      ... With the above, both the script and the :e command will get myfilename (i.e., the name, not the contents, of the Vim variable). Try exe !my_script
      Message 2 of 3 , Mar 1, 2005
      • 0 Attachment
        Shaw Vrana wrote:
        > Hi All,
        >
        > I'm trying to write a simple vim function that prompts me for a filename and
        > then calls an external shell script with the entered filename, and then loads
        > the file. Here's what I have so far.
        >
        > fun! GetFile()
        > let myfilename = input("Filename? )
        > !my_script myfilename
        > e myfilename
        > endfun
        >
        > This almost works, but it doesn't look like my_script is getting the value I
        > entered for myfilename, though it is being assigned the value, and my_script
        > is being called. I guess this is b/c I'm using the ! operator? How can I
        > call my_script with the myfilename input?
        >
        > Any pointers or help pages greatly appreciated!
        >
        > Thanks,
        > Shaw
        >
        >
        >
        With the above, both the script and the ":e" command will get
        "myfilename" (i.e., the name, not the contents, of the Vim variable). Try

        exe "!my_script" myfilename
        exe "edit" myfilename

        instead.

        HTH,
        Tony.
      • Shaw Vrana
        ... Good response time! I love this list. Your tipped worked great. After adding a silent before the exec, I get exactly what I want. Thanks! Shaw
        Message 3 of 3 , Mar 1, 2005
        • 0 Attachment
          On Tuesday 01 March 2005 02:15 pm, A. J. Mechelynck wrote:
          > exe "!my_script" myfilename
          > exe "edit" myfilename

          Good response time! I love this list.

          Your tipped worked great. After adding a silent before the exec, I get
          exactly what I want.

          Thanks!
          Shaw
        Your message has been successfully submitted and would be delivered to recipients shortly.