Wednesday, August 1, 2012

Re: Activating Windows gVim from the command line

On Aug 2, 12:00 pm, His Nerdship <shol...@gmail.com> 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

No comments: