Quantcast

Activating Windows gVim from the command line

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Activating Windows gVim from the command line

His Nerdship
I left a query about 10 days ago which was kindly and competently
answered by Ben (Fritz).  Vielen Dank, Ben.
I have another problem stemming from the same issue, namely that the
moronic managers (aren’t they all?) at my new job have locked down our
PC’s such that we cannot install anything properly.  Ain’t no one like
a manager to stop you doing your job.  This has happened on my last
two contracts, so seems to be the way things are going.
Anyway one side effect is that Vim no longer has a working COM
interface, through which I control Vim from another program (His
Grepship), creating a very handy and powerful combination.  To get
past this I have tried to make His Grepship activate Vim with a
command line request, passed to CreateProcess().  It passes as
arguments the line no from which to search, and the required search
expression.  So if I want to start up Vim so that it immediately takes
me to the word ‘haddock’ on line 713 of fish.cpp I would expect to
enter:
gvim +713 -c “/haddock” fish.cpp
However I find this takes me to (or near) line 713, and all instances
of ‘haddock’ are correctly highlighted, but at best it will take me
only to the start of the line, not to the expression itself. I am
trying to emulate as closely as possible the functionality we get when
COM/OLE is working correctly, where the cursor is placed right on the
search expression.
Is there a way I can achieve this level of control from the command
line?
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Activating Windows gVim from the command line

scott-268
On Wed, Aug 01, 2012 at 04:36:50PM -0700, His Nerdship wrote:

> I left a query about 10 days ago which was kindly and competently
> answered by Ben (Fritz).  Vielen Dank, Ben.
> I have another problem stemming from the same issue, namely that the
> moronic managers (aren’t they all?) at my new job have locked down our
> PC’s such that we cannot install anything properly.  Ain’t no one like
> a manager to stop you doing your job.  This has happened on my last
> two contracts, so seems to be the way things are going.
> Anyway one side effect is that Vim no longer has a working COM
> interface, through which I control Vim from another program (His
> Grepship), creating a very handy and powerful combination.  To get
> past this I have tried to make His Grepship activate Vim with a
> command line request, passed to CreateProcess().  It passes as
> arguments the line no from which to search, and the required search
> expression.  So if I want to start up Vim so that it immediately takes
> me to the word ‘haddock’ on line 713 of fish.cpp I would expect to
> enter:
> gvim +713 -c “/haddock” fish.cpp
> However I find this takes me to (or near) line 713, and all instances
> of ‘haddock’ are correctly highlighted, but at best it will take me
> only to the start of the line, not to the expression itself. I am
> trying to emulate as closely as possible the functionality we get when
> COM/OLE is working correctly, where the cursor is placed right on the
> search expression.
> Is there a way I can achieve this level of control from the command
> line?

what about gvim -c ":call search('haddock')"

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Activating Windows gVim from the command line

Gary Johnson-4
In reply to this post by His Nerdship
On 2012-08-01, His Nerdship wrote:

> So if I want to start up Vim so that it immediately takes
> me to the word ‘haddock’ on line 713 of fish.cpp I would expect to
> enter:
> gvim +713 -c “/haddock” fish.cpp
> However I find this takes me to (or near) line 713, and all instances
> of ‘haddock’ are correctly highlighted, but at best it will take me
> only to the start of the line, not to the expression itself. I am
> trying to emulate as closely as possible the functionality we get when
> COM/OLE is working correctly, where the cursor is placed right on the
> search expression.
> Is there a way I can achieve this level of control from the command
> line?

(I assume that the oddball quotation marks are due to your mailer's
editor.)

The -c option specifies an ex command, not a normal-mode
command.  The ex search command finds the line matching the
patterns, not the column.

What you want is something like this:

    gvim +713 -c 'exe "normal /haddock\<CR>"' fish.cpp

The quoting shown works on Unix.  It's important that the :normal
command be enclosed in double-quotes for the \<CR> to be correctly
expanded by :exe.  I don't know how to quote that properly on
Windows, so I'll leave that to you.

See

    :help -c
    :help :normal
    :help :silent " for an example of a :normal search command
    :help :exe

Regards,
Gary

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Activating Windows gVim from the command line

His Nerdship
>
> (I assume that the oddball quotation marks are due to your mailer's
> editor.)
>
> The -c option specifies an ex command, not a normal-mode
> command.  The ex search command finds the line matching the
> patterns, not the column.
>
> What you want is something like this:
>
>     gvim +713 -c 'exe "normal /haddock\<CR>"' fish.cpp
>
> The quoting shown works on Unix.  It's important that the :normal
> command be enclosed in double-quotes for the \<CR> to be correctly
> expanded by :exe.  I don't know how to quote that properly on
> Windows, so I'll leave that to you.
>
> See
>
>     :help -c
>     :help :normal
>     :help :silent " for an example of a :normal search command
>     :help :exe
>
> Regards,
> Gary

