7

How can I run a command on all lines delimited, say by \begin{otherlanguage} and \end{otherlanguage}?

For example,

1 This line should not be affected,
2 \begin{otherlanguage}
3 but this should;
4 \end{otherlanguage}
5 this should not.

(The cmd could be norm A test.)

2
  • Could you give us a workable example?
    – romainl
    Commented Apr 24, 2016 at 19:35
  • @romainl, yes, sorry if I was unclear.
    – Toothrot
    Commented Apr 24, 2016 at 20:16

2 Answers 2

9

You can use pattern delimiter for this:

:/first/,/second/norm dd

You can use any search pattern around the ,.

If you want to use only the inside of the matched patterns, use + and - like so:

:/first/+1,/second/-1 norm dd
3
  • 1
    Very nice. I found adding g at the beginning helps if there are more than one set of delimiters.
    – Toothrot
    Commented Apr 28, 2016 at 14:46
  • I wonder whether something similar could be used to make a visual selection?
    – Toothrot
    Commented Apr 30, 2016 at 13:39
  • Interesting, you should be able by modifying the marks < and >, I think it's worth another question ;)
    – nobe4
    Commented Apr 30, 2016 at 13:53
5

A more specific answer (since you seem to be editing a TeX file): if you use the vimtex plugin (although LaTeX-Box also has this IIRC), you can easily select the whole environment (without the \begin and \end marker lines) using the inside environment text object (ie). So, assuming the cursor is somewhere inside the otherlanguage environment, your example can be "solved" with something like:

vie:norm A test

For more vimtex mappings, see :h vimtex-default-mappings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.