3

I'm working on some HTML files that are formatted weirdly. Each individual class is on a separate line which makes the file (imo) difficult to read.

Something like:

<div class="
  classA
  classB
  classC
" id="xxx">

I would like to use a macro that does the following:

  1. find the next occurence of class="
  2. select everything inside the matching "
  3. do J to join all those lines together

If I would deal with { instead of " i could do something like f{v%J But this doesn't work for " or ' as far as i can tell. I tried doing vi" but this only seems to find " on the same line.

I'm pretty sure I can make this work using regex but I was wondering if there's something simpler that I'm overlooking.

2 Answers 2

2

(N.B. I'm not sure if by "macro" you mean a mapping or a recording, so I've just included the keystrokes in the below, to match what you did in your question.)

It might not work in general, but for the specific example given, you can use a regular search: /"EntervnJ

1
  • oh waw, thats such a simple solution that i just didn't think of. Thanks, that's exactly what i was looking for :)
    – Enermis
    Sep 20, 2022 at 18:38
1

One solution would be to install the target Vim plugin that extend the i" text object such that it works on multiple line (among other improvements).

2
  • Nice, i didn't know that plugin existed. I do think i like the simplicity of @Rich's answer though. But thanks for the plugin suggestion.
    – Enermis
    Sep 20, 2022 at 18:40
  • You are welcome. With 1.3k star it is a "classic" :-) Sep 20, 2022 at 19:48

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.