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

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

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

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, privacy policy and cookie policy

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