Wednesday, April 9, 2014

Re: systematic replacement of text

On Wed, Apr 9, 2014 at 5:28 PM, Jean-Rene David <vim_use@levelnine.net> wrote:
> * Natércia Fernandes [2014.04.09 07:02]:
>> In a file with many occurrences of something like this:
>>
>> \xxx{a variable number of words that I want to delete}{a variable (diferent)
>> number of words that I want to keep}
>
> [...]
>
>> Don't know if this info is needed or not: both argument 1 and/or argument 2
>> can contain the symbols \ {}.
But will the symbols be balanced? It must be - otherwise, how can we
even tell what is 'argument 1'? Is it LaTeX?

>
> Not only is it needed, it changes everything.
>
> I was going to suggest:
>
> :%s/\\xxx{\_[^}]*}{\(\_[^}]*\)}/\1/g
>
> But that won't work if the arguments can contain
> '}'. That simple fact makes the problem a lot
> harder.
If the OP is not specifically looking to use the :substitute, a macro
might also do the work?

Search for \\xxx, go to end of the word and do d% for deleting all
characters until a matching brace. Repeat the macro 'N' times, where N
is sufficiently large. Make sure wrapscan is off.

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment