# Executing a command on delimited lines

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? Apr 24 '16 at 19:35
• @romainl, yes, sorry if I was unclear. 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

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