Thursday, August 2, 2012

Re: Activating gVim from the command line (cont)

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

No comments: