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

assign current line under cursor to extern program

Expand Messages
  • jerikmail@googlemail.com
    Hi, I want to assign the current line under the cursort to an external program. Example Textfile: 1 foo 2 bar 3 calvin 4 hobbes If the cursor is in line 2,
    Message 1 of 8 , Nov 29, 2007
      Hi,

      I want to assign the current line under the cursort to an external
      program. Example

      Textfile:
      1 foo
      2 bar
      3 calvin
      4 hobbes

      If the cursor is in line 2, want to assign the line "2 bar" to a
      script, like foo.sh.

      If I want to call a external script from vim I type in the command
      modus:

      :! foo.sh [and hit enter]

      Now I want to assign the line in the file to the script via a function
      into the .vimrc.

      I know how to get the line, but I dont know how to assign it to the
      external script. Or better I dont know how to use the variale to
      assign the parameter to the script. Basicly I have this in my .vimrc

      function Foo( )
      :let start=line( '.' )
      :! foo.sh getline(start) "this dont work :(
      endfunction

      command Foo call Foo( )

      This returns the errormessage:
      /bin/bash: -c: line 0: syntax error near unexpected token `('
      /bin/bash: -c: line 0: ` foo.sh getline( start )'

      ideas ?

      cheers -- jerik

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Tony Mechelynck
      ... exe !foo.sh getline(start) otherwise you pass getline(start) to the shell as a literal part of the command string: Vim does not evaluate it. With
      Message 2 of 8 , Nov 29, 2007
        jerikmail@... wrote:
        > Hi,
        >
        > I want to assign the current line under the cursort to an external
        > program. Example
        >
        > Textfile:
        > 1 foo
        > 2 bar
        > 3 calvin
        > 4 hobbes
        >
        > If the cursor is in line 2, want to assign the line "2 bar" to a
        > script, like foo.sh.
        >
        > If I want to call a external script from vim I type in the command
        > modus:
        >
        > :! foo.sh [and hit enter]
        >
        > Now I want to assign the line in the file to the script via a function
        > into the .vimrc.
        >
        > I know how to get the line, but I dont know how to assign it to the
        > external script. Or better I dont know how to use the variale to
        > assign the parameter to the script. Basicly I have this in my .vimrc
        >
        > function Foo( )
        > :let start=line( '.' )
        > :! foo.sh getline(start) "this dont work :(

        exe "!foo.sh" getline(start)

        otherwise you pass "getline(start)" to the shell as a literal part of the
        command string: Vim does not evaluate it. With ":exe", Vim evaluates each
        expression, adds a space between each separate expression, and executes the
        result as an ex-command. ":echo" does the same but displays the evaluated
        expressions instead, so replacing ":exe" by ":echo" above would let you see
        what command your shell would receive.

        > endfunction
        >
        > command Foo call Foo( )
        >
        > This returns the errormessage:
        > /bin/bash: -c: line 0: syntax error near unexpected token `('
        > /bin/bash: -c: line 0: ` foo.sh getline( start )'
        >
        > ideas ?
        >
        > cheers -- jerik

        Best regards,
        Tony.
        --
        This sentence contradicts itself -- no actually it doesn't.
        -- Hofstadter


        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_dev" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Milan Vancura
        ... all chars are important (their order etc.): . means current line; see :help :range w ! is important to write well as it is a big difference between
        Message 3 of 8 , Nov 30, 2007
          >
          > Hi,
          >
          > I want to assign the current line under the cursort to an external
          > program. Example
          >
          > Textfile:
          > 1 foo
          > 2 bar
          > 3 calvin
          > 4 hobbes
          >
          > If the cursor is in line 2, want to assign the line "2 bar" to a
          > script, like foo.sh.

          :.w !foo.sh


          all chars are important (their order etc.):

          '.' means current line; see ':help :range'
          "w !" is important to write well as it is a big difference between ':w! ' and
          ':w !'

          No functions are needed. This is vim, not emacs :-)

          Milan
          --
          Milan Vancura, Prague, Czech Republic, Europe

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_dev" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Charles E Campbell Jr
          ... * the : s aren t needed in your Foo function; you re already in Ex mode. * some reading is in order; read the help on exe, filter, system() Your Foo
          Message 4 of 8 , Nov 30, 2007
            jerikmail@... wrote:

            >Hi,
            >
            >I want to assign the current line under the cursort to an external
            >program. Example
            >
            >Textfile:
            >1 foo
            >2 bar
            >3 calvin
            >4 hobbes
            >
            >If the cursor is in line 2, want to assign the line "2 bar" to a
            >script, like foo.sh.
            >
            >If I want to call a external script from vim I type in the command
            >modus:
            >
            >:! foo.sh [and hit enter]
            >
            >Now I want to assign the line in the file to the script via a function
            >into the .vimrc.
            >
            >I know how to get the line, but I dont know how to assign it to the
            >external script. Or better I dont know how to use the variale to
            >assign the parameter to the script. Basicly I have this in my .vimrc
            >
            >function Foo( )
            > :let start=line( '.' )
            > :! foo.sh getline(start) "this dont work :(
            >endfunction
            >
            >command Foo call Foo( )
            >
            >This returns the errormessage:
            >/bin/bash: -c: line 0: syntax error near unexpected token `('
            >/bin/bash: -c: line 0: ` foo.sh getline( start )'
            >
            >
            * the ":"s aren't needed in your "Foo" function; you're already in Ex mode.
            * some reading is in order; read the help on exe, filter, system()

            Your Foo function got the current line number, then passed
            ! foo.sh getline(start)

            to the shell. You shell didn't know what to do with getline(start),
            which I'm supposing was intended not for the shell to handle but for
            vim. Consider

            exe "!foo.sh '".getline(start)."'"

            or

            call system("foo.sh '".getline(start)."'")

            where I'm quoting the entire string received from getline in single quotes.

            Regards,
            Chip Campbell


            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_dev" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • jerikmail@googlemail.com
            ... Works fine. like expected. Thanks -- jerik --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_dev maillist. For
            Message 5 of 8 , Nov 30, 2007
              > exe "!foo.sh" getline(start)

              Works fine. like expected.

              Thanks -- jerik
              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_dev" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • jerikmail@googlemail.com
              ... I tried but did not work. Cause the directory was not in the PATH, I had to use :.w !./foo.sh foo.sh: echo $* a.txt after the command, a.txt had only one
              Message 6 of 8 , Nov 30, 2007
                > :.w !foo.sh

                I tried but did not work. Cause the directory was not in the PATH, I
                had to use :.w !./foo.sh

                foo.sh: echo $* > a.txt

                after the command, a.txt had only one empty line.

                This returned an empty line.
                >
                > all chars are important (their order etc.):
                >
                > '.' means current line; see ':help :range'
                > "w !" is important to write well as it is a big difference between ':w! ' and
                > ':w !'
                >
                > No functions are needed. This is vim, not emacs :-)

                Would be nice if it would work ;)

                cheers -- jerik

                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_dev" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • Gary Johnson
                ... I think Milan did not understand your request. ... will write the current line to the standard input of the command following the exclamation point (!),
                Message 7 of 8 , Nov 30, 2007
                  On 2007-11-30, "jerikmail@..." <jerikmail@...> wrote:

                  > On 2007-11-30, Milan Vancura <milan@...> wrote:

                  > > :.w !foo.sh
                  >
                  > I tried but did not work. Cause the directory was not in the PATH, I
                  > had to use :.w !./foo.sh
                  >
                  > foo.sh: echo $* > a.txt
                  >
                  > after the command, a.txt had only one empty line.
                  >
                  > This returned an empty line.

                  I think Milan did not understand your request.

                  :.w !foo.sh

                  will write the current line to the standard input of the command
                  following the exclamation point (!), whereas what you are looking
                  for is a way to pass the current line as a set of arguments to a
                  command.

                  On the other hand, if foo.sh is something you have written yourself,
                  another way to solve this problem would be to write foo.sh to accept
                  its data from standard input instead of as command-line arguments.
                  Then you _could_ just execute

                  :.w !./foo.sh

                  > > No functions are needed. This is vim, not emacs :-)

                  It's true that functions are not needed here, but there is no reason
                  to avoid them, either.

                  Regards,
                  Gary


                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_dev" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • jerikmail@googlemail.com
                  Hi, [.w !foo.sh explanation] ... Right now, it works fine for me with the assigned command-line arguments. Furthermore I dont know how to write a shell/ruby
                  Message 8 of 8 , Dec 1, 2007
                    Hi,

                    [.w !foo.sh explanation]

                    > On the other hand, if foo.sh is something you have written yourself,
                    > another way to solve this problem would be to write foo.sh to accept
                    > its data from standard input instead of as command-line arguments.
                    > Then you _could_ just execute
                    >
                    > :.w !./foo.sh

                    Right now, it works fine for me with the assigned command-line
                    arguments. Furthermore I dont know how to write a shell/ruby script to
                    accept data from input standard.

                    But thanks for the tip and explanation.

                    cheers -- jerik
                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_dev" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  Your message has been successfully submitted and would be delivered to recipients shortly.