[PLUG] Vim scripting problem

Nick Aubert nickaubert at gmail.com
Wed Sep 14 07:32:10 UTC 2005


When using vim as an editor, the matched patterns in parenthesis are
called up by escaping the number with a backslash instead of a dollar
symbol.

The perl regexp

s/(foo)(bar)/$2$1/

would be

s/\(foo\)\(bar\)/\2\1/

This works for vim in editing mode.  I don't know how much different
the behavior is with vim scripts.  The relevant document on my Gentoo
system is

/usr/share/vim/vim63/doc/change.txt

You might want to look for that file somewhere equivalent on your
system if you're still working on this problem.

-Nick


On 9/12/05, Eric Wilhelm <scratchcomputing at gmail.com> wrote:
> # from Ovid
> # on Monday 12 September 2005 08:13 pm:
> 
> >Is there any way, in a vim script, to get "dollar digit" variables
> > such as those used in Perl to extract matched text? I have the
> > following:
> 
> Doesn't look likely, but you could try the gvim gurus on irc or
> something.  I've had them answer strange questions immediately after
> hours of searching the docs.
> 
> This is slightly enlightening to your situation (at least it tells you
> not to expect too much.)
> 
> :help search
>   "When a match has been found its line number is returned, and
>     the cursor will be positioned at the match."
> 
> 
> >  function GotoCFile()
> >    if search('^\s*#\s*cfile:\s*\(\w\+\)')
> 
> Sounds like your best bet is to go with the fact that the cursor is now
> at the beginning of the matching line.
> 
> Maybe substitute() (which interestingly enough leads to the docs for
> submatch() and that happens to be just close enough to what you need to
> make you really frustrated at the infinite ad-hoc development :-)
> 
> >I've searched all over the Vim
> >documentation for this and it seems to involve finding the starting
> > and ending positions of the match and doing a bit of math and a
> > extracting a substring. Tell me it's not this hard!
> 
> Why would you expect otherwise?  I guess you can try using vim-perl.  If
> not, you should expect more of the same.
> 
> --Eric
> --
> The only thing that could save UNIX at this late date would be a new $30
> shareware version that runs on an unexpanded Commodore 64.
> --Don Lancaster (1991)
> ---------------------------------------------
>     http://scratchcomputing.com
> ---------------------------------------------
> _______________________________________________
> PLUG mailing list
> PLUG at lists.pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
>



More information about the PLUG mailing list