On 2009-08-14, [email protected] wrote:
> Gary Johnson <[email protected]> [09-08-14 01:40]:
> >
> > On 2009-08-13, [email protected] wrote:
> > > Hi,
> > >
> > > A tool generates a file as output, which has keywords inside of the
> > > pattern:
> > >
> > > A-<keywords> <floating point value n>
> > > (some other keywords)
> > > B-<keywords> <floating point value n>
> > >
> > > It is always a pair and there a lot of pairs with different <keyword>s
> > >
> > > With "*" or "#" I can search for the _same_ matching keyword up and
> > > down. Now I want to use another lowercase key to jump between both
> > > parts of a pair. That is: When the cursor is on
> > >
> > > A-<keywords> <floating point value n>
> > >
> > > I want to jump to
> > >
> > > B-<keywords> <floating point value n>
> > >
> > > and vice versa wihouth modyfing anything, since I need to quick
> > > compare the floating point values.
> > >
> > > I _know_ that there is no "this does not work with vim" but
> > > for sure I know that I dont know how.
> > >
> > > Thank you very much for any part of the puzzle in advance!
> >
> > Just load the matchit.vim plugin, if you don't have it loaded
> > already (see ":help matchit"), and execute this:
> >
> > let b:match_words = '^A\>:^B\>'
> >
> > You could put that line in the filetype plugin for your tool's
> > output file. Then % will jump between A and B just as it does for
> > parentheses and other pairs of symbols. Note that I've anchored A
> > and B to column 1.
> >
> > Regards,
> > Gary
> >
>
> Hi Gary.
>
> there one little problem left...
>
> Matchit was build to match pairs, which enclose "blocks": That is:
> there is a begin-of-block marker and a end-of-block marker and
> tose marker and build different levels.
>
> My case is a little different: I only want to match according to
> keywords. There is only a pair of A-<keyword> and B-<keyword> and
> others, totally unrelated pairs of A-<another keyword> and B-<another
> keyword>.
> Transformed this back to curly braces, braces, square braces and
> brackets, the following would be a total syntactical correct
> example:
>
> ]
> (
> [
> }
> {
> )
>
> If the cursor is on ')' it should match '(' below and back.
> And so forth with the other pairs.
> No levels, no hierachies -- only pairs and only two of the same
> kind.
>
> Currently I only can use matchit, when the cursor is on A-<keyword>
> and can jump down to B-<keyword> and back.
>
> If B-<keyword> is the first and A-<keyword> in lines below this,
> matchit """fails""", since it thinks in levels and hierachies.
>
> I am lost here, I think, am I ?
I understand the problem, so I don't think you're lost in your
thinking. Nor do I think you're lost in being able to do this with
vim. Matchit won't do it because your pairs are dynamic, but
writing your own script to do it wouldn't be all that difficult. I
wrote a plugin to do something similar: traverse 'case' and
'default' lines in a C 'switch' statement. I used the enclosing
braces to limit the scope of the search and the indentation level of
the current line to limit the search expression to case/default
labels at that same level so as to avoid nested switches.
In your case, the idea is, with the cursor on a line, you type a key
which calls a function to
- save the current screen state,
- extract the current line,
- from that line, construct a pattern to match its companion,
- search for the companion line.
- If found,
- save the line number,
- restore the original screen state and cursor position,
- go to that line number.
- Else,
- echo an error message,
- restore the original screen state and cursor position.
Restoring the original screen state before moving the cursor avoids
large screen movements for small cursor movements. It may not be
necessary in your case because you're searching for only one
matching line.
There may be better examples of this sort of thing out there, but my
script is here:
http://vim.sourceforge.net/script.php?script_id=511
> Have a nice weekend !
Thanks. It looks like it will be a good one. It's starting to feel
like fall, though. I'm not finished with summer yet!
You have a good weekend, too.
Regards,
Gary
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---