My question is about a very specific search and replace pattern, but I hope to find answers for the more general case. I am currently working on some LaTeX slides with allot of overlays and I need to increment certain integers by one or more. A sample text:
\only<1,5-7,9>{hello 11}
In short, the only command only shows hello 11 on slide number 1, 5 through 7 and 9. After inserting a slide at position 2, I need all slides above slide 2 to increment. This is what I came up with:
:.,$s/\d\+/\=str2float(submatch(0))>2?submatch(0)+1:submatch(0)/g
From the current line to the end of the file, it increments all integers above 2 by 1. This means that 11 is also incremented, which is not what I want:
\only<1,6-8,10>{hello 12}
Q1: How can I only match and increment the integers between the delimiters '<' and '>'?
Ultimately, I would like to be able to refine search patterns incrementally by specifying a pattern and apply another pattern to the result. For instance I first match the text between delimiters from the given example text.
/<[^<>]*>
which would highlight the text I have quoted:
\only"<1,5-7,9>"{hello 11}
And now apply my original solution to increment the numbers between the delimiters. I can compare what I would like to do with chaining grep commands together in a shell with the pipe symbol, refining the result with each new grep command.
Q2: Is this chaining of vim search patterns possible?
Update: The solution of Floris comes very close. Indeed it solves the original question, but I failed to mention all requirements. They are:
- The delimiters are guaranteed to be on one line, e.g., <1,5-7,9>.
- Multiple delimited parts can be on one line, e.g.:
hello 11\only<1,6-7,9>{hello 11}\only<1,6-7,9>{hello 11}
The second requirement fails, as the solution currently returns:
hello 12\only<1,7-8,10>{hello 12}\only<1,7-8,10>{hello 11}
It only ignores integers after the last occurrence of '>'. I would like the result to be:
hello 11\only<1,7-8,10>{hello 11}\only<1,7-8,10>{hello 11}
Thanks for any help!