Thanks a million, Gary and sc.
Gary your solution didn't work in Windows - it has different quoting
rules to UNIX.  It's just a matter of experimentation and I will try
and bully it into submission later.
sc - your solution worked in that it correctly brought up Vim with the
cursor on the search expression.  However Vim clearly does not
consider this to be a normal search, because the expression was not
highlighted and hitting 'n' (for next occurrence) did nothing.
However it gave me the break I needed because I just preceded your
":call search" action with a normal search:

  gvim +712 -c "/haddock" -c ":call search('haddock')" fish.cpp

The initial -c "/haddock" sets up haddock as the current search
expression (so that all haddocks are highlighted, and hitting 'n' will
find the next one), and the ":call search" takes one to the actual
expression.
HOWEVER - note I had to subtract 1 from the line no (713) because the
"/haddock" takes one to the start of the line, and the ":call search"
starts its search from the following line.  This is not perfect, and
work in progress, but at least it's progress.
Thanks 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Activating Windows gVim from the command line

His Nerdship


On Aug 2, 12:00 pm, His Nerdship <[hidden email]> wrote:

> Thanks a million, Gary and sc.
> Gary your solution didn't work in Windows - it has different quoting
> rules to UNIX.  It's just a matter of experimentation and I will try
> and bully it into submission later.
> sc - your solution worked in that it correctly brought up Vim with the
> cursor on the search expression.  However Vim clearly does not
> consider this to be a normal search, because the expression was not
> highlighted and hitting 'n' (for next occurrence) did nothing.
> However it gave me the break I needed because I just preceded your
> ":call search" action with a normal search:
>
>   gvim +712 -c "/haddock" -c ":call search('haddock')" fish.cpp
>
> The initial -c "/haddock" sets up haddock as the current search
> expression (so that all haddocks are highlighted, and hitting 'n' will
> find the next one), and the ":call search" takes one to the actual
> expression.
> HOWEVER - note I had to subtract 1 from the line no (713) because the
> "/haddock" takes one to the start of the line, and the ":call search"
> starts its search from the following line.  This is not perfect, and
> work in progress, but at least it's progress.
> Thanks again- Hide quoted text -
>
> - Show quoted text -

I have found a working solution:
gvim -c "/haddock" +713 -c ":call search('haddock','c')" fish.cpp

First do the '/' search, then go to the specified line, then do the
":call search", i.e. specify the line no AFTER the initial search.
Also note the parameters passed to search() can be in single quotes.
The 2nd parameter to search(), 'c', tells search() to accept a match
at the cursor position.  Without this, if the search string is at the
beginning of the line, Vim will move on to the next occurrence.

This even works with added conditions, such as case insensitive
(precede with \c), regular expression (\m), and whole word.  This will
also find the above haddock (looking for 'h.dd.CK'):
gvim -c"/\c\m\<h.dd.CK\>" +713 -c ":call search('\c\m\<h.dd.CK
\>','c')" fish.cpp

Thanks for your help guys.  You gave me the break I needed.

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Activating Windows gVim from the command line

Ben Fritz
On Thursday, August 2, 2012 12:21:02 AM UTC-5, His Nerdship wrote:

>
>
> I have found a working solution:
>
> gvim -c "/haddock" +713 -c ":call search('haddock','c')" fish.cpp
>
>
>
> First do the '/' search, then go to the specified line, then do the
>
> ":call search"

I'm glad you got it working, and I don't see any reason to change it.

I do have one minor note which may save you some trouble in the future.

You seem to think vim -c "/pattern" performs a '/' search. It doesn't. What it is doing is specifying the first line of an ex command range via a pattern. I'm not sure where it's documented but specifying a single-line range with no command will just set the cursor to that line.

:help :range gives details. I wonder if you could make use of a ";" in your range to accomplish what you want with a shorter command.

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Activating Windows gVim from the command line

Tony Mechelynck
On 02/08/12 16:30, Ben Fritz wrote:

> On Thursday, August 2, 2012 12:21:02 AM UTC-5, His Nerdship wrote:
>>
>>
>> I have found a working solution:
>>
>> gvim -c "/haddock" +713 -c ":call search('haddock','c')" fish.cpp
>>
>>
>>
>> First do the '/' search, then go to the specified line, then do the
>>
>> ":call search"
>
> I'm glad you got it working, and I don't see any reason to change it.
>
> I do have one minor note which may save you some trouble in the future.
>
> You seem to think vim -c "/pattern" performs a '/' search. It doesn't. What it is doing is specifying the first line of an ex command range via a pattern. I'm not sure where it's documented but specifying a single-line range with no command will just set the cursor to that line.

It has ho helptag of its own, but it is documented as :[range], just
after ":help gg", in the section about up and down motions.

":help +cmd" and ":help [range]" (the section which includes the
":range" overview you mention below) are also relevant because more
detailed, but the section about +something as a Vim argument is ":help -+c".

>
> :help :range gives details. I wonder if you could make use of a ";" in your range to accomplish what you want with a shorter command.
>

...for instance
        gvim +713;/haddock/ -c "call search('haddock','c')" fish.cpp
for the first "haddock" after line 713 (i.e. on line 714 or after).

This will also find chaddocks if present. See
        :help /\<
        :help /\>
about specifying word boundaries in a pattern.


Best regards,
Tony.
--
This is the _LAST_ time I take travel suggestions from Ray Bradbury!

--
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
Loading...