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

Activating gVim from the command line (cont)

Expand Messages
  • His Nerdship
    The original post has been successfully addressed. In my last example, I was searching for haddock in fish.cpp. From the command line I can now successfully
    Message 1 of 11 , Aug 2, 2012
    • 0 Attachment
      The original post has been successfully addressed.
      In my last example, I was searching for 'haddock' in fish.cpp. From
      the command line I can now successfully open fish.cpp and have the
      cursor sitting on a haddock.
      But wait, there's more...
      I will also need to open the same file, again from the command line,
      but with a different search expression. Say fish.cpp is already open
      with haddock as the current search string, but this time I need to
      search for 'blobfish'.
      According to received wisdom, I should be able to issue another
      command with the --remote argument and bring up the same file but this
      time with the cursor sitting on a blobfish.

      gvim -c"/blobfish" +52 -c ":call search('blobfish','c')" --remote
      fish.cpp

      However there are 2 problems:
      1) If there are currently 2 or more Vim servers running, it will issue
      an error 'Swap file ".fish.cpp.swp" already exists'. This message
      always comes from the vim server that does NOT contain fish.cpp. I
      assume I have to force it to the server that already has fish.cpp open
      (with the --server arg). But how can I tell which server it is?
      2) Even if it successfully opens up the existing vim server, it
      ignores the new search expression and continues to search for the
      previous one. In this case it is still looking for haddock even
      though I (should) have instigated a new search, for blobfish.
      Again, thanks in advance.

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Ben Fritz
      ... You can look at $VIMRUNTIME/macros/editexisting.vim for examples. But I think the easiest solution, since you re loading stuff from an external program,
      Message 2 of 11 , Aug 2, 2012
      • 0 Attachment
        On Thursday, August 2, 2012 3:02:42 AM UTC-5, His Nerdship wrote:
        > The original post has been successfully addressed.
        >
        > In my last example, I was searching for 'haddock' in fish.cpp. From
        >
        > the command line I can now successfully open fish.cpp and have the
        >
        > cursor sitting on a haddock.
        >
        > But wait, there's more...
        >
        > I will also need to open the same file, again from the command line,
        >
        > but with a different search expression. Say fish.cpp is already open
        >
        > with haddock as the current search string, but this time I need to
        >
        > search for 'blobfish'.
        >
        > According to received wisdom, I should be able to issue another
        >
        > command with the --remote argument and bring up the same file but this
        >
        > time with the cursor sitting on a blobfish.
        >
        >
        >
        > gvim -c"/blobfish" +52 -c ":call search('blobfish','c')" --remote
        >
        > fish.cpp
        >
        >
        >
        > However there are 2 problems:
        >
        > 1) If there are currently 2 or more Vim servers running, it will issue
        >
        > an error 'Swap file ".fish.cpp.swp" already exists'. This message
        >
        > always comes from the vim server that does NOT contain fish.cpp. I
        >
        > assume I have to force it to the server that already has fish.cpp open
        >
        > (with the --server arg). But how can I tell which server it is?
        >

        You can look at $VIMRUNTIME/macros/editexisting.vim for examples.

        But I think the easiest solution, since you're loading stuff from an external program, would be to always use the same Vim server for that external program. Launch Vim initially with a specific server name and set up your program to use that server name rather than the default.

        > 2) Even if it successfully opens up the existing vim server, it
        >
        > ignores the new search expression and continues to search for the
        >
        > previous one. In this case it is still looking for haddock even
        >
        > though I (should) have instigated a new search, for blobfish.
        >
        > Again, thanks in advance.

        --remote does not pass any of the -c commands on to the new server. --remote causes the Vim you invoke to use all the -c commands itself and then pass the file on to the other Vim server.

        You may need to use the --remote-expr or --remote-send flags instead of (or in addition to) the --remote flag. Also see the remote_expr(), remote_peek(), remote_read(), and remote_send() functions for use within an already-running Vim.

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • His Nerdship
        ... Thanks again Ben. I have found a solution which ticks all the above boxes: * It works both for a new Vim instance and an existing one (as long as the
        Message 3 of 11 , Aug 2, 2012
        • 0 Attachment
          On Aug 3, 12:39 am, Ben Fritz <fritzophre...@...> wrote:
          > You may need to use the --remote-expr or --remote-send flags instead of (or in addition to) the --remote flag. Also see the remote_expr(), remote_peek(), remote_read(), and remote_send() functions for use within an already-running Vim.- Hide quoted text -
          >
          > - Show quoted text -

          Thanks again Ben. I have found a solution which ticks all the above
          boxes:
          * It works both for a new Vim instance and an existing one (as long as
          the server name is the same, as you suggested)
          * A subsequent search works, i.e it will look for blobfish, not
          haddock:

          gvim --servername HgVim --remote-silent "+51;/blobfish/;:call
          search('blobfish','c')" fish.cpp

          However it adds a new twist, albeit a trivial one. I have to
          decrement 1 from the line number. In the above example, if 'blobfish'
          is on line 52 and I specify +52 in the command, it will actually start
          from line 53. This is not important as I can easily code around that,
          even if the search expression is on line 1 (just specify '+0').
          If you know of a way round this it would be good but as I said, it's
          not a showstopper.
          Really appreciate the help you give to me and everyone else.

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Christian Brabandt
          Hi His! ... Try separating the command range by , instead of ; See :h :; regards, Christian -- You received this message from the vim_use maillist. Do
          Message 4 of 11 , Aug 5, 2012
          • 0 Attachment
            Hi His!

            On Do, 02 Aug 2012, His Nerdship wrote:

            > On Aug 3, 12:39 am, Ben Fritz <fritzophre...@...> wrote:
            > > You may need to use the --remote-expr or --remote-send flags instead of (or in addition to) the --remote flag. Also see the remote_expr(), remote_peek(), remote_read(), and remote_send() functions for use within an already-running Vim.- Hide quoted text -
            > >
            > > - Show quoted text -
            >
            > Thanks again Ben. I have found a solution which ticks all the above
            > boxes:
            > * It works both for a new Vim instance and an existing one (as long as
            > the server name is the same, as you suggested)
            > * A subsequent search works, i.e it will look for blobfish, not
            > haddock:
            >
            > gvim --servername HgVim --remote-silent "+51;/blobfish/;:call
            > search('blobfish','c')" fish.cpp
            >
            > However it adds a new twist, albeit a trivial one. I have to
            > decrement 1 from the line number. In the above example, if 'blobfish'
            > is on line 52 and I specify +52 in the command, it will actually start
            > from line 53. This is not important as I can easily code around that,
            > even if the search expression is on line 1 (just specify '+0').
            > If you know of a way round this it would be good but as I said, it's
            > not a showstopper.
            > Really appreciate the help you give to me and everyone else.

            Try separating the command range by ',' instead of ';'

            See :h :;

            regards,
            Christian

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • His Nerdship
            ... Thanks Christian. I take it you mean this: gvim --servername HgVim --remote-silent +51,/blobfish/;:call search( blobfish , c ) fish.cpp i.e a comma
            Message 5 of 11 , Aug 6, 2012
            • 0 Attachment
              On Aug 6, 6:08 am, Christian Brabandt <cbli...@...> wrote:
              > Hi His!
              >
              >
              > Try separating the command range by ',' instead of ';'
              >
              > See :h :;
              >
              > regards,
              > Christian- Hide quoted text -
              >
              > - Show quoted text -

              Thanks Christian. I take it you mean this:

              gvim --servername HgVim --remote-silent "+51,/blobfish/;:call
              search('blobfish','c')" fish.cpp

              i.e a comma after the +51?
              I found that did not work - if the file is already open on, say, line
              80, it would just search from there. It would not go back to line 51
              to begin the search.
              The help suggested, as you said, that it should go back to 51. But it
              didn't!
              Have I failed the IQ test here? (It wouldn't be the first time! Ed)

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • Christian Brabandt
              Hi His! ... Actually, I meant something like this: gvim --servername HgVim --remote-silent +51,/blobfish/call search( blobfish , c ) fish.cpp But you could
              Message 6 of 11 , Aug 7, 2012
              • 0 Attachment
                Hi His!

                On Mo, 06 Aug 2012, His Nerdship wrote:

                > On Aug 6, 6:08 am, Christian Brabandt <cbli...@...> wrote:
                > > Hi His!
                > >
                > >
                > > Try separating the command range by ',' instead of ';'
                > >
                > > See :h :;
                > >
                > > regards,
                > > Christian- Hide quoted text -
                > >
                > > - Show quoted text -
                >
                > Thanks Christian. I take it you mean this:
                >
                > gvim --servername HgVim --remote-silent "+51,/blobfish/;:call
                > search('blobfish','c')" fish.cpp
                >
                > i.e a comma after the +51?

                Actually, I meant something like this:
                gvim --servername HgVim --remote-silent "+51,/blobfish/call
                search('blobfish','c')" fish.cpp

                But you could probably remove the range argument and add the /\%51l item
                to your regular expression, e.g.

                gvim --servername HgVim --remote-silent "+call
                search('\%51lblobfish','c')" fish.cpp


                regards,
                Christian

                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
              • Ben Fritz
                ... From previous discussion, he claims to want the first blobfish on or after line 51. While this could be done with the line number match, it seemed
                Message 7 of 11 , Aug 7, 2012
                • 0 Attachment
                  On Tuesday, August 7, 2012 5:35:18 AM UTC-5, Christian Brabandt wrote:
                  > Hi His!
                  >
                  >
                  >
                  > On Mo, 06 Aug 2012, His Nerdship wrote:
                  >
                  >
                  >
                  > > On Aug 6, 6:08 am, Christian Brabandt <cbli...@...> wrote:
                  >
                  > > > Hi His!
                  >
                  > > >
                  >
                  > > >
                  >
                  > > > Try separating the command range by ',' instead of ';'
                  >
                  > > >
                  >
                  > > > See :h :;
                  >
                  > > >
                  >
                  > > > regards,
                  >
                  > > > Christian- Hide quoted text -
                  >
                  > > >
                  >
                  > > > - Show quoted text -
                  >
                  > >
                  >
                  > > Thanks Christian. I take it you mean this:
                  >
                  > >
                  >
                  > > gvim --servername HgVim --remote-silent "+51,/blobfish/;:call
                  >
                  > > search('blobfish','c')" fish.cpp
                  >
                  > >
                  >
                  > > i.e a comma after the +51?
                  >
                  >
                  >
                  > Actually, I meant something like this:
                  >
                  > gvim --servername HgVim --remote-silent "+51,/blobfish/call
                  >
                  > search('blobfish','c')" fish.cpp
                  >
                  >
                  >
                  > But you could probably remove the range argument and add the /\%51l item
                  >
                  > to your regular expression, e.g.
                  >
                  >
                  >
                  > gvim --servername HgVim --remote-silent "+call
                  >
                  > search('\%51lblobfish','c')" fish.cpp
                  >
                  >
                  >
                  >
                  >
                  > regards,
                  >
                  > Christian

                  From previous discussion, he claims to want the first "blobfish" on or after line 51. While this could be done with the line number match, it seemed clearer to use a range.

                  But maybe try the line number match anyway, the pattern should be like '\%51l\_.\{-}\zsblobfish' (untested), which should match any number of characters including line endings on or after line 51, as few as possible until "blobfish" is encountered, and set the start of match to the start of "blobfish".

                  --
                  You received this message from the "vim_use" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php
                • Ben Fritz
                  ... I think the problem is you re using +52 as a range, meaning 52 lines after the current line . Since when you load a file Vim starts at line 1, this means
                  Message 8 of 11 , Aug 7, 2012
                  • 0 Attachment
                    On Thursday, August 2, 2012 10:16:55 PM UTC-5, His Nerdship wrote:
                    >
                    >
                    >
                    > gvim --servername HgVim --remote-silent "+51;/blobfish/;:call
                    >
                    > search('blobfish','c')" fish.cpp
                    >
                    >
                    >
                    > However it adds a new twist, albeit a trivial one. I have to
                    >
                    > decrement 1 from the line number. In the above example, if 'blobfish'
                    >
                    > is on line 52 and I specify +52 in the command, it will actually start
                    >
                    > from line 53. This is not important as I can easily code around that,
                    >
                    > even if the search expression is on line 1 (just specify '+0').
                    >
                    > If you know of a way round this it would be good but as I said, it's
                    >
                    > not a showstopper.
                    >
                    > Really appreciate the help you give to me and everyone else.

                    I think the problem is you're using +52 as a range, meaning "52 lines after the current line". Since when you load a file Vim starts at line 1, this means line 53.

                    Try using "52" instead of "+52", although I'm not quite sure why what you're doing works, because it looks to me at first glance like Vim should try to edit a file with a name equal to the command you gave rather than executing the command. I guess I need to read through the help on the --remote family again.

                    --
                    You received this message from the "vim_use" maillist.
                    Do not top-post! Type your reply below the text you are replying to.
                    For more information, visit http://www.vim.org/maillist.php
                  • Christian Brabandt
                    Hi Ben! ... It is even easier using the % l item: % 51lblobfish this finds the first blobfish after line 51. regards, Christian -- You received this
                    Message 9 of 11 , Aug 7, 2012
                    • 0 Attachment
                      Hi Ben!

                      On Di, 07 Aug 2012, Ben Fritz wrote:

                      > From previous discussion, he claims to want the first "blobfish" on or
                      > after line 51. While this could be done with the line number match, it
                      > seemed clearer to use a range.
                      >
                      > But maybe try the line number match anyway, the pattern should be like
                      > '\%51l\_.\{-}\zsblobfish' (untested), which should match any number of
                      > characters including line endings on or after line 51, as few as
                      > possible until "blobfish" is encountered, and set the start of match
                      > to the start of "blobfish".

                      It is even easier using the '\%>l' item:

                      \%>51lblobfish

                      this finds the first blobfish after line 51.

                      regards,
                      Christian

                      --
                      You received this message from the "vim_use" maillist.
                      Do not top-post! Type your reply below the text you are replying to.
                      For more information, visit http://www.vim.org/maillist.php
                    • Ben Fritz
                      ... Forgot about that one, thanks. -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying
                      Message 10 of 11 , Aug 7, 2012
                      • 0 Attachment
                        On Tuesday, August 7, 2012 10:49:27 AM UTC-5, Christian Brabandt wrote:
                        > Hi Ben!
                        >
                        >
                        >
                        > On Di, 07 Aug 2012, Ben Fritz wrote:
                        >
                        >
                        >
                        > > From previous discussion, he claims to want the first "blobfish" on or
                        >
                        > > after line 51. While this could be done with the line number match, it
                        >
                        > > seemed clearer to use a range.
                        >
                        > >
                        >
                        > > But maybe try the line number match anyway, the pattern should be like
                        >
                        > > '\%51l\_.\{-}\zsblobfish' (untested), which should match any number of
                        >
                        > > characters including line endings on or after line 51, as few as
                        >
                        > > possible until "blobfish" is encountered, and set the start of match
                        >
                        > > to the start of "blobfish".
                        >
                        >
                        >
                        > It is even easier using the '\%>l' item:
                        >
                        >
                        >
                        > \%>51lblobfish
                        >
                        >
                        >
                        > this finds the first blobfish after line 51.
                        >
                        >
                        >

                        Forgot about that one, thanks.

                        --
                        You received this message from the "vim_use" maillist.
                        Do not top-post! Type your reply below the text you are replying to.
                        For more information, visit http://www.vim.org/maillist.php
                      • His Nerdship
                        ... Thanks guys, but none of these seemed to work: Ben s first suggestion of %51l _. {-} zsblobfish was mistaken for a file path:
                        Message 11 of 11 , Aug 7, 2012
                        • 0 Attachment
                          On Aug 8, 3:34 am, Ben Fritz <fritzophre...@...> wrote:
                          > On Tuesday, August 7, 2012 10:49:27 AM UTC-5, Christian Brabandt wrote:
                          > > Hi Ben!
                          >
                          > > On Di, 07 Aug 2012, Ben Fritz wrote:
                          >
                          > > > From previous discussion, he claims to want the first "blobfish" on or
                          >
                          > > > after line 51. While this could be done with the line number match, it
                          >
                          > > > seemed clearer to use a range.
                          >
                          > > > But maybe try the line number match anyway, the pattern should be like
                          >
                          > > > '\%51l\_.\{-}\zsblobfish' (untested), which should match any number of
                          >
                          > > > characters including line endings on or after line 51, as few as
                          >
                          > > > possible until "blobfish" is encountered, and set the start of match
                          >
                          > > > to the start of "blobfish".
                          >
                          > > It is even easier using the '\%>l' item:
                          >
                          > > \%>51lblobfish
                          >
                          > > this finds the first blobfish after line 51.
                          >
                          > Forgot about that one, thanks.- Hide quoted text -
                          >
                          > - Show quoted text -

                          Thanks guys, but none of these seemed to work:
                          Ben's first suggestion of '\%51l\_.\{-}\zsblobfish' was mistaken for a
                          file path:
                          "\TEMP\tmp\'\%51l\_\{-}\zsblobfish'" [New file]

                          As for omitting the '+' before the line number, that was also mistaken
                          for a file path:
                          <lobfish\;call search('blobfish','c')" [New file]

                          Christian's '\%>51lblobfish' merely opened the file without attempting
                          a search, which is a pity as it would have been an elegant solution.

                          It could be that you are providing only a fragment and I am stuffing
                          up somewhere else on the line. Maybe if you could furnish the full
                          line it might help. Sorry to prevail so much on your time.
                          It really isn't too important now as I have a working solution, albeit
                          a rather inelegant one:
                          gvim --servername HgVim --remote-silent "+51;/blobfish/;call
                          search('blobfish','c')" fish.cpp

                          --
                          You received this message from the "vim_use" maillist.
                          Do not top-post! Type your reply below the text you are replying to.
                          For more information, visit http://www.vim.org/maillist.php
                        Your message has been successfully submitted and would be delivered to recipients shortly.